Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
traptrigger.c
Go to the documentation of this file.
1 class TrapTrigger : Trigger
3 {
4  bool m_Enabled = false;
5  TrapBase m_ParentObj;
6 
7  #ifdef DEVELOPER
8  bool m_CanSendDbg = true;
9  #endif
10 
11  void TrapTrigger()
12  {
13  int mask = GetEventMask();
14  mask &= ~EntityEvent.INIT;
15  SetEventMask(mask);
16  }
17 
18  void SetParentObject( TrapBase obj )
19  {
20  if (GetGame().IsServer())
21  {
22  m_ParentObj = obj;
23  }
24  }
25 
26  override protected bool CanAddObjectAsInsider(Object object)
27  {
28  return m_Enabled && object.IsInherited(EntityAI) && m_ParentObj && m_ParentObj.IsActive() && m_ParentObj.GetTrapTrigger() == this;
29  }
30 
31  override protected void OnEnterServerEvent(TriggerInsider insider)
32  {
33  #ifdef DEVELOPER
34  m_CanSendDbg = false;
35  #endif
36 
37  if (m_ParentObj && m_ParentObj.IsActive())
38  {
39  m_ParentObj.SnapOnObject(EntityAI.Cast(insider.GetObject()));
40  }
41  }
42 
43  override protected void OnLeaveServerEvent(TriggerInsider insider)
44  {
45  if (m_ParentObj && m_ParentObj.IsActive())
46  {
47  m_ParentObj.RemoveFromObject(EntityAI.Cast(insider.GetObject()));
48  }
49  }
50 
52  void SetEnabled()
53  {
54  m_Enabled = true;
55  }
56 
57  #ifdef DEVELOPER
58  override void DebugSendDmgTrigger()
59  {
60  if ( m_CanSendDbg )
61  super.DebugSendDmgTrigger();
62  }
63 
64  #endif
65 }
66 
67 // Used for tripwire type traps, where we want to allow players to go through
68 class TripWireTrigger : TrapTrigger
69 {
70  override protected void OnEnterServerEvent( TriggerInsider insider )
71  {
72  PlayerBase playerInsider = PlayerBase.Cast(insider.GetObject());
73 
74  if (playerInsider)
75  {
76  // If the player is jogging / sprinting while standing with or without hands raised, tripwire will trigger
77  bool isErect = ( playerInsider.m_MovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_ERECT || playerInsider.m_MovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_RAISEDERECT || playerInsider.m_MovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_RAISEDCROUCH );
78  bool isJogging = ( playerInsider.m_MovementState.m_iMovement == DayZPlayerConstants.MOVEMENTIDX_RUN || playerInsider.m_MovementState.m_iMovement == DayZPlayerConstants.MOVEMENTIDX_SPRINT );
79  if (isJogging && isErect)
80  {
81  super.OnEnterServerEvent(insider);
82  return;
83  }
84 
85  // Special handling of crouch sprint
86  if ( playerInsider.m_MovementState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_CROUCH && playerInsider.m_MovementState.m_iMovement == DayZPlayerConstants.MOVEMENTIDX_SPRINT )
87  {
88  super.OnEnterServerEvent(insider);
89  return;
90  }
91  }
92  else
93  {
94  super.OnEnterServerEvent(insider);
95  }
96  }
97 }
GetGame
proto native CGame GetGame()
OnEnterServerEvent
TrapTrigger Trigger OnEnterServerEvent(TriggerInsider insider)
Definition: traptrigger.c:70
TriggerInsider
The object which is in a trigger and its metadata.
Definition: trigger.c:2
m_ParentObj
TrapBase m_ParentObj
Definition: traptrigger.c:3
m_Enabled
bool m_Enabled
Definition: traptrigger.c:2
PlayerBase
Definition: playerbaseclient.c:1
Trigger
Scripted Trigger.
Definition: hologram.c:1573
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
Object
Definition: objecttyped.c:1
TrapTrigger
Trigger used by traps.
Definition: traptrigger.c:2
EntityEvent
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition: enentity.c:44
EntityAI
Definition: building.c:5
TrapBase
Definition: trap_bear.c:1