"If... Then..." logic?

Any aspects of level design for the Source engine.

"If... Then..." logic?

Postby OPFOR on Fri Mar 02, 2007 11:35 pm

Greetings Interlopers,

I'm pretty new to Hammer and creating levels for HL2 SP. It's been easy to pick up the editor so far, especially with all the good threads and tutorials on this forum. I'm enjoying the method of inputs and outputs that drives entity relationships.

The big thing I'm trying to figure out right now is how to set up some "if-then" type of logic. The very nature of the inputs and outputs makes simple "if A then B" relationships second nature. What I can't figure out how to do is "If A and B but not C then D" types of things. Can anyone help me with how to do this?

Also, if one of the above conditions (A,B,C or D) happens to be a trigger set to trigger of the player, does that trigger stay "true" as long as the player is in it? Is there an option to have it toggle back to untrue whenever the player leaves it?

A specific example of what I'm trying to accomplish is to have different enemy ai types trigger depending on which trigger or combination of triggers a player is in and therefor has active.

Thanks in advance for any help you can offer! 8)

-OPposing FORces
OPFOR
Member
Member
 
Joined: Fri Mar 02, 2007 11:17 pm

Postby slayera on Sat Mar 03, 2007 12:10 am

Check out logic entities. You should find what you need
there.
Image


"When one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion." -Robert Pirsig
User avatar
slayera
Veteran
Veteran
 
Joined: Wed Dec 08, 2004 3:15 am
Location: Near the world's only super volcano.

Postby Mr. Happy on Sat Mar 03, 2007 12:10 am

You seem to have a solid grasp of logic and the I/O system in general, so I'm just going to point the way, rather than explain what to do.

List of logic entities
these entites are what your looking for!

The simplest if then's I like to do with a logic_branch. This entity is a binary operator. Basically, I'll give the true event an ouput like
My Ouput Named: <trigger>
Target entities named: <logic branch>
Via this input: SetValue
With a parameter override of: 1

and then to exectute the if then statement, send the logic_branch a Test input. Also, set the logic_branch's OnTrue output. (false works same way, with 0 of course)

For timed triggers use a logic_timer. Have it's refire time set.

Trigger brushes can also have OnStartTouch and OnEndTouch outputs, not just OnTrigger. Use these for something to happen when player enters the brush, and something else when he exits it. Say, activate and then deactivate the logic_timer, to complete the timed trigger setup.

For more complex if then's you can stack logic_branch's. Logic_compare and logic_multicompare let you compare values to each other and then set OnEwual and OnNotEqual outputs. logic_case is for simple case statements.

Complex if then's can also be done with a logic_case and a logic_counter. I forget the term...you might know this.....anyway, there are cetain powers of two that when added together equal a number that won't result in any addition of other numbers in this set....damn I can't explain it very well. Anyway, this is how the flags are done. You could set each case to a different result, and then use different triggers to increment the counter by each of the numbers with SetValueNoFire. Then pass the result to the logic_case with OutValue. You know what, thats probably too complicated unless you know what I mean lol. I'll look up the set later.

Anyway, I hope this helps :D
Image
-You've just been happified!?
User avatar
Mr. Happy
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sat Dec 30, 2006 9:20 am
Location: Flyin' thru "da cloud" in the MotherShip

Postby OPFOR on Sat Mar 03, 2007 12:55 am

Very interesting... I *really* appreciate the input! :)

So, it sounds like I can use the combination of On Start Touch and On End Touch to cause logic entity arrangements to "re-think" whenever the player enters or leaves a trigger. Neat.

I'm understanding from your post that I'll have to use a combination of different logic entities to set up the more complex "if... then..." relationships I'm looking for. Unfortunately these logic entities are much different than anything I've used in the other game editors I've worked with. I'm sure it's straightforward when I understand the paradigm... I'm just having a hard time getting my head around it all! It seems that counting values has a lot to do with their use.

I'm going to "chew" on all this and will post back with another question or two...

Thanks! 8)
OPFOR
Member
Member
 
Joined: Fri Mar 02, 2007 11:17 pm

Postby leadphalanx on Sat Mar 03, 2007 1:51 am

There are several Logic entities, which can be extremely useful once you figure out how to use them. Math_counter, Logic_auto,and Logic_compare , are the ones I use most. Math_counters are useful for having outputs activated when a certain number has been reached (such as number of bullets hitting a wall, number of times a button is pressed, etc.) A logic compare is extremely useful when used with a Game_ui entity. A logic compare can create outputs for the W,S,A,D and mouse keys, making things such as working cranes possible to control.

You can do quite a lot with logic entities, so I suggest reading through some tutorials.
User avatar
leadphalanx
Pheropod
Pheropod
 
Joined: Tue Jul 19, 2005 6:02 pm
Location: Florida

Postby Creatus on Sun Mar 04, 2007 5:29 am

The logic_relay can be one of the most helpful things ever.

The mindset you'll get into with the source input/output system is slightly different from basic programming.

Instead of thinking: "If the player is in the trigger, then the door is open"

You'll think: "In the trigger; OnStartTouch, Door opens. OnEndTouch, Door closes"
Image
User avatar
Creatus
1337 p0st3r
1337 p0st3r
 
Joined: Sun Oct 16, 2005 1:07 am

Postby toxicity on Sun Mar 04, 2007 2:06 pm

Oh my god, someone smart who even types correctly?

This topic must be fake.



ontopic:

my favorite part of hammer was the input/output thing your talking about. What i did to figure out SOO much of it was just make random maps, and keep adding to them, at one point i got a fully interactive space ship going.
I even found out how to make landmines, grenades you can pick up and throw, and bombing runs in DoD:S (although the bombs were barrels, i was too lazy to make detailed prop_physics brush bombs and tie explosion/parents to em).
http://www.putphoto.com/d/97604-1/untitled.JPG
Signature image size limit is 450x100
toxicity
Regular
Regular
 
Joined: Sun Aug 14, 2005 1:17 am

Postby Sauce on Sun Mar 04, 2007 2:08 pm

OPFOR wrote: I *really* appreciate the input!

pun intended? :P
Image
Blink wrote:Do you watch porn and decide you don't need to have sex because you've seen the ending? :-D

zombie@computer wrote:what retarded countries measure in stones anyway?
or feet? or inches? Your dick is a lot longer in cms
User avatar
Sauce
Senior Member
Senior Member
 
Joined: Sat Nov 26, 2005 4:36 am
Location: Australia

Postby OPFOR on Mon Mar 05, 2007 6:50 pm

Sauce wrote:
OPFOR wrote: I *really* appreciate the input!

pun intended? :P


Ha! Unfortunately no... but that was pretty good, eh?

As far as my question goes, I've made *a lot* of progress using the math_counter entity. Not quite the "if A and B but not C" type of thing I was looking for but I've done some good stuff with it. I learned a lot about Hammer over the weekend so I think I'll have this particular logic figured out pretty soon. I guess I could use the math counter set to a max of 2 where A and B each add one and then C subtracts one if true? Hmmm... more to think on.

On another note, is there a way to get Combine to trigger triggers? I thought I could use a filter_class (or whatever it's called) with a trigger_multiple brush to do this but I havn't been getting any good results.

Thanks :)
OPFOR
Member
Member
 
Joined: Fri Mar 02, 2007 11:17 pm

Postby Mr. Happy on Mon Mar 05, 2007 8:40 pm

That could work, but I find systems like that tend to bug up pretty easily.

Something you could try is the power-of-two system I was talking about.

You would have a math counter, and each input add's or subtracts a different power of two for true and false (add for true, subtract for false).

So, A would add 2, B would add 4, and C would add 8. If they start false, then you would have the math_counter start at 0, if they start at true then they it would start at 14.

Since every possbiilty produces a different result, 2+4=6, 2+8=10, 4+8=12, and 2+4+8=14, you can assign each of these value's to different cases in a logic_case. Case01 = 6, Case02 = 10, Case03 = 12, and Case04 = 14.

So, A and B not C is represented by 6. When it comes time to test the logic, you use the math_counter's OutValue output in conjunction with the logic_case's InValue input.

One of the birrst advantages to this is that you can then set Outputs to the other four options.
I think these are called bitfields but im not sure.....
Image
-You've just been happified!?
User avatar
Mr. Happy
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sat Dec 30, 2006 9:20 am
Location: Flyin' thru "da cloud" in the MotherShip

Postby OPFOR on Mon Mar 05, 2007 9:06 pm

Mr Happy wrote:Something you could try is the power-of-two system I was talking about.

You would have a math counter, and each input add's or subtracts a different power of two for true and false (add for true, subtract for false).

So, A would add 2, B would add 4, and C would add 8. If they start false, then you would have the math_counter start at 0, if they start at true then they it would start at 14.

Since every possbiilty produces a different result, 2+4=6, 2+8=10, 4+8=12, and 2+4+8=14, you can assign each of these value's to different cases in a logic_case. Case01 = 6, Case02 = 10, Case03 = 12, and Case04 = 14.

So, A and B not C is represented by 6. When it comes time to test the logic, you use the math_counter's OutValue output in conjunction with the logic_case's InValue input.


Ahh... this makes sense to me now! Particularly after gaining a lot of experience with basic math_counter functionality over the weekend. This system of logic is not as obvious as some other systems I've used but now that I understand it, I can see that that must work very well.

Thanks for explaining that! 8)
OPFOR
Member
Member
 
Joined: Fri Mar 02, 2007 11:17 pm

Postby OPFOR on Mon Mar 05, 2007 9:07 pm

OPFOR wrote:On another note, is there a way to get Combine to trigger triggers? I thought I could use a filter_class (or whatever it's called) with a trigger_multiple brush to do this but I havn't been getting any good results.


Anyone have any insight on this? Thanks :)
OPFOR
Member
Member
 
Joined: Fri Mar 02, 2007 11:17 pm

Postby Flufd on Mon Mar 05, 2007 9:50 pm

Add a filter_activator_class, then set it's name as say, "combine_filter", then set it's filter mode to "Allow entities that match criteria" and set it's filter classname to "npc_combine_s". On your trigger, set the filter name to the name of your filter, in this example "combine_filter". That should work if I remember correctly. Oh and you will also have to set the NPC flag on your trigger.
Flufd
1337 p0st3r
1337 p0st3r
 
Joined: Sun Jan 15, 2006 9:54 pm
Location: Staffordshire, UK

Postby OPFOR on Mon Mar 05, 2007 10:29 pm

Flufd wrote:Oh and you will also have to set the NPC flag on your trigger.


Ah-ha! This is what I was doing incorrectly! I had figured everything else out but did not check this flag. Excellent! *crosses fingers* 8)
OPFOR
Member
Member
 
Joined: Fri Mar 02, 2007 11:17 pm

Return to Hammer Editor Help

Who is online

Users browsing this forum: No registered users