DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Land_Underground_Panel.c
Go to the documentation of this file.
2{
6}
7
8enum ELEDColors
9{
12}
13
15{
16 static ref set<Land_Underground_EntranceBase> m_Entrances;
17 static ref set<Land_Underground_Panel> m_Panels;
18
20
21 const string COLOR_LED_OFF = "#(argb,8,8,3)color(0,0,0,1.0,co)";
22 const string COLOR_LED_GREEN = "#(argb,8,8,3)color(0,1,0,1.0,co)";
23 const string COLOR_LED_RED = "#(argb,8,8,3)color(1,0,0,1.0,co)";
24
25 const string SELECTION_NAME_LED_RED = "LED_Red";
26 const string SELECTION_NAME_LED_GREEN = "LED_Green";
27
28 bool m_PanelWasUsed
32
34
37
39 {
40 RegisterNetSyncVariableBool("m_PanelWasUsed");
41 RegisterPanel(this);
42 SetLEDState(ELEDColors.RED, ELEDState.ON);
43 SetLEDState(ELEDColors.GREEN, ELEDState.OFF);
44 }
45
47 {
48 UnregisterPanel(this);
49 }
50
52 {
54 if (door)
55 {
57 }
58 return false;
59 }
60
61 void Interact()
62 {
64 if (door)
65 {
69 m_PanelWasUsed = true;
70 SetSynchDirty();
71 }
72 else
73 {
74 ErrorEx("Can't find the instance of entrance the panel is linkined to");
75 }
76 }
77
79 {
80 if (!m_Entrances)
81 {
82 m_Entrances = new set<Land_Underground_EntranceBase>();
83 }
84 m_Entrances.Insert(entrance);
85 }
86
88 {
89 if (m_Entrances)
90 {
91 int index = m_Entrances.Find(entrance);
92 if (index != -1)
93 {
94 m_Entrances.Remove(index);
95 }
96 else
97 {
98 ErrorEx("Attempted to unregistered non-registered entrance");
99 }
100 }
101 }
102
104 {
105 if (!m_Panels)
106 {
107 m_Panels = new set<Land_Underground_Panel>;
108 }
109 m_Panels.Insert(panel);
110 }
111
113 {
114 if (m_Panels)
115 {
116 int index = m_Panels.Find(panel);
117 if (index != -1)
118 {
119 m_Panels.Remove(index);
120 }
121 else
122 {
123 ErrorEx("Attempted to unregistered non-registered panel");
124 }
125 }
126 }
127
128 EUndegroundDoorType GetLinkedDoorType()
129 {
130 return GetLinkedDoor().m_DoorType;
131 }
132
134 {
135 if (!m_LinkedDoor)
137 return m_LinkedDoor;
138 }
139
141 {
142 if (!m_Entrances)
143 {
144 return null;
145 }
146
147 float closestDst = float.MAX;
149 vector thisPos = GetPosition();
150
152 {
153 float dist = vector.DistanceSq(thisPos, obj.GetPosition());
154 if (dist < closestDst)
155 {
156 closestDst = dist;
157 closestObj = obj;
158 }
159 }
160
161 return closestObj;
162 }
163
164 void SetLEDState(ELEDColors color, ELEDState state)
165 {
166 #ifndef SERVER
167 if (color == ELEDColors.RED)
168 {
169 if (m_LedStateRed != state)
170 {
171 m_LedStateRed = state;
173 }
174 }
175 else
176 {
177 if (m_LedStateGreen != state)
178 {
179 m_LedStateGreen = state;
181 }
182 }
183 #endif
184 }
185
186 void SetBlinkingTimer(bool enable)
187 {
188 if (enable)
189 {
190 if (!m_FlipFlopTimer)
191 {
192 m_FlipFlopTimer = new Timer();
193 m_FlipFlopTimer.Run(0.1, this, "ToggleFlipFlop", NULL, true);
194 }
195 }
196 else
197 {
198 if (m_FlipFlopTimer)
199 {
200 m_FlipFlopTimer = null;
201 }
202 }
203 }
204
206 {
207 /*
208 Print("OnLEDStateChanged()");
209 Print("m_LedStateRed: " + m_LedStateRed);
210 Print("m_LedStateGreen: " + m_LedStateGreen);
211 */
212 if (m_LedStateRed == ELEDState.BLINKING || m_LedStateGreen == ELEDState.BLINKING)
213 {
214 SetBlinkingTimer(true);
215 }
216 else
217 {
218 SetBlinkingTimer(false);
219 }
220 //red
221 if (m_LedStateRed == ELEDState.ON)
222 {
224 }
225 else if (m_LedStateRed == ELEDState.OFF)
226 {
228 }
229 else if (m_LedStateRed == ELEDState.BLINKING)
230 {
232 {
234 }
235 else
236 {
238 }
239
240 //green
241 }
242 if (m_LedStateGreen == ELEDState.ON)
243 {
245 }
246 else if (m_LedStateGreen == ELEDState.OFF)
247 {
249 }
250 else if (m_LedStateGreen == ELEDState.BLINKING)
251 {
253 {
255 }
256 else
257 {
259 }
260
261 }
262 }
263
265 {
266 m_PanelWasUsed = false;
267 SetSynchDirty();
268 }
269
271 {
272 switch (GetLinkedDoorType())
273 {
274 case EUndegroundDoorType.MAIN:
275 {
276 if (newState >= EUndegroundEntranceState.CLOSED && newState < EUndegroundEntranceState.OPENING_G)
277 {
278 SetLEDState(ELEDColors.RED, ELEDState.ON);
279 }
280 else if (newState == EUndegroundEntranceState.OPENING_G)
281 {
282 SetLEDState(ELEDColors.RED, ELEDState.OFF);
283 }
284 else if (newState >= EUndegroundEntranceState.CLOSING_A)
285 {
286 SetLEDState(ELEDColors.RED, ELEDState.BLINKING);
287 }
288
289 if (newState == EUndegroundEntranceState.CLOSED)
290 {
291 SetLEDState(ELEDColors.GREEN, ELEDState.OFF);
292 }
293 else if (newState >= EUndegroundEntranceState.OPENING_A && newState < EUndegroundEntranceState.OPENING_G)
294 {
295 SetLEDState(ELEDColors.GREEN, ELEDState.BLINKING);
296 }
297 else if (newState >= EUndegroundEntranceState.OPENING_G)
298 {
299 SetLEDState(ELEDColors.GREEN, ELEDState.ON);
300 }
301 }
302 break;
303 case EUndegroundDoorType.SMALL:
304 {
305 if (newState == EUndegroundEntranceState.OPENING_A)
306 {
307 SetLEDState(ELEDColors.RED, ELEDState.ON);
308 SetLEDState(ELEDColors.GREEN, ELEDState.BLINKING);
309 }
310 else if (newState == EUndegroundEntranceState.OPENING_B)
311 {
312 SetLEDState(ELEDColors.RED, ELEDState.OFF);
313 SetLEDState(ELEDColors.GREEN, ELEDState.ON);
314 }
315 else if (newState == EUndegroundEntranceState.CLOSING_A)
316 {
317 SetLEDState(ELEDColors.RED, ELEDState.BLINKING);
318 SetLEDState(ELEDColors.GREEN, ELEDState.ON);
319 }
320 if (newState == EUndegroundEntranceState.CLOSING_B || newState == EUndegroundEntranceState.CLOSED)
321 {
322 SetLEDState(ELEDColors.RED, ELEDState.ON);
323 SetLEDState(ELEDColors.GREEN, ELEDState.OFF);
324 }
325 }
326 break;
327 }
328 }
329
330
331 protected void UpdateLED(string selection, string color)
332 {
333 int selectionIdx = GetHiddenSelectionIndex(selection);
334 SetObjectTexture(selectionIdx, color);
335 //Print("selection: " +selection + ", color: " + color +", selectionIdx: "+ selectionIdx);
336 }
337
339 {
342 }
343
345 {
346 PlaySoundSet( m_ActivationSound, "UndergroundDoor_PanelActivation_SoundSet", 0, 0 );
347 }
348
350 {
351 if (m_PanelWasUsed != m_PanelWasUsedPrev)
352 {
353 if (m_PanelWasUsed)
354 {
356 }
357 m_PanelWasUsedPrev = m_PanelWasUsed;
358 }
359 }
360
361}
enum ELEDState GREEN
const string SELECTION_NAME_LED_RED
static void UnregisterPanel(Land_Underground_Panel panel)
void ~Land_Underground_Panel()
static void RegisterEntrance(Land_Underground_EntranceBase entrance)
const string COLOR_LED_OFF
enum ELEDState RED
static void RegisterPanel(Land_Underground_Panel panel)
void ResetPanelUsed()
ELEDState m_LedStateRed
void Land_Underground_Panel()
void OnPanelUsedSynchronized()
EUndegroundDoorType GetLinkedDoorType()
void ToggleFlipFlop()
void OnDoorStateChangedClient(EUndegroundEntranceState newState, EUndegroundEntranceState prevState)
const string SELECTION_NAME_LED_GREEN
const string COLOR_LED_GREEN
static ref set< Land_Underground_Panel > m_Panels
void SetBlinkingTimer(bool enable)
bool m_PanelWasUsed bool m_PanelWasUsedPrev
enum ELEDState m_Entrances
protected void UpdateLED(string selection, string color)
bool CanInteract()
void Interact()
ELEDState m_LedStateGreen
EffectSound m_ActivationSound
Land_Underground_EntranceBase m_LinkedDoor
Land_Underground_EntranceBase GetClosestDoor()
static void UnregisterEntrance(Land_Underground_EntranceBase entrance)
void OnLEDStateChanged()
void SetLEDState(ELEDColors color, ELEDState state)
Land_Underground_EntranceBase GetLinkedDoor()
override void OnVariablesSynchronized()
const string COLOR_LED_RED
ref Timer m_FlipFlopTimer
bool m_BlinkingFlipFlop
class JsonUndergroundAreaTriggerData GetPosition
proto native bool RegisterNetworkStaticObject(Object object)
Static objects cannot be replicated by default (there are too many objects on the map)....
override ScriptCallQueue GetCallQueue(int call_category)
Definition DayZGame.c:1153
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
proto void CallLater(func fn, int delay=0, bool repeat=false, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto native CGame GetGame()
enum ShapeType ErrorEx
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8