Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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
7}
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.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.OnStoreSave(ctx);
40
41 ctx.Write( m_State );
42 }
43
44 //----------------------------------------------------------------
45 override bool OnStoreLoad(ParamsReadContext ctx, int version)
46 {
47 if ( !super.OnStoreLoad(ctx, version) )
48 return false;
49
50 int state = FOLDED;
51 if ( !ctx.Read( state ) )
52 state = FOLDED;
53
54 SetState( state );
56
57 return true;
58 }
59
60 override void CreateTrigger()
61 {
62 m_TrapTrigger = TripWireTrigger.Cast(g_Game.CreateObjectEx("TripWireTrigger", GetPosition(), SPAWN_FLAGS));
63 vector mins = "-0.75 0.3 -0.01";
64 vector maxs = "0.75 0.32 0.01";
65 m_TrapTrigger.SetOrientation(GetOrientation());
66 m_TrapTrigger.SetExtents(mins, maxs);
67 m_TrapTrigger.SetParentObject(this);
68
70 }
71
72 override void OnSteppedOn(EntityAI victim)
73 {
74 if (!victim)
75 {
76 return;
77 }
78
79 if (!victim.GetAllowDamage())
80 {
81 return;
82 }
83
84 // We must deal some damage, here 5 shock as melee damage in order to trigger hit animation
85 if (g_Game.IsServer())
86 {
87 victim.ProcessDirectDamage(DamageType.CLOSE_COMBAT, this, "", "TripWireHit", "0 0 0", 1);
89 SetInactive(false);
90 }
91
92 // We play the trap trigger sound
93 #ifndef SERVER
94 EffectSound sound = SEffectManager.PlaySound("TripwireTrap_Trigger_SoundSet", GetPosition());
95 sound.SetAutodestroy(true);
96 #endif
97 }
98
99 override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
100 {
101 super.OnItemLocationChanged(old_owner, new_owner);
102
103 PlayerBase player = PlayerBase.Cast(new_owner);
104 if (player)
105 {
106 StartDeactivate(player);
107 return;
108 }
109 }
110
111 override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
112 {
113 super.EEItemLocationChanged(oldLoc, newLoc);
114
116 {
117 if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.GROUND)
118 {
119 SetActive();
120 m_TrapTrigger.SetPosition(m_TriggerPosition);
121 m_TrapTrigger.SetOrientation(m_TriggerOrientation);
122 }
123
125 }
126
127 if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.CARGO)
128 {
129 SetInactive();
132 RefreshState();
133 }
134 }
135
136 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
137 {
138 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
139
140 if (g_Game.IsServer())
141 {
142 if (newLevel == GameConstants.STATE_RUINED)
143 {
145 RefreshState();
146 }
147 }
148 }
149
150 override void SetInactive(bool stop_timer = true)
151 {
152 super.SetInactive(stop_timer);
153
154 // de-attach attachments after "activating them"
155 GameInventory inventory = GetInventory();
156 for (int att = 0; att < inventory.AttachmentCount(); ++att)
157 {
158 ItemBase attachment = ItemBase.Cast(inventory.GetAttachmentFromIndex(att));
159 if (attachment)
160 {
161 if (attachment.IsLockedInSlot())
162 {
163 attachment.UnlockFromParent();
164 }
165
166 attachment.OnActivatedByItem(this);
167 inventory.DropEntity(InventoryMode.SERVER, this, attachment);
168 }
169 }
170 }
171
172 void SetState(int state_ID)
173 {
174 m_State = state_ID;
175 }
176
178 {
179 return m_State;
180 }
181
182 void SetWireType( int wireType )
183 {
184 m_WireMaterial = wireType;
185 }
186
188 {
189 return m_WireMaterial;
190 }
191
192
193 override void RefreshState()
194 {
195 super.RefreshState();
196
197 if (GetState() == FOLDED)
198 {
199 FoldTripWire();
200 }
201 }
202
203 override void SetupTrapPlayer( PlayerBase player, bool set_position = true )
204 {
205 super.SetupTrapPlayer( player, set_position );
207 }
208
209 override void StartDeactivate(PlayerBase player)
210 {
211 super.StartDeactivate(player);
212
215 }
216
217 // We do not want players to attach charges before trap is deployed
218 override bool CanReceiveAttachment( EntityAI attachment, int slotId )
219 {
220 if ( GetState() != DEPLOYED )
221 return false;
222
223 return super.CanReceiveAttachment( attachment, slotId );
224 }
225
226 // As players cannot attch charges, we do not display the attachment slot before it is necessary
227 override bool CanDisplayAttachmentSlot( int slot_id )
228 {
229 if ( GetState() != DEPLOYED )
230 return false;
231
232 return super.CanDisplayAttachmentSlot( slot_id );
233 }
234
235 override void EEItemAttached(EntityAI item, string slot_name)
236 {
237 super.EEItemAttached(item, slot_name);
238
239 SetTakeable(false);
240 }
241
242 override void EEItemDetached(EntityAI item, string slot_name)
243 {
244 super.EEItemDetached(item, slot_name);
245
246 SetTakeable(false);
247 }
248
249 override void EEKilled(Object killer)
250 {
251 if (m_TrapTrigger)
252 {
253 StartDeactivate(null);
254 }
255
256 super.EEKilled(killer);
257 }
258
259 // We reset the animation phases to see the tripwire as folded
261 {
262 if ( m_AnimationPhaseGrounded != "" )
263 {
264 SetAnimationPhase( m_AnimationPhaseSet, 1 );
265
267 {
268 SetAnimationPhase( m_AnimationPhaseTriggered, 1 );
269 }
270
271 SetAnimationPhase( m_AnimationPhaseGrounded, 0 );
272 }
273 }
274
275 override void OnInventoryEnter( Man player )
276 {
277 SetState( FOLDED );
278 }
279
280 #ifdef PLATFORM_WINDOWS
281 // How one sees the tripwire when in vicinity
282 override int GetViewIndex()
283 {
284 if ( MemoryPointExists( "invView2" ) )
285 {
286 InventoryLocation il = new InventoryLocation;
287 GetInventory().GetCurrentInventoryLocation( il );
288 InventoryLocationType type = il.GetType();
289 switch ( type )
290 {
291 case InventoryLocationType.CARGO:
292 {
293 return 0;
294 }
295 case InventoryLocationType.ATTACHMENT:
296 {
297 return 1;
298 }
299 case InventoryLocationType.HANDS:
300 {
301 return 0;
302 }
303 case InventoryLocationType.GROUND:
304 {
305 // Different view index depending on deployment state
306 if ( GetState() == DEPLOYED )
307 return 1;
308 else if ( GetState() == TRIGGERED )
309 return 2;
310
311 // When folded
312 return 0;
313 }
314 case InventoryLocationType.PROXYCARGO:
315 {
316 return 0;
317 }
318 default:
319 {
320 if ( GetState() == DEPLOYED )
321 return 1;
322 else if ( GetState() == TRIGGERED )
323 return 2;
324
325 // When folded
326 return 0;
327 }
328 }
329 }
330 return 0;
331 }
332 #endif
333
334 //================================================================
335 // ADVANCED PLACEMENT
336 //================================================================
337
338 // On placement complete, set state, play sound, create trigger and synch to client
339 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
340 {
341 if (g_Game.IsServer())
342 {
344
345 m_TriggerPosition = position;
346 m_TriggerOrientation = orientation;
348 }
349
350 super.OnPlacementComplete(player, position, orientation);
351 }
352
353 override void OnPlacementCancelled(Man player)
354 {
355 super.OnPlacementCancelled(player);
356
358
360 }
361
362 override bool IsDeployable()
363 {
364 return true;
365 }
366
367 // Tripwire cannot be taken if deployed with attachment
368 override bool IsTakeable()
369 {
370 return GetState() != DEPLOYED || (GetInventory().AttachmentCount() == 0 && GetState() == DEPLOYED);
371 }
372
373 override string GetDeploySoundset()
374 {
375 return "tripwire_deploy_SoundSet";
376 }
377
378 override string GetLoopDeploySoundset()
379 {
380 return "tripwiretrap_deploy_SoundSet";
381 }
382
383 override void SetActions()
384 {
385 super.SetActions();
386
389 }
390
391 // ====================================
392 // =========== DEPRECATED ===========
393 // ====================================
394
396 {
397 if ( GetInventory().AttachmentCount() > 0)
398 {
399 ItemBase attachment = ItemBase.Cast( GetInventory().GetAttachmentFromIndex(0) );
400
401 if ( attachment )
402 {
403 // Hide all proxies
404 for (int i = 1; i <= 3; i++)
405 {
406 HideSelection("s" + i + "_charge");
407 }
408
409 // Now show the one we need to see
410 string proxy_to_show = string.Format("s%1_charge", GetState() );
411 //Print(proxy_to_show);
412 ShowSelection( proxy_to_show );
413 }
414 }
415 }
416
417#ifdef DEVELOPER
418 //================================================================
419 // DEBUG
420 //================================================================
421
422 //Debug menu Spawn Ground Special
423 override void OnDebugSpawn()
424 {
426 StartActivate(null);
427 }
428
429 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
430 {
431 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Activate", FadeColors.LIGHT_GREY));
432 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEACTIVATE_ENTITY, "Deactivate", FadeColors.LIGHT_GREY));
433 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
434
435 super.GetDebugActions(outputList);
436 }
437
438 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
439 {
440 if (super.OnAction(action_id, player, ctx))
441 return true;
442 if (g_Game.IsServer() || !g_Game.IsMultiplayer())
443 {
444 if (action_id == EActions.ACTIVATE_ENTITY)
445 {
446 StartActivate(null);
447 }
448 else if (action_id == EActions.DEACTIVATE_ENTITY)
449 {
450 SetInactive();
451 }
452 }
453 return false;
454 }
455
456#endif
457}
458
460{
461
462}
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition entityai.c:104
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition inventory.c:22
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
void AddAction(typename actionName)
void SetActions()
vector GetOrientation()
override void EEItemDetached(EntityAI item, string slot_name)
override void EEItemAttached(EntityAI item, string slot_name)
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.
script counterpart to engine's class Inventory
Definition inventory.c:81
bool DropEntity(InventoryMode mode, EntityAI owner, notnull EntityAI item)
Definition inventory.c:1266
proto native EntityAI GetAttachmentFromIndex(int index)
proto native int AttachmentCount()
Returns count of attachments attached to this item.
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.
proto bool Write(void value_out)
proto bool Read(void value_in)
DamageType
exposed from C++ (do not change)
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition dayzanimal.c:136
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition dayzanimal.c:125
DayZGame g_Game
Definition dayzgame.c:3942
EActions
Definition eactions.c:2
override void EEKilled(Object killer)
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
override bool IsTakeable()
Serializer ParamsReadContext
Definition gameplay.c:15
Serializer ParamsWriteContext
Definition gameplay.c:16
const int STATE_RUINED
Definition constants.c:851
const int SAT_DEBUG_ACTION
Definition constants.c:457
vector GetPosition()
Get the world position of the Effect.
Definition effect.c:473
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
proto native int GetState()
returns one of STATE_...
InventoryLocationType
types of Inventory Location
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition itembase.c:6124
bool IsDeployable()
Definition itembase.c:9270
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition itembase.c:6976
string GetLoopDeploySoundset()
Definition largetent.c:151
override void SetTakeable(bool pState)
Definition itembase.c:9284
string GetDeploySoundset()
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:8813
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Definition itembase.c:9090
void OnStoreSave(ParamsWriteContext ctx)
bool OnStoreLoad(ParamsReadContext ctx, int version)
enum EObjectTemperatureState m_State
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
void SetState(bool state)
bool m_ResultOfAdvancedPlacing
int m_WireMaterial
static const int TRIGGERED
enum eWireMaterial FOLDED
int GetWireType()
static const int DEPLOYED
eWireMaterial
@ WIRE
@ ROPE
@ BARBED_WIRE
void FoldTripWire()
override bool CanDisplayAttachmentSlot(int slot_id)
void SetWireType(int wireType)
override void OnPlacementCancelled(Man player)
vector m_TriggerOrientation
vector m_TriggerPosition
void UpdateProxySelections()
void TripwireTrap()
string m_AnimationPhaseTriggered
Definition trapbase.c:34
float m_DefectRate
Definition trapbase.c:19
void DeferredEnableTrigger()
Definition trapbase.c:487
enum SoundTypeTrap SPAWN_FLAGS
void CreateTrigger()
Definition trapbase.c:465
string m_AnimationPhaseGrounded
Definition trapbase.c:32
void RefreshState()
Definition trapbase.c:321
void SetActive()
Definition trapbase.c:404
bool m_NeedActivation
Definition trapbase.c:18
void OnSteppedOn(EntityAI victim)
Definition trapbase.c:273
string m_InfoActivationTime
Definition trapbase.c:40
string m_AnimationPhaseSet
Definition trapbase.c:33
void SetInactive(bool stop_timer=true)
Definition trapbase.c:449
float m_InitWaitTime
Definition trapbase.c:17
TrapTrigger m_TrapTrigger
Definition trapbase.c:44
void SetupTrapPlayer(PlayerBase player, bool set_position=true)
Definition trapbase.c:378
float m_DamagePlayers
Definition trapbase.c:20
void StartActivate(PlayerBase player)
Definition trapbase.c:428
void DeleteTrigger()
Definition trapbase.c:478
void StartDeactivate(PlayerBase player)