Triggering events when looking at something

From The DarkMod Wiki
Revision as of 17:04, 19 March 2013 by Obsttorte (talk | contribs) (This article describes how to setup entities that trigger events if they were looked at.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

Triggering events in games is a nice feature that can be used to drive the story forwards or to create tension. There are already several possibilities, how events can be triggered in DarkRadiant. The most common ones are the player entering a specific area, taking an object or fulfilling an objective.

This article describes how to get entities to trigger events, if the player looks at them.

The scriptobject

The first thing you need is the scriptobject, which you can get here. Put t in your script folder and include it by adding the line

 #include "script/trigger_look.script"

In your tdm_custom_scripts.script file. If there is no such file, you have to create it.

The setup

On the object you want to trigger an event, add the spawnarg "scriptobject" "trigger_look". That's it. If the player does look at it, it will trigger all it's targets.

Additional Spawnargs

There are some additional spawnargs that can be used to control the behaviour of this object. They are all optional.

- "entityname": The entity to react to (default is player1, thus meaning the player) - "stim": the stim used to enable this object (default is PLAYER_STIM) - "distance": how close the entity must be (default: 1024) - "tolerance": describes how exact the player (or another entity) must look (default: 0.1) - "once": if set to one, the entity will trigger it's targets only once (default: 0)

Remarks

There are two parts in the workflow of this object. The first part is the stim, that enables the object, the second one is the entity to react to. This must not be the same!

While for the player the code checks, if he looks at it, for other entities it only checks wheter they are facing in the correct direction (in the x-y-plane).

The code does not check, if the entity can be really seen. So if the player for example looks at it trough a wall within the proper range, it will be activated, too. I plan to add this feature later on. In the meantime, you should adjust the distance spawnarg to get the desired effect.