Security Cameras

Today’s map hack allows you to create an point entity which watches for the player like an idle monster. When it notices the player it will fire its targets. The simplest use of this hack is to use it to place a “security camera” (or a “haunted statue/painting/idol” depending on the theme of your map) that alerts monsters or sets off traps unless the player can avoid its gaze. They can also be carefully placed to react when an actual monster is alerted to the player, effectively allowing you to trigger events on monster waking.

Today’s entity will be our old friend info_notnull. Insert one into the map, and add the following keys:

"think" "shal_stand"
"nextthink" "0.3"
"pausetime" "999999999"
"th_run" "SUB_UseTargets"
"target" "trapdoor"

We’ve added the standing animation function from the Vore as this entity’s think function, and set an nextthink time so that it starts running immediately. We could have chosen any monster’s standing function, but the Vore doesn’t loop through an animation while standing so it’s cleaner. We set pausetime impossibly high so that the Vore doesn’t try and walk off.

The shal_stand function calls ai_stand, and ai_stand doesn’t do much except call FindTarget – the main Quake AI function for deciding if a monster has detected a player. If FindTarget answers yes then the FoundTarget function runs, which calls the function stored in th_run – normally changing the monster’s animation and AI into attack mode. This is where the next part of our hack comes in – we’ve set this function to SUB_UseTargets, which means our entity fires its targets.

One important detail is that FoundTarget doesn’t call the th_run function directly – it actually schedules it to run next frame using the think/nextthink fields. This overwrites shal_stand, so our entity will only fire its target once. Afterwards, it has stopped looking for the player. If you added the key "use" "shal_stand", you could trigger the camera to reactivate it (bonus idea: then remove the think/nextthink keys from the entity, and create a camera that isn’t watching until it is triggered).

Because we’re just using the standard Quake AI functions, we get all the usual behaviour. For example, the camera is fooled by a ring of invisibility or the notarget cheat. The camera also obeys the standard distance rules for noticing a player

Long range: never wakes up
Mid range: wakes up if the player is in front of the camera and visible
Near range: also wakes up if the player recently attacked but isn’t in front
Melee range: always wakes up if player is visible

Note that this means the angle the camera is facing matters. If you find your camera has too wide a field of view, you might want to place it inside a recess or a box in your map to restrict its line of sight.

One final important detail is that by default the camera will wake up if it can see another monster waking up. If this is undesirable, you can set spawnflag 1 on the camera – this is the AMBUSH spawnflag for a monster, and it will have the same effect on the camera – it only activates if it sees the player directly. On the other hand, if you place a camera inside a monster, looking down at the ground, it will effectively only activate when that monster wakes up. This gives you the ability to tie events to the monster waking up – for example locking the doors until it dies.

The test map demonstrates this idea – the door to the outside will lock when you wake up the knight, and unlock again when you kill him. Caveat – make sure you’ve thought about what will happen if the monster is killed without being woken up! A quad grenade from outside LOS can often stealth kill a monster. An easy to miss detail is that the security camera would still exist at this point, and if the player walks to where the monster was the camera might see the player directly. So you’d need whatever clean-up you planned to incorporate a killtarget on the camera as well.

That’s about it for today, but it’s worth mentioning that you could do more with this hack than just trigger targets with it. You could change the th_run function to something else and get different effects. As a simple (but stupid) idea you could use OgreGrenadeExplode to make an explosion goes off when the entity notices the player. For further inspiration, why not look through the earlier articles in the map hacks section…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.