Flashlight Triggered Events

From Valve Developer Community
Jump to: navigation, search

Introduction

This is a short and easy tutorial on how to create events based by pointing your flashlight at specific targets. Here a ragdoll will be hanging from the ceiling in a room shrouded in darkness and will fall down if the player looks at it with the flashlight turned on.

The entities

In this tutorial you will use the following entities:

The rooms

First of all create a tiny map with two rooms and make a short hallway connect the two. Then place an info_player_start and an item_suit right next to each other in one of the rooms. Place an light entity here as well so the other room becomes dark. From now on we'll call the room the player spawns in as the "spawn room" and the other "dark room."

The flashlight listener

To perform the condition checks we need place an logic_playerproxy anywhere in your map, you don't need to name this. This entity can, among many other things, perform an output whenever the player turns the flashlight on or off. Since we can't turn logic_playerproxy on or off we're going to store the status of the flashlight in a logic_branch. Create an logic_branch and name it "flashlight_branch" and let initial value be 0. In logic_playerproxy, make the following outputs:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnFlashLightOn flashlight_branch SetValue 1 0 No
Entity-output-icon.png OnFlashLightOff flashlight_branch SetValue 0 0 No

The room listener

Now we need to find out if the player is in the dark room we are making. First make another logic_branch and name it "room_branch", let initial value be 0. We want to know if the player is actually in the room when the flashlight turns on. So we're going to make two triggers: One that indicates that the player enters the dark room and one that indicates he or she is leaving the dark room. At the door leading into the dark room create one trigger_multiple that fills the entire frame and place it at the end of the hallway at the entrance to the dark room. Then make another trigger_multiple at the other entrance leading to the spawn room.

On the trigger closest to the dark room make this output:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTrigger room_branch SetValue 1 0 no

And on the trigger closest to the spawn room make this output:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTrigger room_branch SetValue 0 0 no

Two conditions down, time to handle the trigger on look.

The trigger look

First of all we're going to need a phys_constraint and a prop_ragdoll. First place the prop_ragdoll and give it the fast-zombie model (for the spooky effect), located at models/zombie/fast.mdl. Name it "fastzombie" and place it somewhere above ground in the dark room so it can't be seen from the entrance. Next, place the phys_constraint close to the prop_ragdoll and name it "fastzombie_constraint", in "Entity 1" write "fastzombie".

Next up is the trigger_look, this trigger will fire an output if these conditions are met: The player is inside the trigger volume and has either looked or moved towards a given entity. Make a trigger volume that fills the entire dark room and make it a trigger_look with these values added:

Class: trigger_look
Keyvalues Comments
Name fastzombie_look This is so we can control this trigger remotely
Start Disabled Yes We're going to toggle this when the flashlight goes on and off
Look target fastzombie What we want to look at
Look Time 0.5 How long we should look at this
FieldOfView 0.90 A value of 0.90 makes the trigger happen just as it comes into view with the flashlight, try setting it at different values from -1.00 to 1.00

The rest of the values can be as they were. Create a third logic_branch and name it "look_branch" with initial value set to 0. In the trigger_look we made, make an output with this:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnTrigger look_branch SetValue 1 0 no

The last check we need for the look trigger is to check if the flashlight is activated while the player is looking where we want him or her to. For this we need another output in logic_playerproxy:

The whole output page should look like this:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnFlashLightOn flashlight_branch SetValue 1 0 No
Entity-output-icon.png OnFlashLightOff flashlight_branch SetValue 0 0 No
Entity-output-icon.png OnFlashLightOn fastzombie_look Enable 0 0 No The flashlight goes on, the trigger can happend
Entity-output-icon.png OnFlashLightOff fastzombie_look Disable 0 0 No The flashlight goes on, the trigger is disabled

We are nearly done. Go your cluster of logic_branch and place a logic_branch_listener near them, it dosen't need a name. Fill in this on the first three entries of the logic_branch_listener:

Class: logic_branch_listener
Keyvalues Comments
Name Leave this blank.
Logic Branch 01 flashlight_branch Check if the flashlight is on.
Logic Branch 02 room_branch Check if the player is in the dark room.
Logic Branch 03 look_branch Check if the player is looking at the hanging zombie.

Still on the logic_branch_listener, create an output with the following:

My output Target entity Target input Parameter Delay Only once Comments
Entity-output-icon.png OnAllTrue fastzombie_constraint Break 0.00 no

And that should be all. Compile your map, grab the suit, enter the room and look at the hanging zombie with the flashlight on to make it fall down.

Down below is an .vmf file of the tutorial and two addtional events triggered by the flashlight and trigger_look.

Addtional info