DayZ 1.26
DayZ Explorer by KGB
Загрузка...
Поиск...
Не найдено
Класс Trigger

Scripted Trigger. Подробнее...

+ Граф наследования:Trigger:

Защищенные члены

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)
 

Защищенные данные

int m_TriggerUpdateMs
 
Hologram m_ParentObj
 
PlayerBase m_Player
 

Закрытые члены

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.
 
- Закрытые члены унаследованные от 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)
 

Закрытые данные

const int TIMEOUT = 1000
 DEPRECATED.
 
ref array< ref TriggerInsiderm_insiders
 The objects and their metadata which are currently inside the Trigger.
 
- Закрытые данные унаследованные от TriggerEvents
ref ScriptInvoker m_OnEnterInvoker
 
ref ScriptInvoker m_OnLeaveInvoker
 

Подробное описание

Scripted Trigger.

Конструктор(ы)

◆ Trigger()

void Trigger ( )
inlineprivate

ctor

54 {
55 SetEventMask(EntityEvent.INIT /*| EntityEvent.TOUCH*/ | EntityEvent.FRAME | EntityEvent.ENTER | EntityEvent.LEAVE );
56 SetFlags(EntityFlags.TRIGGER, false);
57
59 }
Definition EntityAI.c:95
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:45
EntityFlags
Entity flags.
Definition EnEntity.c:115

Перекрестные ссылки m_insiders и SetFlags().

◆ ~Trigger()

void ~Trigger ( )
inlineprivate

dtor

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

Методы

◆ AddInsider()

void AddInsider ( Object obj)
inlineprotected

Adding of new TriggerInsider.

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:3815
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:181
void Enter(TriggerInsider insider)
Definition TriggerEvents.c:26
bool ShouldRemoveInsider(TriggerInsider insider)
Condition whether a TriggerInsider should still be updated or not (checked in update loop and before ...
Definition Trigger.c:204
TriggerInsider CreateInsider(Object obj)
Used for easily overriding TriggerInsider creation without rewriting AddInsider.
Definition Trigger.c:222
bool ShouldRemoveInsiderNoLeave(TriggerInsider insider)
Condition whether a TriggerInsider should still be updated or not, skips OnLeaveEvent (checked in upd...
Definition Trigger.c:210
TriggerInsider GetInsiderForObject(Object object)
Gets the TriggerInsider for the Object if it exists.
Definition Trigger.c:134
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()
Definition dayzplayer.c:1170
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90

Перекрестные ссылки CreateInsider(), TriggerEvents::Enter(), Error(), g_Game, GetDebugName(), GetInsiderForObject(), TriggerInsider::lastUpdated, m_insiders, ShouldRemoveInsider(), ShouldRemoveInsiderNoLeave(), TriggerInsider::timeEntered, TriggerInsider::timeStamp и Debug::TriggerLog().

Используется в EOnEnter().

◆ CanAddObjectAsInsider()

bool CanAddObjectAsInsider ( Object object)
inlineprotected

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

199 {
200 return true;
201 }

Используется в EOnEnter().

◆ CreateInsider()

TriggerInsider CreateInsider ( Object obj)
inlineprotected

Used for easily overriding TriggerInsider creation without rewriting AddInsider.

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

Используется в AddInsider().

◆ EOnEnter()

override void EOnEnter ( IEntity other,
int extra )
inlineprivate

When an Object enters the trigger add it to Insiders.

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
Definition ObjectTyped.c:2
void AddInsider(Object obj)
Adding of new TriggerInsider.
Definition Trigger.c:228
bool CanAddObjectAsInsider(Object object)
Condition whether an Object can be added as TriggerInsider (checked before calling AddInsider)
Definition Trigger.c:198
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.

Перекрестные ссылки AddInsider(), CanAddObjectAsInsider() и Class::CastTo().

◆ EOnFrame()

override void 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?)

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

Перекрестные ссылки TIMEOUT и UpdateInsiders().

◆ EOnInit()

override void EOnInit ( IEntity other,
int extra )
inlineprivate

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

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

Перекрестные ссылки SetExtents().

◆ EOnLeave()

override void EOnLeave ( IEntity other,
int extra )
inlineprivate

When an Object exits the trigger remove it from Insiders.

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

Перекрестные ссылки Class::CastTo() и RemoveInsiderByObject().

◆ GetInsiderForObject()

TriggerInsider GetInsiderForObject ( Object object)
inlineprivate

Gets the TriggerInsider for the Object if it exists.

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 }

Перекрестные ссылки m_insiders.

Используется в AddInsider().

◆ GetInsiderIndexForObject()

int GetInsiderIndexForObject ( Object object)
inlineprivate

Gets the index in m_insiders for the Object.

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 }

Перекрестные ссылки m_insiders.

◆ GetInsiders()

array< ref TriggerInsider > GetInsiders ( )
inlineprivate

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

129 {
130 return m_insiders;
131 }

Перекрестные ссылки m_insiders.

Используется в ConstructionBoxTrigger::IsColliding().

◆ GetRadius()

float GetRadius ( vector min,
vector max )
inlineprivate

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

123 {
124 return GetCollisionRadius();
125 }

◆ OnEnter() [1/2]

override void OnEnter ( Object obj)
inlineprotected
1577 {
1578 //Print("OnEnter");
1579 if ( m_ParentObj )
1580 {
1582 m_TriggerUpdateMs = 50;
1583 }
1584 }
void SetIsCollidingPlayer(bool is_colliding)
Definition Hologram.c:1306
Hologram m_ParentObj
Definition Hologram.c:1573
int m_TriggerUpdateMs
Definition Hologram.c:1572

Перекрестные ссылки m_ParentObj.

Используется в OnEnterBeginEvent().

◆ OnEnter() [2/2]

void OnEnter ( Object obj)
inlineprotected
187{}

◆ OnEnterBeginEvent()

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

Перекрестные ссылки TriggerInsider::GetObject() и OnEnter().

◆ OnLeave() [1/2]

override void OnLeave ( Object obj)
inlineprotected
1587 {
1588 //Print("OnLeave");
1589 if ( m_ParentObj )
1590 {
1592 }
1593 }

Перекрестные ссылки m_ParentObj.

Используется в OnLeaveBeginEvent().

◆ OnLeave() [2/2]

void OnLeave ( Object obj)
inlineprotected
189{}

◆ OnLeaveBeginEvent()

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

Перекрестные ссылки TriggerInsider::GetObject() и OnLeave().

◆ OnRPC()

override void OnRPC ( PlayerIdentity sender,
int rpc_type,
ParamsReadContext ctx )
inlineprotected
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
Definition EnConvert.c:106
static const vector Zero
Definition EnConvert.c:110

Перекрестные ссылки vector::Zero.

◆ RemoveInsider()

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

Removing of TriggerInsider.

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)
Definition TriggerEvents.c:129

Перекрестные ссылки GetDebugName(), TriggerInsider::GetObject(), TriggerEvents::Leave(), m_insiders и Debug::TriggerLog().

Используется в RemoveInsiderByObject() и UpdateInsiders().

◆ RemoveInsiderByObject()

void RemoveInsiderByObject ( Object object)
inlineprotected

Removing of TriggerInsider through Object.

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

Перекрестные ссылки m_insiders и RemoveInsider().

Используется в EOnLeave().

◆ SetExtents()

void SetExtents ( vector mins,
vector maxs )
inlineprivate

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

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

Перекрестные ссылки SetCollisionBox().

Используется в CreateCollisionTrigger(), CreateTrigger(), TrapBase::CreateTrigger(), ManTrigger::EOnInit() и EOnInit().

◆ SetParentObject()

void SetParentObject ( Hologram projection)
inlineprotected
1601 {
1603 }

Перекрестные ссылки m_ParentObj.

◆ SetParentOwner()

void SetParentOwner ( PlayerBase player)
inlineprotected
1606 {
1607 m_Player = player;
1608 }
PlayerBase m_Player
Definition Hologram.c:1574

Перекрестные ссылки m_Player.

◆ ShouldRemoveInsider()

bool ShouldRemoveInsider ( TriggerInsider insider)
inlineprotected

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

205 {
206 return false;
207 }

Используется в AddInsider() и UpdateInsiders().

◆ ShouldRemoveInsiderNoLeave()

bool ShouldRemoveInsiderNoLeave ( TriggerInsider insider)
inlineprotected

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

211 {
212 return false;
213 }

Используется в AddInsider() и UpdateInsiders().

◆ UpdateInsiders() [1/2]

void UpdateInsiders ( int timeout)
inlineprotected
1596 {
1597 super.UpdateInsiders(m_TriggerUpdateMs);
1598 }

Используется в EOnFrame().

◆ UpdateInsiders() [2/2]

void UpdateInsiders ( int timeout)
inlineprotected

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

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 Stay(TriggerInsider insider, float deltaTime)
Definition TriggerEvents.c:79
void StayStart(int nrOfInsiders)
Definition TriggerEvents.c:54
void StayFinish()
Definition TriggerEvents.c:104

Перекрестные ссылки g_Game, GetDebugName(), TriggerInsider::GetObject(), TriggerInsider::lastUpdated, m_insiders, RemoveInsider(), ShouldRemoveInsider(), ShouldRemoveInsiderNoLeave(), TriggerEvents::Stay(), TriggerEvents::StayFinish(), TriggerEvents::StayStart() и Debug::TriggerLog().

Поля

◆ m_insiders

ref array<ref TriggerInsider> m_insiders
private

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

Используется в AddInsider(), GetInsiderForObject(), GetInsiderIndexForObject(), GetInsiders(), RemoveInsider(), RemoveInsiderByObject(), Trigger() и UpdateInsiders().

◆ m_ParentObj

Hologram m_ParentObj
protected

◆ m_Player

PlayerBase m_Player
protected

◆ m_TriggerUpdateMs

int m_TriggerUpdateMs
protected

◆ TIMEOUT

const int TIMEOUT = 1000
private

DEPRECATED.

Используется в EOnFrame().


Объявления и описания членов классов находятся в файлах: