DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ClockBase.c
Go to the documentation of this file.
2{
6 //-----------
9
11{
14 static const float UPDATE_TICK_RATE = 1; // Clock update tick frequency
17 int m_StatePrev = -1;
18
24
25 const float RINGING_DURATION_MAX = 60;//in secs, at or past this value, the clock stops ringing
26
27 void ClockBase()
28 {
29 Init();
30 }
31
33 {
39 }
40
41 void Init()
42 {
43 RegisterNetSyncVariableInt("m_State",0, EAlarmClockState.COUNT - 1);
44 }
45
46 override void SetActions()
47 {
48 super.SetActions();
49
51 }
52
53 protected int GetAlarmInMin()
54 {
55 int alarm_hand_in_mins = ConvertAlarmHand01ToMins12h(m_AlarmTime01);
56
57 int pass, hour, minute;
58 GetGame().GetWorld().GetDate(pass, pass, pass, hour, minute);
59
60 int curr_time_in_minutes = ConvertTimeToMins12h(hour, minute);
61 int ring_in_mins = GetTimeDiffInMins12h(curr_time_in_minutes, alarm_hand_in_mins);
62 return ring_in_mins;
63 }
64
65 static int ConvertAlarmHand01ToMins12h(float time01)
66 {
67 return Math.Lerp(0,12*60,time01);
68 }
69
70 static int ConvertAlarmHand01ToMins(float time01, int mins_max/*what's the upper range in minutes we are trying to map the time01 to*/)
71 {
72 return Math.Lerp(0,mins_max,time01);
73 }
74
75 static float ConvertMins12hToAlarmHand01(int mins)
76 {
77 return Math.InverseLerp(0,12*60,mins);
78 }
79
80
81 static int ConvertTimeToMins12h(int hour, int minute)
82 {
83 if (hour >= 12)
84 hour -= 12;
85 return hour * 60 + minute;
86 }
87
88 static int GetTimeDiffInMins12h(int from_mins, int to_mins)
89 {
90 if (to_mins > from_mins)
91 {
92 return to_mins - from_mins;
93 }
94 else if (to_mins < from_mins)
95 {
96 return ((12 * 60) - from_mins) + to_mins;
97 }
98 else return 0;
99 }
100
102 {
103 return "";
104 }
106 {
107 return "";
108 }
109 string GetHitSound()
110 {
111 return "";
112 }
114 {
115 return "";
116 }
118 {
119 return "";
120 }
121
122 override void EEKilled(Object killer)
123 {
124 super.EEKilled(killer);
125 TurnOff();
126 }
127
128 override void EEHitByRemote(int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos)
129 {
130 super.EEHitByRemote(damageType, source, component, dmgZone, ammo, modelPos);
131 PlaySoundSet( m_HitSound, GetHitSound(), 0, 0 );
132 }
133
134 override void OnDamageDestroyed(int oldLevel)
135 {
136 super.OnDamageDestroyed(oldLevel);
137
138 if (GetGame().IsClient())
139 {
141
142 if (oldLevel != -1)
143 {
144 PlaySoundSet(m_DestoryedSound, GetDestroyedSound(), 0, 0);
145 }
146 }
147 }
148
149 protected void OnRingingStartServer()
150 {
152 }
153
154 protected void OnRingingStartClient()
155 {
156 PlaySoundSetLoop( m_RingingSoundLoop, GetRingingSound(), 0, 0 );
157 if (m_WorkingSound)
158 {
160 }
161 }
162
163 protected void OnRingingStopServer();
164
165 protected void OnRingingStopClient()
166 {
168 }
169
170 void SetAlarmInXMins(int in_mins)
171 {
172 int pass, hour, minute;
173 GetGame().GetWorld().GetDate(pass, pass, pass, hour, minute);
174 int mins12h = ConvertTimeToMins12h(hour, minute) + in_mins;
175 float time01 = ConvertMins12hToAlarmHand01(mins12h);
176 SetAlarmTimeServer(time01);
177 Arm();
178 }
179
181 {
183 }
184
185
186 protected void SetupTimerServer()
187 {
188 m_TimerUpdate = new Timer;
189 m_TimerUpdate.Run(UPDATE_TICK_RATE , this, "OnUpdate", null, true);
190 }
191
192 protected void SetState(EAlarmClockState state)
193 {
194 m_State = state;
195 SetSynchDirty();
196 }
197
198 protected void Disarm()
199 {
201 }
202
203 protected void Arm()
204 {
208 }
209
210 protected void ActivateParent()
211 {
212 if (GetHierarchyParent())
213 {
214 ItemBase parent = ItemBase.Cast(GetHierarchyParent());
215 if (parent)
216 {
217 parent.OnActivatedByItem(this);
218 }
219 }
220 }
221
222 protected void MakeRingingStart()
223 {
224 if (!m_TimerUpdate)
226 SetState(EAlarmClockState.RINGING);
227
229 }
230
231 protected void MakeRingingStop()
232 {
234
236 }
237
239
241
243 {
244 super.OnVariablesSynchronized();
245
246 if (m_State != m_StatePrev)//state changed
247 {
248 if (m_StatePrev == EAlarmClockState.RINGING)
249 {
251 }
252 else if (m_State == EAlarmClockState.RINGING)
253 {
255 }
256 if (m_State == EAlarmClockState.SET)
257 {
258 if (m_StatePrev != -1 || IsInitialized())
259 {
260 PlaySoundSet( m_TurnOnSound, GetToggleSound(), 0, 0 );
261 }
262 if (GetWorkingSound())
263 {
264 PlaySoundSet( m_WorkingSound, GetWorkingSound(), 0, 0, true );
265 }
266 }
267 else if (m_State == EAlarmClockState.UNSET)
268 {
269 if (m_StatePrev == EAlarmClockState.SET)
270 {
271 if (m_WorkingSound)
272 {
274 }
275 if (m_StatePrev != -1 || IsInitialized())
276 {
277 PlaySoundSet( m_TurnOnSound, GetToggleSound(), 0, 0 );
278 }
279 }
280 }
282 }
283 }
284
285
286 //---------------------------------------------------------------------------------------------------------
287 //---------------------------------------------- Public methods -------------------------------------------
288 //---------------------------------------------------------------------------------------------------------
289
291 {
292 return (m_State == EAlarmClockState.RINGING);
293 }
294
296 {
297 return (m_State == EAlarmClockState.SET);
298 }
299
300 void TurnOn()
301 {
302 Arm();
303 }
304
305 void TurnOff()
306 {
307 if ( IsRinging() )
308 {
310 }
311 else
312 {
313 Disarm();
314 }
315
316 m_TimerUpdate = null;
317 }
318
319 void SetAlarmTimeServer(float time01)
320 {
321 SetAnimationPhaseNow("ClockAlarm", time01);
322 m_AlarmTime01 = time01;
323 }
324}
ActionAttachExplosivesTriggerCB ActionContinuousBaseCB ActionAttachExplosivesTrigger()
void AddAction(typename actionName)
enum EAlarmClockState m_AlarmTime01
void TurnOff()
Definition ClockBase.c:305
bool IsRinging()
Definition ClockBase.c:290
ref Timer m_TimerUpdate
Definition ClockBase.c:15
string GetHitSound()
Definition ClockBase.c:109
void ClockBase()
Definition ClockBase.c:27
protected void SetupTimerServer()
Definition ClockBase.c:186
static int ConvertAlarmHand01ToMins(float time01, int mins_max)
Definition ClockBase.c:70
EffectSound m_WorkingSound
Definition ClockBase.c:23
bool IsAlarmOn()
Definition ClockBase.c:295
const float RINGING_DURATION_MAX
Definition ClockBase.c:25
int m_StatePrev
Definition ClockBase.c:17
string GetRingingSound()
Definition ClockBase.c:105
static int GetTimeDiffInMins12h(int from_mins, int to_mins)
Definition ClockBase.c:88
string GetToggleSound()
Definition ClockBase.c:101
void TurnOnClient()
void SetAlarmInXMins(int in_mins)
Definition ClockBase.c:170
protected void MakeRingingStop()
Definition ClockBase.c:231
protected void Disarm()
Definition ClockBase.c:198
float m_RingingDuration
Definition ClockBase.c:16
protected void OnRingingStartServer()
Definition ClockBase.c:149
void TurnOn()
Definition ClockBase.c:300
protected void ActivateParent()
Definition ClockBase.c:210
EffectSound m_TurnOnSound
Definition ClockBase.c:20
EffectSound m_DestoryedSound
Definition ClockBase.c:21
static float ConvertMins12hToAlarmHand01(int mins)
Definition ClockBase.c:75
EAlarmClockState
Definition ClockBase.c:2
@ COUNT
Definition ClockBase.c:7
@ SET
Definition ClockBase.c:4
@ RINGING
Definition ClockBase.c:5
@ UNSET
Definition ClockBase.c:3
override void EEHitByRemote(int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos)
Definition ClockBase.c:128
protected void MakeRingingStart()
Definition ClockBase.c:222
static int ConvertAlarmHand01ToMins12h(float time01)
Definition ClockBase.c:65
protected void OnRingingStopClient()
Definition ClockBase.c:165
protected void OnRingingStartClient()
Definition ClockBase.c:154
float GetRingingDurationMax()
Definition ClockBase.c:180
EffectSound m_HitSound
Definition ClockBase.c:22
static const float UPDATE_TICK_RATE
Definition ClockBase.c:14
void TurnOffClient()
EffectSound m_RingingSoundLoop
Definition ClockBase.c:19
void SetAlarmTimeServer(float time01)
Definition ClockBase.c:319
void ~ClockBase()
Definition ClockBase.c:32
override void OnDamageDestroyed(int oldLevel)
Definition ClockBase.c:134
protected int GetAlarmInMin()
Definition ClockBase.c:53
string GetWorkingSound()
Definition ClockBase.c:117
string GetDestroyedSound()
Definition ClockBase.c:113
static int ConvertTimeToMins12h(int hour, int minute)
Definition ClockBase.c:81
protected void OnRingingStopServer()
override bool IsInitialized()
override Widget Init()
Definition DayZGame.c:122
override void EEKilled(Object killer)
void Arm()
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
protected float m_DrainThreshold protected bool m_State
proto native World GetWorld()
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
protected int m_State
Definition HescoBox.c:11
override void OnVariablesSynchronized()
Definition HescoBox.c:47
override void SetActions()
Definition Mace.c:3
void SetState(int state)
Definition HescoBox.c:79
Definition EnMath.c:7
Manager class for managing Effect (EffectParticle, EffectSound)
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
proto void GetDate(out int year, out int month, out int day, out int hour, out int minute)
Get actual ingame world time.
proto native CGame GetGame()
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.