DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Trap_TripWire.c
Go to the documentation of this file.
1// Wire type is used in the case of decrafting to give back the correct base Ingredient
3{
4 WIRE = 0,
6 ROPE = 2
8
10{
11 // Current state of the tripwire
12 static const int FOLDED = 3;
13 static const int DEPLOYED = 2;
14 static const int TRIGGERED = 1;
15
17 private int m_WireMaterial;
18
22
24 {
25 m_DamagePlayers = 0; //How much damage player gets when caught
26 m_InitWaitTime = 0; //After this time after deployment, the trap is activated
27 m_DefectRate = 15;
28 m_NeedActivation = false;
29 m_AnimationPhaseGrounded = "inventory";
30 m_AnimationPhaseSet = "placing";
31 m_AnimationPhaseTriggered = "triggered";
32 m_InfoActivationTime = string.Format("#STR_TripwireTrap0%1#STR_TripwireTrap1", m_InitWaitTime.ToString()); // nefunguje dynamicke vyrazy mimo funkcii
33
34 RegisterNetSyncVariableInt("m_State");
35 }
36
38 {
39 super.OnVariablesSynchronized();
40
41 if ( IsPlaceSound() )
42 {
44 }
45 }
46
48 {
49 super.OnStoreSave(ctx);
50
51 ctx.Write( m_State );
52 }
53
54 //----------------------------------------------------------------
55 override bool OnStoreLoad(ParamsReadContext ctx, int version)
56 {
57 if ( !super.OnStoreLoad(ctx, version) )
58 return false;
59
60 int state = FOLDED;
61 if ( !ctx.Read( state ) )
62 state = FOLDED;
63
64 SetState( state );
66
67 return true;
68 }
69
70 override void CreateTrigger()
71 {
72 m_TrapTrigger = TripWireTrigger.Cast(GetGame().CreateObjectEx("TripWireTrigger", GetPosition(), SPAWN_FLAGS));
73 vector mins = "-0.75 0.3 -0.01";
74 vector maxs = "0.75 0.32 0.01";
75 m_TrapTrigger.SetOrientation(GetOrientation());
76 m_TrapTrigger.SetExtents(mins, maxs);
78 }
79
80 override void OnSteppedOn(EntityAI victim)
81 {
82 if (!victim)
83 {
84 return;
85 }
86
87 if (!victim.GetAllowDamage())
88 {
89 return;
90 }
91
92 // We must deal some damage, here 5 shock as melee damage in order to trigger hit animation
93 if (GetGame().IsServer())
94 {
95 victim.ProcessDirectDamage(DT_CLOSE_COMBAT, this, "", "TripWireHit", "0 0 0", 1);
97 SetInactive(false);
98 }
99
100 // We play the trap trigger sound
101 #ifndef SERVER
102 EffectSound sound = SEffectManager.PlaySound("TripwireTrap_Trigger_SoundSet", GetPosition());
103 sound.SetAutodestroy(true);
104 #endif
105 }
106
107 override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
108 {
109 super.OnItemLocationChanged(old_owner, new_owner);
110
111 PlayerBase player = PlayerBase.Cast(new_owner);
112 if (player)
113 {
114 StartDeactivate(player);
115 return;
116 }
117 }
118
119 override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
120 {
121 super.EEItemLocationChanged(oldLoc, newLoc);
122
124 {
125 if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.GROUND)
126 {
127 SetActive();
128 m_TrapTrigger.SetPosition(m_TriggerPosition);
129 m_TrapTrigger.SetOrientation(m_TriggerOrientation);
130 }
131
133 }
134
135 if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.CARGO)
136 {
137 SetInactive();
140 RefreshState();
141 }
142 }
143
144 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
145 {
146 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
147
148 if (GetGame().IsServer())
149 {
150 if (newLevel == GameConstants.STATE_RUINED)
151 {
153 RefreshState();
154 }
155 }
156 }
157
158 override void SetInactive(bool stop_timer = true)
159 {
160 super.SetInactive(stop_timer);
161
162 // de-attach attachments after "activating them"
163 for (int att = 0; att < GetInventory().AttachmentCount(); att++)
164 {
165 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(att));
166 if (attachment)
167 {
168 if (attachment.IsLockedInSlot())
169 {
170 attachment.UnlockFromParent();
171 }
172
173 attachment.OnActivatedByItem(this);
174 GetInventory().DropEntity(InventoryMode.SERVER, this, attachment);
175 }
176 }
177 }
178
179 void SetState(int state_ID)
180 {
181 m_State = state_ID;
182 }
183
185 {
186 return m_State;
187 }
188
189 void SetWireType( int wireType )
190 {
191 m_WireMaterial = wireType;
192 }
193
195 {
196 return m_WireMaterial;
197 }
198
199
200 override void RefreshState()
201 {
202 super.RefreshState();
203
204 if (GetState() == FOLDED)
205 {
206 FoldTripWire();
207 }
208 }
209
210 override void SetupTrapPlayer( PlayerBase player, bool set_position = true )
211 {
212 super.SetupTrapPlayer( player, set_position );
214 }
215
216 override void StartDeactivate(PlayerBase player)
217 {
218 super.StartDeactivate(player);
219
222 }
223
224 // We do not want players to attach charges before trap is deployed
225 override bool CanReceiveAttachment( EntityAI attachment, int slotId )
226 {
227 if ( GetState() != DEPLOYED )
228 return false;
229
230 return super.CanReceiveAttachment( attachment, slotId );
231 }
232
233 // As players cannot attch charges, we do not display the attachment slot before it is necessary
234 override bool CanDisplayAttachmentSlot( int slot_id )
235 {
236 if ( GetState() != DEPLOYED )
237 return false;
238
239 return super.CanDisplayAttachmentSlot( slot_id );
240 }
241
242 override void EEItemAttached(EntityAI item, string slot_name)
243 {
244 super.EEItemAttached(item, slot_name);
245
246 SetTakeable(false);
247 }
248
249 override void EEItemDetached(EntityAI item, string slot_name)
250 {
251 super.EEItemDetached(item, slot_name);
252
253 SetTakeable(false);
254 }
255
256 override void EEKilled(Object killer)
257 {
258 if (m_TrapTrigger)
259 {
260 StartDeactivate(null);
261 }
262
263 super.EEKilled(killer);
264 }
265
266 // We reset the animation phases to see the tripwire as folded
268 {
269 if ( m_AnimationPhaseGrounded != "" )
270 {
271 SetAnimationPhase( m_AnimationPhaseSet, 1 );
272
274 {
275 SetAnimationPhase( m_AnimationPhaseTriggered, 1 );
276 }
277
278 SetAnimationPhase( m_AnimationPhaseGrounded, 0 );
279 }
280 }
281
282 override void OnInventoryEnter( Man player )
283 {
284 SetState( FOLDED );
285 }
286
287 #ifdef PLATFORM_WINDOWS
288 // How one sees the tripwire when in vicinity
289 override int GetViewIndex()
290 {
291 if ( MemoryPointExists( "invView2" ) )
292 {
294 GetInventory().GetCurrentInventoryLocation( il );
295 InventoryLocationType type = il.GetType();
296 switch ( type )
297 {
298 case InventoryLocationType.CARGO:
299 {
300 return 0;
301 }
302 case InventoryLocationType.ATTACHMENT:
303 {
304 return 1;
305 }
306 case InventoryLocationType.HANDS:
307 {
308 return 0;
309 }
310 case InventoryLocationType.GROUND:
311 {
312 // Different view index depending on deployment state
313 if ( GetState() == DEPLOYED )
314 return 1;
315 else if ( GetState() == TRIGGERED )
316 return 2;
317
318 // When folded
319 return 0;
320 }
321 case InventoryLocationType.PROXYCARGO:
322 {
323 return 0;
324 }
325 default:
326 {
327 if ( GetState() == DEPLOYED )
328 return 1;
329 else if ( GetState() == TRIGGERED )
330 return 2;
331
332 // When folded
333 return 0;
334 }
335 }
336 }
337 return 0;
338 }
339 #endif
340
341 //================================================================
342 // ADVANCED PLACEMENT
343 //================================================================
344
345 // On placement complete, set state, play sound, create trigger and synch to client
346 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
347 {
348 super.OnPlacementComplete(player, position, orientation);
349
350 SetIsPlaceSound(true);
351 if (GetGame().IsServer())
352 {
354
355 m_TriggerPosition = position;
356 m_TriggerOrientation = orientation;
358 }
359 }
360
361 override void OnPlacementCancelled(Man player)
362 {
363 super.OnPlacementCancelled(player);
364
366
368 }
369
370 override bool IsDeployable()
371 {
372 return true;
373 }
374
375 // Tripwire cannot be taken if deployed with attachment
376 override bool IsTakeable()
377 {
378 return GetState() != DEPLOYED || (GetInventory().AttachmentCount() == 0 && GetState() == DEPLOYED);
379 }
380
381 override string GetDeploySoundset()
382 {
383 return "tripwire_deploy_SoundSet";
384 }
385
386 override string GetLoopDeploySoundset()
387 {
388 return "tripwiretrap_deploy_SoundSet";
389 }
390
391 override void SetActions()
392 {
393 super.SetActions();
394
397 }
398
399 // ====================================
400 // =========== DEPRECATED ===========
401 // ====================================
402
404 {
405 if ( GetInventory().AttachmentCount() > 0)
406 {
407 ItemBase attachment = ItemBase.Cast( GetInventory().GetAttachmentFromIndex(0) );
408
409 if ( attachment )
410 {
411 // Hide all proxies
412 for (int i = 1; i <= 3; i++)
413 {
414 HideSelection("s" + i + "_charge");
415 }
416
417 // Now show the one we need to see
418 string proxy_to_show = string.Format("s%1_charge", GetState() );
419 //Print(proxy_to_show);
420 ShowSelection( proxy_to_show );
421 }
422 }
423 }
424
425#ifdef DEVELOPER
426 //================================================================
427 // DEBUG
428 //================================================================
429
430 //Debug menu Spawn Ground Special
431 override void OnDebugSpawn()
432 {
434 StartActivate(null);
435 }
436
437 override void GetDebugButtonNames(out string button1, out string button2, out string button3, out string button4)
438 {
439 button1 = "Activate";
440 button2 = "Deactivate";
441 }
442
443 override void OnDebugButtonPressServer(int button_index)
444 {
445 switch (button_index)
446 {
447 case 1:
448 StartActivate(null);
449 break;
450 case 2:
451 SetInactive();
452 break;
453 }
454
455 }
456#endif
457}
458
460{
461
462}
InventoryMode
Definition Inventory.c:20
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
void AddAction(typename actionName)
vector GetOrientation()
override void EEItemDetached(EntityAI item, string slot_name)
override void EEItemAttached(EntityAI item, string slot_name)
override void EEKilled(Object killer)
override bool IsTakeable()
override void OnDebugButtonPressServer(int button_index)
override void GetDebugButtonNames(out string button1, out string button2, out string button3, out string button4)
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
InventoryLocationType
types of Inventory Location
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition ItemBase.c:5779
override void SetTakeable(bool pState)
Definition ItemBase.c:8843
void SetIsPlaceSound(bool is_place_sound)
Definition ItemBase.c:8900
string GetDeploySoundset()
Definition LargeTent.c:146
void OnInventoryEnter(Man player)
Event called on item when it is placed in the player(Man) inventory, passes the owner as a parameter.
Definition ItemBase.c:8390
void PlayPlaceSound()
Definition ItemBase.c:8938
bool IsPlaceSound()
Definition ItemBase.c:8905
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Definition ItemBase.c:8662
override void OnVariablesSynchronized()
void OnStoreSave(ParamsWriteContext ctx)
bool OnStoreLoad(ParamsReadContext ctx, int version)
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
void SetState(bool state)
protected float m_DrainThreshold protected bool m_State
static const int TRIGGERED
enum eWireMaterial FOLDED
int GetWireType()
protected vector m_TriggerOrientation
static const int DEPLOYED
eWireMaterial
@ WIRE
@ ROPE
@ BARBED_WIRE
private int m_WireMaterial
void FoldTripWire()
override bool CanDisplayAttachmentSlot(int slot_id)
void SetWireType(int wireType)
override void OnPlacementCancelled(Man player)
protected bool m_ResultOfAdvancedPlacing
protected vector m_TriggerPosition
void UpdateProxySelections()
void TripwireTrap()
string m_AnimationPhaseTriggered
Definition TrapBase.c:34
float m_DefectRate
Definition TrapBase.c:19
enum SoundTypeTrap SPAWN_FLAGS
string m_AnimationPhaseGrounded
Definition TrapBase.c:32
void RefreshState()
Definition TrapBase.c:374
void SetActive()
Definition TrapBase.c:463
bool m_NeedActivation
Definition TrapBase.c:18
string m_InfoActivationTime
Definition TrapBase.c:40
string m_AnimationPhaseSet
Definition TrapBase.c:33
void SetInactive(bool stop_timer=true)
Definition TrapBase.c:510
int m_InitWaitTime
Definition TrapBase.c:17
void SetupTrapPlayer(PlayerBase player, bool set_position=true)
Definition TrapBase.c:433
float m_DamagePlayers
Definition TrapBase.c:20
void StartActivate(PlayerBase player)
Definition TrapBase.c:487
void DeleteTrigger()
Definition TrapBase.c:542
void StartDeactivate(PlayerBase player)
protected TrapTrigger m_TrapTrigger
Definition TrapBase.c:44
class JsonUndergroundAreaTriggerData GetPosition
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
InventoryLocation.
proto native int GetType()
returns type of InventoryLocation
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
override string GetLoopDeploySoundset()
Definition Trap_Bear.c:246
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition Trap_Bear.c:30
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition Trap_Bear.c:227
override void OnSteppedOn(EntityAI victim)
Definition Trap_Bear.c:67
override bool IsDeployable()
Definition Trap_Bear.c:241
override void SetActions()
Definition Trap_Bear.c:251
override void CreateTrigger()
Definition Trap_Bear.c:43
void SetParentObject(TrapBase obj)
Definition TrapTrigger.c:10
void SetExtents(vector mins, vector maxs)
Set the size of the Trigger, avoid using SetCollisionBox directly.
Definition Trigger.c:116
proto native CGame GetGame()
const int STATE_RUINED
Definition constants.c:742
static proto string Format(string fmt, 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)
Gets n-th character from string.
proto native int GetState()
returns one of STATE_...