DayZ 1.24
Loading...
Searching...
No Matches
Trigger Class Reference

Scripted Trigger. More...

Inheritance diagram for Trigger:
[legend]
Collaboration diagram for Trigger:
[legend]

Protected Member Functions

override void OnEnter (Object obj)
 
override void OnLeave (Object obj)
 
void UpdateInsiders (int timeout)
 
void SetParentObject (Hologram projection)
 
void SetParentOwner (PlayerBase player)
 
TriggerEvents, backwards compatibility calling

Implementation for backwards compatibility with old Trigger system

void OnEnterBeginEvent (TriggerInsider insider)
 
void OnLeaveBeginEvent (TriggerInsider insider)
 
DEPRECATED Events

left for backwards compatibility

void OnEnter (Object obj)
 
void OnLeave (Object obj)
 
TriggerInsider conditions

Conditions applied to TriggerInsider for if it can be added or should be removed

bool CanAddObjectAsInsider (Object object)
 Condition whether an Object can be added as TriggerInsider (checked before calling AddInsider)
 
bool ShouldRemoveInsider (TriggerInsider insider)
 Condition whether a TriggerInsider should still be updated or not (checked in update loop and before adding)
 
bool ShouldRemoveInsiderNoLeave (TriggerInsider insider)
 Condition whether a TriggerInsider should still be updated or not, skips OnLeaveEvent (checked in update loop and before adding)
 
TriggerInsider processing

Logic and processing of adding, removing and updating a TriggerInsider

TriggerInsider CreateInsider (Object obj)
 Used for easily overriding TriggerInsider creation without rewriting AddInsider.
 
void AddInsider (Object obj)
 Adding of new TriggerInsider.
 
void RemoveInsider (TriggerInsider insider, int index=-1)
 Removing of TriggerInsider.
 
void RemoveInsiderByObject (Object object)
 Removing of TriggerInsider through Object.
 
void UpdateInsiders (int timeout)
 Update the current TriggerInsider inside the Trigger, timeout paramter is deprecated.
 
DEBUGGING

General internal debugging functionality

override void OnRPC (PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
 

Protected Attributes

int m_TriggerUpdateMs
 
Hologram m_ParentObj
 
PlayerBase m_Player
 

Private Member Functions

void Trigger ()
 ctor
 
void ~Trigger ()
 dtor
 
IEntity events

Usage of IEntity events

override void EOnInit (IEntity other, int extra)
 Set the default extents of the Trigger only once it is properly initialized.
 
override void EOnFrame (IEntity other, float timeSlice)
 When an Object touches the Trigger, we want to register it being inside the Trigger -> Replaced by EOnEnter.
 
override void EOnEnter (IEntity other, int extra)
 When an Object enters the trigger add it to Insiders.
 
override void EOnLeave (IEntity other, int extra)
 When an Object exits the trigger remove it from Insiders.
 
Trigger configuration

Basic configuration and data API

void SetExtents (vector mins, vector maxs)
 Set the size of the Trigger, avoid using SetCollisionBox directly.
 
float GetRadius (vector min, vector max)
 Get the radius of the CollisionBox, simply left for backwards compatibility.
 
array< ref TriggerInsiderGetInsiders ()
 Get the current TriggerInsider array, left for backwards compatibility, moved down from ManTrigger.
 
TriggerInsider GetInsiderForObject (Object object)
 Gets the TriggerInsider for the Object if it exists.
 
int GetInsiderIndexForObject (Object object)
 Gets the index in m_insiders for the Object.
 
- Private Member Functions inherited from TriggerEvents
ScriptInvoker GetOnEnterInvoker ()
 
ScriptInvoker GetOnLeaveInvoker ()
 
void Enter (TriggerInsider insider)
 
void OnEnterBeginEvent (TriggerInsider insider)
 
void OnEnterServerEvent (TriggerInsider insider)
 
void OnEnterClientEvent (TriggerInsider insider)
 
void OnEnterEndEvent (TriggerInsider insider)
 
void StayStart (int nrOfInsiders)
 
void OnStayStartBeginEvent (int nrOfInsiders)
 
void OnStayStartServerEvent (int nrOfInsiders)
 
void OnStayStartClientEvent (int nrOfInsiders)
 
void OnStayStartEndEvent (int nrOfInsiders)
 
void Stay (TriggerInsider insider, float deltaTime)
 
void OnStayBeginEvent (TriggerInsider insider, float deltaTime)
 
void OnStayServerEvent (TriggerInsider insider, float deltaTime)
 
void OnStayClientEvent (TriggerInsider insider, float deltaTime)
 
void OnStayEndEvent (TriggerInsider insider, float deltaTime)
 
void StayFinish ()
 
void OnStayFinishBeginEvent ()
 
void OnStayFinishServerEvent ()
 
void OnStayFinishClientEvent ()
 
void OnStayFinishEndEvent ()
 
void Leave (TriggerInsider insider)
 
void OnLeaveBeginEvent (TriggerInsider insider)
 
void OnLeaveServerEvent (TriggerInsider insider)
 
void OnLeaveClientEvent (TriggerInsider insider)
 
void OnLeaveEndEvent (TriggerInsider insider)
 

Private Attributes

const int TIMEOUT = 1000
 DEPRECATED.
 
ref array< ref TriggerInsiderm_insiders
 The objects and their metadata which are currently inside the Trigger.
 
- Private Attributes inherited from TriggerEvents
ref ScriptInvoker m_OnEnterInvoker
 
ref ScriptInvoker m_OnLeaveInvoker
 

Detailed Description

Scripted Trigger.

Definition at line 1517 of file Hologram.c.

Constructor & Destructor Documentation

◆ Trigger()

void Trigger::Trigger ( )
inlineprivate

ctor

Definition at line 53 of file Trigger.c.

54 {
55 SetEventMask(EntityEvent.INIT /*| EntityEvent.TOUCH*/ | EntityEvent.FRAME | EntityEvent.ENTER | EntityEvent.LEAVE);
56 SetFlags(EntityFlags.TRIGGER, false);
57
59 }
ref array< ref TriggerInsider > m_insiders
The objects and their metadata which are currently inside the Trigger.
Definition Trigger.c:44
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition EnEntity.c:44
EntityFlags
Entity flags.
Definition EnEntity.c:114

References m_insiders, and SetFlags().

◆ ~Trigger()

void Trigger::~Trigger ( )
inlineprivate

dtor

Definition at line 62 of file Trigger.c.

63 {
64#ifdef DIAG_DEVELOPER
65 CleanupDebugShapes(dbgTargets);
66#endif
67 }

Member Function Documentation

◆ AddInsider()

void Trigger::AddInsider ( Object obj)
inlineprotected

Adding of new TriggerInsider.

Definition at line 228 of file Trigger.c.

229 {
230 if (!obj)
231 return;
232
233 // Already in?
234 if (GetInsiderForObject(obj))
235 {
236 Error(string.Format("[WARNING] :: [Trigger] :: [%1] :: Insider (%2) is already inside.", GetDebugName(this), GetDebugName(obj)));
237 return;
238 }
239
240 // New Object entered! Fill the data.
241 TriggerInsider insider = CreateInsider(obj);
242 insider.timeStamp = g_Game.GetTime();
243 insider.timeEntered = g_Game.GetTickTime();
244 insider.lastUpdated = insider.timeEntered;
245
246 // Don't add if it is going to be removed anyways..
247 if (ShouldRemoveInsider(insider) || ShouldRemoveInsiderNoLeave(insider))
248 return;
249
250 // Keep track of the Object as long as it is inside the Trigger
251 int index = m_insiders.Insert(insider);
252
253 // Call the enter event to signal this Object entered
254 Enter(insider);
255 obj.OnEnterTrigger(this);
256
257#ifdef TRIGGER_DEBUG_NORMAL
258 Debug.TriggerLog(string.Format("%1: inserted at index %2", GetDebugName(obj), index), "Trigger", "", "AddInsider", GetDebugName(this));
259#endif
260 }
DayZGame g_Game
Definition DayZGame.c:3528
Definition Debug.c:14
static void TriggerLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Definition Debug.c:223
void Enter(TriggerInsider insider)
TriggerInsider CreateInsider(Object obj)
Used for easily overriding TriggerInsider creation without rewriting AddInsider.
Definition Trigger.c:222
TriggerInsider GetInsiderForObject(Object object)
Gets the TriggerInsider for the Object if it exists.
Definition Trigger.c:134
bool ShouldRemoveInsider(TriggerInsider insider)
Condition whether a TriggerInsider should still be updated or not (checked in update loop and before ...
Definition Trigger.c:204
bool ShouldRemoveInsiderNoLeave(TriggerInsider insider)
Condition whether a TriggerInsider should still be updated or not, skips OnLeaveEvent (checked in upd...
Definition Trigger.c:210
The object which is in a trigger and its metadata.
Definition Trigger.c:3
int timeStamp
Last time the object was seen in ms.
Definition Trigger.c:10
float lastUpdated
Last time the object was updated in seconds, is used for calculating deltaTime.
Definition Trigger.c:16
float timeEntered
Time the object was first seen in seconds.
Definition Trigger.c:13
override string GetDebugName()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90

References CreateInsider(), TriggerEvents::Enter(), Error(), g_Game, GetDebugName(), GetInsiderForObject(), TriggerInsider::lastUpdated, m_insiders, ShouldRemoveInsider(), ShouldRemoveInsiderNoLeave(), TriggerInsider::timeEntered, TriggerInsider::timeStamp, and Debug::TriggerLog().

Referenced by EOnEnter().

◆ CanAddObjectAsInsider()

bool Trigger::CanAddObjectAsInsider ( Object object)
inlineprotected

Condition whether an Object can be added as TriggerInsider (checked before calling AddInsider)

Definition at line 198 of file Trigger.c.

199 {
200 return true;
201 }

Referenced by EOnEnter().

◆ CreateInsider()

TriggerInsider Trigger::CreateInsider ( Object obj)
inlineprotected

Used for easily overriding TriggerInsider creation without rewriting AddInsider.

Definition at line 222 of file Trigger.c.

223 {
224 return new TriggerInsider(obj);
225 }

Referenced by AddInsider().

◆ EOnEnter()

override void Trigger::EOnEnter ( IEntity other,
int extra )
inlineprivate

When an Object enters the trigger add it to Insiders.

Definition at line 94 of file Trigger.c.

95 {
96 Object obj;
97 if (Class.CastTo(obj, other) && CanAddObjectAsInsider(obj))
98 AddInsider(obj);
99 }
Super root of all classes in Enforce script.
Definition EnScript.c:11
bool CanAddObjectAsInsider(Object object)
Condition whether an Object can be added as TriggerInsider (checked before calling AddInsider)
Definition Trigger.c:198
void AddInsider(Object obj)
Adding of new TriggerInsider.
Definition Trigger.c:228
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.

References AddInsider(), CanAddObjectAsInsider(), and Class::CastTo().

◆ EOnFrame()

override void Trigger::EOnFrame ( IEntity other,
float timeSlice )
inlineprivate

When an Object touches the Trigger, we want to register it being inside the Trigger -> Replaced by EOnEnter.

We want to update the insiders every frame (or do we?)

Definition at line 88 of file Trigger.c.

89 {
91 }
void UpdateInsiders(int timeout)
Definition Hologram.c:1540
const int TIMEOUT
DEPRECATED.
Definition Trigger.c:42

References TIMEOUT, and UpdateInsiders().

◆ EOnInit()

override void Trigger::EOnInit ( IEntity other,
int extra )
inlineprivate

Set the default extents of the Trigger only once it is properly initialized.

Definition at line 74 of file Trigger.c.

75 {
76 SetExtents("-2 -4 -2", "2 4 2");
77 }
void SetExtents(vector mins, vector maxs)
Set the size of the Trigger, avoid using SetCollisionBox directly.
Definition Trigger.c:116

References SetExtents().

◆ EOnLeave()

override void Trigger::EOnLeave ( IEntity other,
int extra )
inlineprivate

When an Object exits the trigger remove it from Insiders.

Definition at line 102 of file Trigger.c.

103 {
104 Object obj;
105 if (Class.CastTo(obj, other))
107 }
void RemoveInsiderByObject(Object object)
Removing of TriggerInsider through Object.
Definition Trigger.c:279

References Class::CastTo(), and RemoveInsiderByObject().

◆ GetInsiderForObject()

TriggerInsider Trigger::GetInsiderForObject ( Object object)
inlineprivate

Gets the TriggerInsider for the Object if it exists.

Definition at line 134 of file Trigger.c.

135 {
137
138 for (int n = 0; n < m_insiders.Count(); ++n)
139 {
140 ins = m_insiders[n];
141 if (ins.GetObject() == object)
142 return ins;
143 }
144
145 return null;
146 }

References m_insiders.

Referenced by AddInsider().

◆ GetInsiderIndexForObject()

int Trigger::GetInsiderIndexForObject ( Object object)
inlineprivate

Gets the index in m_insiders for the Object.

Definition at line 149 of file Trigger.c.

150 {
152
153 for (int n = 0; n < m_insiders.Count(); ++n)
154 {
155 ins = m_insiders[n];
156 if (ins.GetObject() == object)
157 return n;
158 }
159
160 return -1;
161 }

References m_insiders.

◆ GetInsiders()

array< ref TriggerInsider > Trigger::GetInsiders ( )
inlineprivate

Get the current TriggerInsider array, left for backwards compatibility, moved down from ManTrigger.

Definition at line 128 of file Trigger.c.

129 {
130 return m_insiders;
131 }

References m_insiders.

Referenced by ConstructionBoxTrigger::IsColliding().

◆ GetRadius()

float Trigger::GetRadius ( vector min,
vector max )
inlineprivate

Get the radius of the CollisionBox, simply left for backwards compatibility.

Definition at line 122 of file Trigger.c.

123 {
124 return GetCollisionRadius();
125 }

◆ OnEnter() [1/2]

override void Trigger::OnEnter ( Object obj)
inlineprotected

Definition at line 1523 of file Hologram.c.

1524 {
1525 //Print("OnEnter");
1526 if (m_ParentObj)
1527 {
1529 m_TriggerUpdateMs = 50;
1530 }
1531 }
void SetIsCollidingPlayer(bool is_colliding)
Definition Hologram.c:1263
Hologram m_ParentObj
Definition Hologram.c:1520
int m_TriggerUpdateMs
Definition Hologram.c:1519

References m_ParentObj.

Referenced by OnEnterBeginEvent().

◆ OnEnter() [2/2]

void Trigger::OnEnter ( Object obj)
inlineprotected

Definition at line 187 of file Trigger.c.

187{}

◆ OnEnterBeginEvent()

void Trigger::OnEnterBeginEvent ( TriggerInsider insider)
inlineprotected

Definition at line 169 of file Trigger.c.

170 {
171 // Call the old event for backwards compatibility
172 OnEnter(insider.GetObject());
173 }
override void OnEnter(Object obj)
Definition Hologram.c:1523
Object GetObject()
Definition Trigger.c:28

References TriggerInsider::GetObject(), and OnEnter().

◆ OnLeave() [1/2]

override void Trigger::OnLeave ( Object obj)
inlineprotected

Definition at line 1533 of file Hologram.c.

1534 {
1535 //Print("OnLeave");
1536 if (m_ParentObj)
1538 }

References m_ParentObj.

Referenced by OnLeaveBeginEvent().

◆ OnLeave() [2/2]

void Trigger::OnLeave ( Object obj)
inlineprotected

Definition at line 189 of file Trigger.c.

189{}

◆ OnLeaveBeginEvent()

void Trigger::OnLeaveBeginEvent ( TriggerInsider insider)
inlineprotected

Definition at line 175 of file Trigger.c.

176 {
177 // Call the old event for backwards compatibility
178 OnLeave(insider.GetObject());
179 }
override void OnLeave(Object obj)
Definition Hologram.c:1533

References TriggerInsider::GetObject(), and OnLeave().

◆ OnRPC()

override void Trigger::OnRPC ( PlayerIdentity sender,
int rpc_type,
ParamsReadContext ctx )
inlineprotected

Definition at line 350 of file Trigger.c.

351 {
352 super.OnRPC(sender, rpc_type, ctx);
353
354#ifdef DIAG_DEVELOPER
355 switch (rpc_type)
356 {
357 case ERPCs.DIAG_TRIGGER_DEBUG:
359
360 if (ctx.Read(data))
361 DebugDmgTrigger(data.param1, data.param2, data.param3, data.param4, data.param5, data.param6, data.param7);
362 break;
363 }
364#endif
365 }
ERPCs
Definition ERPCs.c:2
static const vector Zero
Definition EnConvert.c:110

References vector::Zero.

◆ RemoveInsider()

void Trigger::RemoveInsider ( TriggerInsider insider,
int index = -1 )
inlineprotected

Removing of TriggerInsider.

Definition at line 263 of file Trigger.c.

264 {
265 Leave(insider);
266 insider.GetObject().OnLeaveTrigger(this);
267
268#ifdef TRIGGER_DEBUG_NORMAL
269 Debug.TriggerLog(string.Format("%1: removing at index %2", GetDebugName(insider.GetObject()), index), "Trigger", "", "RemoveInsider", GetDebugName(this));
270#endif
271
272 if (index >= 0)
273 m_insiders.Remove(index);
274 else
275 m_insiders.RemoveItemUnOrdered(insider);
276 }
void Leave(TriggerInsider insider)

References GetDebugName(), TriggerInsider::GetObject(), TriggerEvents::Leave(), m_insiders, and Debug::TriggerLog().

Referenced by RemoveInsiderByObject(), and UpdateInsiders().

◆ RemoveInsiderByObject()

void Trigger::RemoveInsiderByObject ( Object object)
inlineprotected

Removing of TriggerInsider through Object.

Definition at line 279 of file Trigger.c.

280 {
282 for (int n = 0; n < m_insiders.Count(); ++n)
283 {
284 ins = m_insiders[n];
285 if (ins.GetObject() == object)
286 {
288 return;
289 }
290 }
291
292 // As EOnLeave can call this, it is perfectly valid that this Object is not found on Script side
293 // because of "ShouldRemoveInsider" and "ShouldRemoveInsiderNoLeave"
294 }
void RemoveInsider(TriggerInsider insider, int index=-1)
Removing of TriggerInsider.
Definition Trigger.c:263

References m_insiders, and RemoveInsider().

Referenced by EOnLeave().

◆ SetExtents()

void Trigger::SetExtents ( vector mins,
vector maxs )
inlineprivate

Set the size of the Trigger, avoid using SetCollisionBox directly.

Definition at line 116 of file Trigger.c.

117 {
119 }
proto native void SetCollisionBox(vector mins, vector maxs)
Sets collision box for object.

References SetCollisionBox().

Referenced by CreateCollisionTrigger(), CreateTrigger(), TrapBase::CreateTrigger(), ManTrigger::EOnInit(), and EOnInit().

◆ SetParentObject()

void Trigger::SetParentObject ( Hologram projection)
inlineprotected

Definition at line 1545 of file Hologram.c.

1546 {
1548 }

References m_ParentObj.

◆ SetParentOwner()

void Trigger::SetParentOwner ( PlayerBase player)
inlineprotected

Definition at line 1550 of file Hologram.c.

1551 {
1552 m_Player = player;
1553 }
PlayerBase m_Player
Definition Hologram.c:1521

References m_Player.

◆ ShouldRemoveInsider()

bool Trigger::ShouldRemoveInsider ( TriggerInsider insider)
inlineprotected

Condition whether a TriggerInsider should still be updated or not (checked in update loop and before adding)

Definition at line 204 of file Trigger.c.

205 {
206 return false;
207 }

Referenced by AddInsider(), and UpdateInsiders().

◆ ShouldRemoveInsiderNoLeave()

bool Trigger::ShouldRemoveInsiderNoLeave ( TriggerInsider insider)
inlineprotected

Condition whether a TriggerInsider should still be updated or not, skips OnLeaveEvent (checked in update loop and before adding)

Definition at line 210 of file Trigger.c.

211 {
212 return false;
213 }

Referenced by AddInsider(), and UpdateInsiders().

◆ UpdateInsiders() [1/2]

void Trigger::UpdateInsiders ( int timeout)
inlineprotected

Definition at line 1540 of file Hologram.c.

1541 {
1542 super.UpdateInsiders(m_TriggerUpdateMs);
1543 }

Referenced by EOnFrame().

◆ UpdateInsiders() [2/2]

void Trigger::UpdateInsiders ( int timeout)
inlineprotected

Update the current TriggerInsider inside the Trigger, timeout paramter is deprecated.

Definition at line 297 of file Trigger.c.

298 {
299#ifdef DIAG_DEVELOPER
301#endif
302
303 // Don't do anything if there aren't any insiders
304 if (m_insiders.Count() == 0)
305 return;
306
307 // Mark the beginning of the update loop
308 StayStart(m_insiders.Count());
309
310 // Iterate over the current insiders, backwards because we are deleting
311 for (int n = m_insiders.Count() - 1; n >= 0 ; --n)
312 {
313 TriggerInsider insider = m_insiders.Get(n);
314 Object obj = insider.GetObject();
315
316 // Check if the Object still exists or should be removed without calling OnLeaveEvent
317 if (!obj || ShouldRemoveInsiderNoLeave(insider))
318 {
319#ifdef TRIGGER_DEBUG_BASIC
320 Debug.TriggerLog(string.Format("%1: removed with no Leave.", GetDebugName(obj)), "Trigger", "", "UpdateInsiders", GetDebugName(this));
321#endif
322
323 m_insiders.Remove(n);
324 continue;
325 }
326
327 // Check if Object left the Trigger or should be removed regardless
328 if (ShouldRemoveInsider(insider))
329 {
330 RemoveInsider(insider, n);
331 continue;
332 }
333
334 // Call the OnStayEvent, Object is still inside the Trigger and can be updated
335 // Pass in the time since the Object was last updated (or entered)
336 float currentTime = g_Game.GetTickTime();
337 Stay(insider, currentTime - insider.lastUpdated);
338 insider.lastUpdated = currentTime;
339 }
340
341 // Mark the end of the update loop
342 StayFinish();
343 }
void StayStart(int nrOfInsiders)
void Stay(TriggerInsider insider, float deltaTime)

References g_Game, GetDebugName(), TriggerInsider::GetObject(), TriggerInsider::lastUpdated, m_insiders, RemoveInsider(), ShouldRemoveInsider(), ShouldRemoveInsiderNoLeave(), TriggerEvents::Stay(), TriggerEvents::StayFinish(), TriggerEvents::StayStart(), and Debug::TriggerLog().

Member Data Documentation

◆ m_insiders

ref array<ref TriggerInsider> Trigger::m_insiders
private

The objects and their metadata which are currently inside the Trigger.

Definition at line 44 of file Trigger.c.

Referenced by AddInsider(), GetInsiderForObject(), GetInsiderIndexForObject(), GetInsiders(), RemoveInsider(), RemoveInsiderByObject(), Trigger(), and UpdateInsiders().

◆ m_ParentObj

Hologram Trigger::m_ParentObj
protected

Definition at line 1520 of file Hologram.c.

◆ m_Player

PlayerBase Trigger::m_Player
protected

Definition at line 1521 of file Hologram.c.

◆ m_TriggerUpdateMs

int Trigger::m_TriggerUpdateMs
protected

Definition at line 1519 of file Hologram.c.

◆ TIMEOUT

const int Trigger::TIMEOUT = 1000
private

DEPRECATED.

Definition at line 42 of file Trigger.c.

Referenced by EOnFrame().


The documentation for this class was generated from the following files: