DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
AreaDamageLooped.c
Go to the documentation of this file.
2{
4 protected float m_CurrentTime = 0.0;
6 protected float m_PreviousTime = 0.0;
8 protected float m_AccumulatedTime = 0.0;
10 protected float m_LoopInterval = 1.0;
11
13 protected int m_AmountOfLoops = 0;
14
16 protected bool m_LoopByObject = true;
17
18 void AreaDamageLooped(EntityAI parent, bool loopByObject = true)
19 {
20 m_LoopByObject = loopByObject;
21 }
22
24 override void OnTriggerCreated()
25 {
26 super.OnTriggerCreated();
27
28 m_PreviousTime = g_Game.GetTickTime();
30 }
31
32 override void SetLoopInterval( float time )
33 {
34 m_LoopInterval = time;
35 }
36
37 override void OnEnterServerEvent(TriggerInsider insider)
38 {
39 super.OnEnterServerEvent(insider);
40
41 // Do direct damaging first time on entering
43 OnEvaluateDamageEx(insider, 1);
44 }
45
46 override void OnStayStartServerEvent(int nrOfInsiders)
47 {
48 super.OnStayStartServerEvent(nrOfInsiders);
49
50 m_CurrentTime = g_Game.GetTickTime();
53
55 }
56
57 override void OnStayServerEvent(TriggerInsider insider, float deltaTime)
58 {
59 super.OnStayServerEvent(insider, deltaTime);
60
61 // As we are using the Ex variant, we can put the logic in CalculateDamageScale
62 OnEvaluateDamageEx(insider, deltaTime);
63 }
64
66 {
67 super.OnStayFinishServerEvent();
68
70 }
71
72 // TODO: EMH: OnLeaveServerEvent -> perform the remaining buffered damage to be done?
73
74 override protected float CalculateDamageScale(TriggerInsider insider, float deltaTime)
75 {
76 // If we want the LoopInterval to be dependant on the Object, we will need their lastDamaged time
78 {
79 float lastDamaged = 0;
80
82 if ( CastTo( dInsider, insider ) )
83 lastDamaged = dInsider.lastDamaged;
84
85 // First time it is damaged, do full damage
86 if (lastDamaged == 0)
87 return 1;
88
89 // This way, in case the server lags, it will scale the damage to catch up if necessary
90 // We want to wait until it is at least above 1, to not spam the network with hit messages
91 float damageCoeff = (m_CurrentTime - lastDamaged) / m_LoopInterval;
92 if ( damageCoeff >= 1 )
93 return damageCoeff;
94
95 return 0;
96 }
97 else
98 {
99 return m_AmountOfLoops;
100 }
101 }
102}
bool OnEvaluateDamageEx(TriggerInsider insider, float deltaTime)
void AreaDamageManager(EntityAI parent)
DayZGame g_Game
Definition DayZGame.c:3654
protected bool m_LoopByObject
Decides if the looping will be using the Object as reference or the time since last update loop.
override void OnStayServerEvent(TriggerInsider insider, float deltaTime)
override protected float CalculateDamageScale(TriggerInsider insider, float deltaTime)
protected float m_AccumulatedTime
How much time has accumulated.
protected int m_AmountOfLoops
Caching of the amount of loops that will be performed in this frame.
override void OnStayStartServerEvent(int nrOfInsiders)
override void OnStayFinishServerEvent()
protected float m_LoopInterval
Loop interval in seconds.
void AreaDamageLooped(EntityAI parent, bool loopByObject=true)
override void OnTriggerCreated()
Gets called when the trigger is spawned, so is the start and also a reset.
protected float m_CurrentTime
Current start time in seconds.
override void OnEnterServerEvent(TriggerInsider insider)
protected float m_PreviousTime
Previous start time in seconds.
override void SetLoopInterval(float time)
Extended TriggerInsider for AreaDamageTriggerBase.
float lastDamaged
Last time the object was damaged in seconds.
The object which is in a trigger and its metadata.
Definition Trigger.c:3