Using a math_counter and logic entites and to count "keys"

Using a math_counter and logic entites and to count "keys"

Re: Using a math_counter and logic entites and to count "keys" Posted by DrFrag on Sat Jun 11th 2005 at 2:22pm
DrFrag
62 posts
Posted 2005-06-11 2:22pm
DrFrag
member
62 posts 16 snarkmarks Registered: Jan 12th 2005 Location: Australia
I'm trying to set up a system for the player to carry up to 5 keys. The game keeps track of how many keys they have with a math_counter entity. This is what I have so far:

User posted image

(1) This is a func_wall with a picture of the key (an ankh in this case). In front of it is a trigger_multiple which is the "pick up" area. Running into this triggers (2) math_counter, increasing it by 1. This is the running total of how many keys have been picked up.
(2) math_counter passes its value on to (3) logic_case, which then does a few things. It displays the text at (4) game_text ("you picked up a key") and one of the five messages at (5) game_text ("you now have n keys"). The logic_case also triggers a sound effect at (6), and destroys the func_wall and trigger_multiple at (1) so the player can't pick it up twice.

So far so good, it all seems to work.

However, because these are all linked together and it ends with the initial key trigger entities being destroyed, I'll need a set of the main entities for each key in the game. But that would mean having a different math_counter for each key which is no good - I need a single counter for all the keys.

Is there some way I can check and change the value in math_counter without having to "pass through" it?
It'll need to be separate for the locks too.
Re: Using a math_counter and logic entites and to count "keys" Posted by DrFrag on Sat Jun 11th 2005 at 3:54pm
DrFrag
62 posts
Posted 2005-06-11 3:54pm
DrFrag
member
62 posts 16 snarkmarks Registered: Jan 12th 2005 Location: Australia
Something I forgot to mention. Since I want the player to have a maximum of 5 keys, I'll be adding a check to see if they already have 5 keys (before the key entity is destroyed on pickup). This is pretty easy, but it means I can't use the above process and stick the math_counter at the end.
Re: Using a math_counter and logic entites and to count "keys" Posted by zombie_computer on Sat Jun 11th 2005 at 6:56pm
zombie_computer
28 posts
Posted 2005-06-11 6:56pm
28 posts 3 snarkmarks Registered: Feb 15th 2005 Location: Netherlands
seems awfully complicated what you want to do, and i probalby can help
you, but not with the current info (can't really make out what it is
exactly you want: when is the trigger and brush going to be deleted?
What exactly do you want with the locks?)

but know you can check the value of the counter by just doing an "add
0" input, causing the entity to refire its output. youi can change this
output for these checks and quickly set it to the default one as you
see need
Re: Using a math_counter and logic entites and to count "keys" Posted by DrFrag on Sun Jun 12th 2005 at 2:42pm
DrFrag
62 posts
Posted 2005-06-12 2:42pm
DrFrag
member
62 posts 16 snarkmarks Registered: Jan 12th 2005 Location: Australia
Thanks Zombie. Ideally I'd like a way to check the value of a counter without firing its outputs, but maybe I'm looking at the flow of events the wrong way.

I think I've come up with a solution. It uses a few logic_compare entities and it's pretty messy. The math_counter entity ends up having something like 90 outputs. Hopefully it'll work, I'll post again later with the results.

Are there any tutorials on the general use of logic entities? The examples I've found are too specific, and information on them presented more as a reference. I'm having trouble getting my head around it all.
Re: Using a math_counter and logic entites and to count "keys" Posted by zombie_computer on Sun Jun 12th 2005 at 5:41pm
zombie_computer
28 posts
Posted 2005-06-12 5:41pm
28 posts 3 snarkmarks Registered: Feb 15th 2005 Location: Netherlands
Some images in this post have been automatically down-sized, click on them to view the full sized versions:

to be more specific as to check for a value of the math_counter:

User posted image

to test your value, simply trigger the relay, cant get any simpler
Re: Using a math_counter and logic entites and to count "keys" Posted by DrFrag on Mon Jun 13th 2005 at 10:26am
DrFrag
62 posts
Posted 2005-06-13 10:26am
DrFrag
member
62 posts 16 snarkmarks Registered: Jan 12th 2005 Location: Australia
Thanks for the diagram. It took me a little while to figure out, but I think I understand it now.

Unfortunately my programming skills are pretty basic so I already used a different method. I'll try to explain it.

The map is based on an old game called Total Eclipse. You run around in a pyramid picking up keys and opening doors. You can hold a maximum of 5 keys at any one time. In the game there are 7 keys and 11 doors.

The way I've put it into hammer is this. Each key is made up of three brush entities and a point entity (a logic_compare that acts as a "key zone" flag). The first brush is a thin func_wall with a picture of the key - that's what you see. The second brush is a trigger_multiple which lies just in front of it - this is the "key pickup" area. Around this is a large trigger_multiple brush that acts as sort of a "key zone". As soon as you enter this, the point entity logic_compare is set to value 1 compare 1. As soon as you leave it switches back to value 0 compare 1. This way, the game knows which key you're about to pick up (by reading the state of the logic_compare flag).

(At this point, control is moved to a bunch of global entities no matter what key you've tried to pick up.)

Once you're in the key zone and try to pick up the key, it runs a compare on a logic_compare entity called Maxkeys. This is to make sure you're not trying to pick up more than 5 keys. It keeps a copy of the main math_counter used to count your keys, and a constant Compare of 5. If the Value has gone up to 5, the compare run on it will trip a game_text entity saying you have too many keys - the program flow will end there.
But if you have less than five keys, it adds one to the main math_counter (which also triggers it). The math_counter passes its own value to a logic_case entity where most of the work happens.

The logic_case entity is filled with Case01=0, Case02=1, Case03=2, etc. For its outputs, it triggers a display text entity for each possible value (eg "You now have 1 key"). It also passes its own value to Maxkeys (and Minkeys) for the next time you try to pick up a key but have too many.
It also does a compare for every case against every "key zone" flag, so every possible key and lock in the game is checked to see if the player is standing in that area. That makes 108 additional outputs - notice at this point how much my programming skills suck!

But of all 108 logic_compare entities that are called, only one of them is going to have Value 1 Compare 1 - the "key zone" that was entered earlier on. So control is passed back to the single point entity that sits next to the key. It then plays a pickup sound and destroys two brush entites (the func_wall that looks like a key, and the trigger to pick it up). This stops the player picking up that key twice.

The locks go through the same process, but subtract one from math_counter and check their value against Minkeys instead of Maxkeys (if you have no keys it says you can't open it).
For those who skipped the above, start reading again here
Long story short, I got it working using logic_compare entities as flags. It was probably the hardest part of making this map so I decided to get it out of the way first. The map will be available for download when I'm done. In the meantime, the original 1988 version of Total Eclipse is available from The Underdogs.