DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
AlarmClock.c
Go to the documentation of this file.
2{
3 const string RINGING_SOUND = "AlarmClock_Ring_Loop_SoundSet";
4 const string TURN_TOGGLE_SOUND = "AlarmClock_Turn_Off_SoundSet";
5 const string DESTROYED_SOUND = "AlarmClock_Destroyed_SoundSet";
6 const string HIT_SOUND = "AlarmClock_Hit_SoundSet";
7
8
11
12 override void Init()
13 {
14 super.Init();
15 if ( GetGame().IsServer() )
16 {
18 if ( m_NoiseSystem && !m_NoisePar )
19 {
20 // Create and load noise parameters
22 m_NoisePar.LoadFromPath("cfgVehicles " + GetType() + " NoiseAlarmClock");
23 }
24 }
25 }
26
28 {
29 #ifndef SERVER
31 #endif
32 }
33
34
35 override void SetActions()
36 {
37 super.SetActions();
38
42 }
43
44 override string GetToggleSound()
45 {
46 return TURN_TOGGLE_SOUND;
47 }
48
49 override string GetRingingSound()
50 {
51 return RINGING_SOUND;
52 }
53
54 override string GetDestroyedSound()
55 {
56 return DESTROYED_SOUND;
57 }
58
59 override string GetHitSound()
60 {
61 return HIT_SOUND;
62 }
63
64 override void GetDebugButtonNames(out string button1, out string button2, out string button3, out string button4)
65 {
66 button1 = "SetAlarmAhead1Min";
67 }
68
70 {
71 return "TriggerAlarmClock";
72 }
73
74 override void OnDebugButtonPressServer(int button_index)
75 {
77 }
78
79 override string GetDebugText()
80 {
81 string debug_output;
82
83 if( GetGame().IsDedicatedServer())
84 {
85 debug_output = "alarm in: " + GetAlarmInMin().ToString() + " mins" + "\n";
86 debug_output += "current state: " + typename.EnumToString(EAlarmClockState, m_State) + "\n";;
87 debug_output += "ringing for " + m_RingingDuration.ToString()+ " secs" + "\n";
88 debug_output += "ringing max " + GetRingingDurationMax().ToString()+ " secs" + "\n";
89 }
90 else
91 {
92 debug_output = "this is client";
93 }
94 return debug_output;
95 }
96
97 void OnUpdate()
98 {
99 if ( IsAlarmOn() )
100 {
101 //due to variable server time flow(day-night time accel), it's not possible to simply set a timer for X secs without some convoluted math/code, so we need to check at regular intervals
102 int alarm_hand_in_minutes = ConvertAlarmHand01ToMins12h(m_AlarmTime01);
103
104 int pass, hour, minute;
105 GetGame().GetWorld().GetDate(pass, pass, pass, hour, minute);
106
107 int curr_time_in_minutes = ConvertTimeToMins12h(hour, minute);
108
109 //Print(GetAlarmInMin());
110
111 if ( alarm_hand_in_minutes == curr_time_in_minutes )
112 {
114 }
115 }
116
117 if ( IsRinging())
118 {
120
122 {
123 TurnOff();
124 }
125 else if ( m_NoiseSystem )
126 {
128 }
129 }
130 }
131
132 protected void AnimateAlarmHand(float value)
133 {
134 SetAnimationPhaseNow("ClockAlarm", value);
135 }
136
137
138 override bool OnStoreLoad( ParamsReadContext ctx, int version )
139 {
140 if (!super.OnStoreLoad(ctx, version))
141 return false;
142
143 if (version < 126)
144 {
145 return true;
146 }
147
148 EAlarmClockState state;
149
150 if ( !ctx.Read( state ) )
151 {
152 return false;
153 }
154
155 float time;
156
157 if ( !ctx.Read( time ) )
158 {
159 return false;
160 }
161
162 SetAlarmTimeServer(time);
163 SetState(state);
164 if ( state == EAlarmClockState.SET )
165 {
166 TurnOn();
167 }
168 else if (state == EAlarmClockState.RINGING )
169 {
171 }
172
173 return true;
174 }
175
177 {
178 super.OnStoreSave(ctx);
179
180 ctx.Write(m_State);
181 ctx.Write(m_AlarmTime01);
182 }
183
184 override void OnDebugSpawn()
185 {
186 TurnOn();
188 }
189
190};
191
eBleedingSourceType GetType()
ActionTurnOffAlarmClockCB ActionSingleUseBaseCB ActionTurnOffAlarmClock()
ActionTurnOnAlarmClockCB ActionSingleUseBaseCB ActionTurnOnAlarmClock()
void AddAction(typename actionName)
enum EAlarmClockState m_AlarmTime01
void TurnOff()
Definition ClockBase.c:305
bool IsRinging()
Definition ClockBase.c:290
void ClockBase()
Definition ClockBase.c:27
bool IsAlarmOn()
Definition ClockBase.c:295
void SetAlarmInXMins(int in_mins)
Definition ClockBase.c:170
float m_RingingDuration
Definition ClockBase.c:16
void TurnOn()
Definition ClockBase.c:300
EAlarmClockState
Definition ClockBase.c:2
protected void MakeRingingStart()
Definition ClockBase.c:222
static int ConvertAlarmHand01ToMins12h(float time01)
Definition ClockBase.c:65
protected void OnRingingStopClient()
Definition ClockBase.c:165
float GetRingingDurationMax()
Definition ClockBase.c:180
static const float UPDATE_TICK_RATE
Definition ClockBase.c:14
void SetAlarmTimeServer(float time01)
Definition ClockBase.c:319
protected int GetAlarmInMin()
Definition ClockBase.c:53
static int ConvertTimeToMins12h(int hour, int minute)
Definition ClockBase.c:81
class NoiseSystem NoiseParams()
Definition Noise.c:15
void SetState(bool state)
protected float m_DrainThreshold protected bool m_State
class JsonUndergroundAreaTriggerData GetPosition
override void OnDebugSpawn()
Definition AlarmClock.c:184
override void OnStoreSave(ParamsWriteContext ctx)
Definition AlarmClock.c:176
override string GetDebugText()
Definition AlarmClock.c:79
override string GetToggleSound()
Definition AlarmClock.c:44
override string GetRingingSound()
Definition AlarmClock.c:49
override void OnDebugButtonPressServer(int button_index)
Definition AlarmClock.c:74
const string HIT_SOUND
Definition AlarmClock.c:6
static ref NoiseParams m_NoisePar
Definition AlarmClock.c:9
override string GetExplosiveTriggerSlotName()
Definition AlarmClock.c:69
const string DESTROYED_SOUND
Definition AlarmClock.c:5
override void Init()
Definition AlarmClock.c:12
const string TURN_TOGGLE_SOUND
Definition AlarmClock.c:4
static NoiseSystem m_NoiseSystem
Definition AlarmClock.c:10
override string GetHitSound()
Definition AlarmClock.c:59
protected void AnimateAlarmHand(float value)
Definition AlarmClock.c:132
override string GetDestroyedSound()
Definition AlarmClock.c:54
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition AlarmClock.c:138
const string RINGING_SOUND
Definition AlarmClock.c:3
override void GetDebugButtonNames(out string button1, out string button2, out string button3, out string button4)
Definition AlarmClock.c:64
void ~AlarmClock_ColorBase()
Definition AlarmClock.c:27
override void SetActions()
Definition AlarmClock.c:35
proto native World GetWorld()
proto native NoiseSystem GetNoiseSystem()
proto void AddNoiseTarget(vector pos, float lifetime, NoiseParams noise_params, float external_strength_multiplier=1.0)
Will make a noise at that position which the AI will "see" for the duration of 'lifetime'.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
proto void GetDate(out int year, out int month, out int day, out int hour, out int minute)
Get actual ingame world time.
proto string ToString()
proto native CGame GetGame()