DayZ 1.24
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
9class TripwireTrap : TrapBase
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.OnVariablesSynchronized();
40
41 if (IsPlaceSound())
43 }
44
46 {
47 super.OnStoreSave(ctx);
48
49 ctx.Write(m_State);
50 }
51
52 //----------------------------------------------------------------
53 override bool OnStoreLoad(ParamsReadContext ctx, int version)
54 {
55 if (!super.OnStoreLoad(ctx, version))
56 return false;
57
58 int state = FOLDED;
59 if (!ctx.Read(state))
60 state = FOLDED;
61
64
65 return true;
66 }
67
68 override void CreateTrigger()
69 {
70 m_TrapTrigger = TripWireTrigger.Cast(GetGame().CreateObjectEx("TripWireTrigger", GetPosition(), SPAWN_FLAGS));
71 vector mins = "-0.75 0.3 -0.01";
72 vector maxs = "0.75 0.32 0.01";
73 m_TrapTrigger.SetOrientation(GetOrientation());
76
78 }
79
81 {
82 if (!victim)
83 return;
84
85 if (!victim.GetAllowDamage())
86 return;
87
88 // We must deal some damage, here 5 shock as melee damage in order to trigger hit animation
89 if (GetGame().IsServer())
90 {
91 victim.ProcessDirectDamage(DT_CLOSE_COMBAT, this, "", "TripWireHit", "0 0 0", 1);
93 SetInactive(false);
94 }
95
96 // We play the trap trigger sound
97#ifndef SERVER
98 EffectSound sound = SEffectManager.PlaySound("TripwireTrap_Trigger_SoundSet", GetPosition());
99 sound.SetAutodestroy(true);
100#endif
101 }
102
104 {
105 super.OnItemLocationChanged(old_owner, new_owner);
106
108 if (player)
109 {
111 return;
112 }
113 }
114
116 {
117 super.EEItemLocationChanged(oldLoc, newLoc);
118
120 {
121 if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.GROUND)
122 {
123 SetActive();
124 m_TrapTrigger.SetPosition(m_TriggerPosition);
125 m_TrapTrigger.SetOrientation(m_TriggerOrientation);
126 }
127
129 }
130
131 if (oldLoc.GetType() == InventoryLocationType.GROUND && newLoc.GetType() == InventoryLocationType.CARGO)
132 {
133 SetInactive();
136 RefreshState();
137 }
138 }
139
140 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
141 {
142 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
143
144 if (GetGame().IsServer())
145 {
147 {
149 RefreshState();
150 }
151 }
152 }
153
154 override void SetInactive(bool stop_timer = true)
155 {
156 super.SetInactive(stop_timer);
157
158 // de-attach attachments after "activating them"
159 for (int att = 0; att < GetInventory().AttachmentCount(); att++)
160 {
161 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(att));
162 if (attachment)
163 {
164 if (attachment.IsLockedInSlot())
165 attachment.UnlockFromParent();
166
167 attachment.OnActivatedByItem(this);
168 GetInventory().DropEntity(InventoryMode.SERVER, this, attachment);
169 }
170 }
171 }
172
174 {
176 }
177
179 {
180 return m_State;
181 }
182
184 {
186 }
187
189 {
190 return m_WireMaterial;
191 }
192
193
194 override void RefreshState()
195 {
196 super.RefreshState();
197
198 if (GetState() == FOLDED)
199 FoldTripWire();
200 }
201
202 override void SetupTrapPlayer(PlayerBase player, bool set_position = true)
203 {
204 super.SetupTrapPlayer(player, set_position);
206 }
207
209 {
210 super.StartDeactivate(player);
211
214 }
215
216 // We do not want players to attach charges before trap is deployed
218 {
219 if (GetState() != DEPLOYED)
220 return false;
221
222 return super.CanReceiveAttachment(attachment, slotId);
223 }
224
225 // As players cannot attch charges, we do not display the attachment slot before it is necessary
227 {
228 if (GetState() != DEPLOYED)
229 return false;
230
231 return super.CanDisplayAttachmentSlot(slot_id);
232 }
233
234 override void EEItemAttached(EntityAI item, string slot_name)
235 {
236 super.EEItemAttached(item, slot_name);
237
238 SetTakeable(false);
239 }
240
241 override void EEItemDetached(EntityAI item, string slot_name)
242 {
243 super.EEItemDetached(item, slot_name);
244
245 SetTakeable(false);
246 }
247
248 override void EEKilled(Object killer)
249 {
250 if (m_TrapTrigger)
252
253 super.EEKilled(killer);
254 }
255
256 // We reset the animation phases to see the tripwire as folded
258 {
259 if (m_AnimationPhaseGrounded != "")
260 {
261 SetAnimationPhase(m_AnimationPhaseSet, 1);
262
264 SetAnimationPhase(m_AnimationPhaseTriggered, 1);
265
266 SetAnimationPhase(m_AnimationPhaseGrounded, 0);
267 }
268 }
269
270 override void OnInventoryEnter(Man player)
271 {
273 }
274
275#ifdef PLATFORM_WINDOWS
276 // How one sees the tripwire when in vicinity
277 override int GetViewIndex()
278 {
279 if (MemoryPointExists("invView2"))
280 {
282 GetInventory().GetCurrentInventoryLocation(il);
283 InventoryLocationType type = il.GetType();
284 switch (type)
285 {
286 case InventoryLocationType.CARGO:
287 {
288 return 0;
289 }
290 case InventoryLocationType.ATTACHMENT:
291 {
292 return 1;
293 }
294 case InventoryLocationType.HANDS:
295 {
296 return 0;
297 }
298 case InventoryLocationType.GROUND:
299 {
300 // Different view index depending on deployment state
301 if (GetState() == DEPLOYED)
302 return 1;
303 else if (GetState() == TRIGGERED)
304 return 2;
305
306 // When folded
307 return 0;
308 }
309 case InventoryLocationType.PROXYCARGO:
310 {
311 return 0;
312 }
313 default:
314 {
315 if (GetState() == DEPLOYED)
316 return 1;
317 else if (GetState() == TRIGGERED)
318 return 2;
319
320 // When folded
321 return 0;
322 }
323 }
324 }
325 return 0;
326 }
327#endif
328
329 //================================================================
330 // ADVANCED PLACEMENT
331 //================================================================
332
333 // On placement complete, set state, play sound, create trigger and synch to client
334 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
335 {
336 SetIsPlaceSound(true);
337 if (GetGame().IsServer())
338 {
340
344 }
345 }
346
347 override void OnPlacementCancelled(Man player)
348 {
349 super.OnPlacementCancelled(player);
350
352
354 }
355
356 override bool IsDeployable()
357 {
358 return true;
359 }
360
361 // Tripwire cannot be taken if deployed with attachment
362 override bool IsTakeable()
363 {
364 return GetState() != DEPLOYED || (GetInventory().AttachmentCount() == 0 && GetState() == DEPLOYED);
365 }
366
367 override string GetDeploySoundset()
368 {
369 return "tripwire_deploy_SoundSet";
370 }
371
372 override string GetLoopDeploySoundset()
373 {
374 return "tripwiretrap_deploy_SoundSet";
375 }
376
377 override void SetActions()
378 {
379 super.SetActions();
380
382 AddAction(ActionDeployObject);
383 }
384
385 // ====================================
386 // =========== DEPRECATED ===========
387 // ====================================
388
390 {
391 if (GetInventory().AttachmentCount() > 0)
392 {
393 ItemBase attachment = ItemBase.Cast(GetInventory().GetAttachmentFromIndex(0));
394
395 if (attachment)
396 {
397 // Hide all proxies
398 for (int i = 1; i <= 3; i++)
399 HideSelection("s" + i + "_charge");
400
401 // Now show the one we need to see
402 string proxy_to_show = string.Format("s%1_charge", GetState());
403 //Print(proxy_to_show);
404 ShowSelection(proxy_to_show);
405 }
406 }
407 }
408
409#ifdef DEVELOPER
410 //================================================================
411 // DEBUG
412 //================================================================
413
414 //Debug menu Spawn Ground Special
415 override void OnDebugSpawn()
416 {
419 }
420
422 {
423 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Activate", FadeColors.LIGHT_GREY));
424 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEACTIVATE_ENTITY, "Deactivate", FadeColors.LIGHT_GREY));
425 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
426
427 super.GetDebugActions(outputList);
428 }
429
430 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
431 {
432 if (super.OnAction(action_id, player, ctx))
433 return true;
434 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
435 {
436 if (action_id == EActions.ACTIVATE_ENTITY)
438 else if (action_id == EActions.DEACTIVATE_ENTITY)
439 SetInactive();
440 }
441 return false;
442 }
443
444#endif
445}
446
447class TripwireTrapDeployed : TripwireTrap
448{
449
450}
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition EntityAI.c:97
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition Inventory.c:22
void AddAction(typename actionName)
void SetActions()
override void OnVariablesSynchronized()
vector GetOrientation()
override void EEItemDetached(EntityAI item, string slot_name)
override void EEItemAttached(EntityAI item, string slot_name)
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()
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
InventoryLocationType
types of Inventory Location
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition ItemBase.c:6834
bool IsDeployable()
Definition ItemBase.c:8891
string GetDeploySoundset()
Definition LargeTent.c:138
void PlayPlaceSound()
Definition ItemBase.c:9027
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:8449
override void SetTakeable(bool pState)
Definition ItemBase.c:8905
void SetIsPlaceSound(bool is_place_sound)
Definition ItemBase.c:8962
string GetLoopDeploySoundset()
Definition LargeTent.c:143
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition ItemBase.c:5867
bool IsPlaceSound()
Definition ItemBase.c:8967
override bool CanReceiveAttachment(EntityAI attachment, int slotId)
Definition ItemBase.c:8724
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition ItemBase.c:6792
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition ItemBase.c:6535
void OnStoreSave(ParamsWriteContext ctx)
bool OnStoreLoad(ParamsReadContext ctx, int version)
override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
void SetState(bool state)
bool m_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:490
enum SoundTypeTrap SPAWN_FLAGS
void CreateTrigger()
Definition TrapBase.c:468
string m_AnimationPhaseGrounded
Definition TrapBase.c:32
void RefreshState()
Definition TrapBase.c:336
void SetActive()
Definition TrapBase.c:409
bool m_NeedActivation
Definition TrapBase.c:18
void OnSteppedOn(EntityAI victim)
Definition TrapBase.c:272
string m_InfoActivationTime
Definition TrapBase.c:40
string m_AnimationPhaseSet
Definition TrapBase.c:33
void SetInactive(bool stop_timer=true)
Definition TrapBase.c:452
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:385
float m_DamagePlayers
Definition TrapBase.c:20
void StartActivate(PlayerBase player)
Definition TrapBase.c:431
void DeleteTrigger()
Definition TrapBase.c:481
void StartDeactivate(PlayerBase player)
class JsonUndergroundAreaTriggerData GetPosition
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
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
void SetParentObject(TrapBase obj)
Definition TrapTrigger.c:18
void SetExtents(vector mins, vector maxs)
Set the size of the Trigger, avoid using SetCollisionBox directly.
Definition Trigger.c:116
proto string ToString()
proto native CGame GetGame()
const int STATE_RUINED
Definition constants.c:757
const int SAT_DEBUG_ACTION
Definition constants.c:424
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.
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8
proto native int GetState()
returns one of STATE_...