Snarkpit Articles

Using A Logic_Case For Random Effect

Introduction to, and use of, a logic_case

Using Logic_Case for Random Effect

Author: Stadric

For this example, we?re going to use buttons, we?ll unlock one at random, then lock them all, then unlock another. First of all, make a room with three buttons(func_button) and an info_player_start in it.

Give your buttons these properties:
Locked Sound: Access Denied
Unlocked Sound: Access Granted
Flags:
Don?t move
Use Activates

Name each of the buttons, I named them button1, button2, and button3.

Now we need to give our buttons to do something, like open a door. Place a prop_door_rotating somewhere in your map, and give it these properties:
World Model: models/props_c17/door01_left.mdl
Flags:
Ignore Player +USE

Now hold down shift and drag the door somewhere, then do once more, now you should have three doors, give each a name. I named mine door1, door2, and door3

Now give your buttons outputs, for button1:
Article image


for button2:
Article image


for button3:
Article image


Now make a logic_case and give it a name, I named mine case. Give it these properties:

Case 01: case1
Case 02: case2
Case 03: case3

In all reality, it doesn?t matter what you call these, but you have to name any that you will use. You use as many as you have outputs to choose from, in this case, we?re going to unlock one of three buttons, so we have three possible outputs:
-Unlock button1
-Unlock button2
-Unlock button3
And we name three cases inside our logic_case

Now add these outputs to your logic_case:
Article image


Now we need something to make the logic_case randomly choose a button to unlock. We?ll use a logic_timer. Give your logic_timer these properties:

Refire interval: 5

Give this output to your logic_timer:
Article image


Now all of the doors will be closed so that when you press a button, they?ll all be ready to open again, and all of the buttons will be locked, and ready to be unlocked again.

When a logic_case receives a PickRandom input, it randomly chooses one of the cases that have been named. We named three of them, so it will randomly choose between the three cases, and unlock one of the buttons accordingly, so that we can open a door with it.

Compile your map and run it.

EDIT
You don't need to name cases inside of a logic_case, the "pickrandom" output only chooses between cases that have outputs.

Discussion

Posted by CombineX on Tue Mar 13th 2007 at 3:41pm

Awesome tutorial!
I were thinking a lot how Valve can make random sounds(like in Ravenholm)
and thanks to you, now i know!

If a new mapper wants to create random ambients, but dont know how(after he/she read this tutorial)please mail me and i try to help ya out. Its really easy
Posted by parakeet on Mon Jan 9th 2006 at 11:14pm

Hehee i find it interesting that the first pic is nearly smallest but nearly biggest in size , but i'll leave that up to orph to settle :P . Personally i enjoyed the possibilities that this opens up for me ;) , likes inconsistancy in a game

it was well explained with nicely spaced pictures , and the correct colors to catch my eye.
Posted by Stadric on Fri Jan 6th 2006 at 4:38am
[Author]

I use the entity all the time in my mapping, usually for electrical effects, I can randomly turn env_beams on and off, and randomly play electrical sounds. I also used it for a floor that fell apart when you pushed a button, that was fun =D
Posted by dilbert_halflife on Thu Jan 5th 2006 at 11:51am

Nice.
I have used random events, hl1 maps to generate sounds.
This could be used in the same way.
For example at a popular sniper spot I would randomly play the sound of a crossbow bolt hitting a wall (frightens campers away)
With this tut, it could play only when there was someone there.
Posted by fishy on Thu Jan 5th 2006 at 6:05am

Nice. i don't normally understand entity tuts, but i think i've got this one. it's good to know a way to trigger random events.
Posted by DrGlass on Thu Jan 5th 2006 at 4:00am

Very nice tutorial, easy to understand and a good amount of information presented in a very clear way. My only problem is I cant think of anyway this could be used in-game. I'd add a few ideas where this could come in handy.

good example of logic_case (an over looked entity) no the less.