Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
trap_landmine.c
Go to the documentation of this file.
2 {
4 }
5 
6 class LandMineTrap extends TrapBase
7 {
8  protected ref EffectSound m_TimerLoopSound;
11  protected ref Timer m_DeleteTimer;
12 
13  private const int BROKEN_LEG_PROB = 90;
14  private const int BLEED_SOURCE_PROB = 50;
15  private const int MAX_BLEED_SOURCE = 1;
16 
17  void LandMineTrap()
18  {
19  m_DefectRate = 15;
20  m_DamagePlayers = 0; //How much damage player gets when caught
21  m_InitWaitTime = 10; //After this time after deployment, the trap is activated
22  m_InfoActivationTime = string.Format("#STR_LandMineTrap0%1#STR_LandMineTrap1", m_InitWaitTime.ToString());
23 
25 
26  //Order is important and must match clothing array in DamageClothing method
28  m_ClothingDmg.Insert(60); //Trousers
29  m_ClothingDmg.Insert(100); //BackPack
30  m_ClothingDmg.Insert(40); //Vest
31  m_ClothingDmg.Insert(10); //HeadGear
32  m_ClothingDmg.Insert(10); //Mask
33  m_ClothingDmg.Insert(40); //Body
34  m_ClothingDmg.Insert(50); //Feet
35  m_ClothingDmg.Insert(5); //Gloves
36  }
37 
39  {
40  SEffectManager.DestroyEffect(m_TimerLoopSound);
41  SEffectManager.DestroyEffect(m_DisarmingLoopSound);
42  }
43 
44  override void StartActivate(PlayerBase player)
45  {
46  super.StartActivate(player);
47 
48  if (!GetGame().IsDedicatedServer())
49  {
50  if (m_SafetyPinSound)
51  {
52  m_SafetyPinSound = SEffectManager.PlaySound("landmine_safetyPin_SoundSet", GetPosition(), 0, 0, false);
53  m_SafetyPinSound.SetAutodestroy(true);
54  }
55 
56  if (!m_TimerLoopSound)
57  m_TimerLoopSound = SEffectManager.PlaySound("landmine_timer2_SoundSet", GetPosition(), 0, 0, true);
58  }
59  }
60 
61  override void OnActivatedByItem(notnull ItemBase item)
62  {
63  SetHealth("", "", 0.0);
64  DeleteThis();
65  }
66 
67  override void OnActivate()
68  {
69  if (!GetGame().IsDedicatedServer())
70  {
71  if (m_TimerLoopSound)
72  {
73  m_TimerLoopSound.SetAutodestroy(true);
74  m_TimerLoopSound.SoundStop();
75  }
76 
77  if (GetGame().GetPlayer())
78  {
80  }
81  }
82  }
83 
84  override bool CanExplodeInFire()
85  {
86  return true;
87  }
88 
89  override void OnUpdate(EntityAI victim)
90  {
91  if (victim && victim.IsInherited(CarScript))
92  {
93  EntityAI wheel = GetClosestCarWheel(victim);
94  if (wheel)
95  {
96  OnServerSteppedOn(wheel, "");
97  }
98  }
99  }
100 
101  override void OnSteppedOn(EntityAI victim)
102  {
103  int i;
104 
105  if (GetGame().IsServer() && victim)
106  {
107  if (!victim.GetAllowDamage())
108  {
109  return;
110  }
111 
112  if (victim.IsInherited(CarScript))
113  {
115  Param1<EntityAI> params = new Param1<EntityAI>(victim);
116  m_UpdateTimer.Run(UPDATE_TIMER_INTERVAL, this, "OnUpdate", params, true);
117 
118  return;
119  }
120  else
121  {
122  //Check if we have a player
123  PlayerBase victim_PB = PlayerBase.Cast(victim);
124  if (victim_PB && victim_PB.IsAlive())
125  {
126  int randNum; //value used for probability evaluation
127  randNum = Math.RandomInt(0, 100);
128  if (randNum <= BROKEN_LEG_PROB)
129  {
130  float damage = victim_PB.GetMaxHealth("RightLeg", ""); //deal 100% damage to break legs
131  victim_PB.DamageAllLegs( damage );
132  }
133 
134  randNum = Math.RandomInt(0, 100);
135  if (randNum < BLEED_SOURCE_PROB)
136  {
137  for (i = 0; i < MAX_BLEED_SOURCE; i++)
138  {
139  //We add two bleeding sources max to lower half
140  randNum = Math.RandomIntInclusive(0, PlayerBase.m_BleedingSourcesLow.Count() - 1);
141 
142  victim_PB.m_BleedingManagerServer.AttemptAddBleedingSourceBySelection(PlayerBase.m_BleedingSourcesLow[randNum]);
143  }
144  }
145 
146  DamageClothing(victim_PB);
147  }
148  else
149  {
150  ItemBase victim_IB = ItemBase.Cast(victim);
151  if (victim_IB)
152  {
153  MiscGameplayFunctions.DealAbsoluteDmg(victim_IB, DAMAGE_TRIGGER_MINE);
154  }
155  }
156 
157  Explode(DamageType.EXPLOSION);
158  }
159 
160  DeleteThis();
161  }
162 
163  super.OnSteppedOn(victim);
164  }
165 
166  override void OnSteppedOut(EntityAI victim)
167  {
168  if (victim.IsInherited(CarScript))
169  {
170  if (m_UpdateTimer && m_UpdateTimer.IsRunning())
171  {
172  m_UpdateTimer.Stop();
173  }
174  }
175  }
176 
177  protected void OnServerSteppedOn(Object obj, string damageZone)
178  {
179  if (obj.IsInherited(CarWheel))
180  {
181  obj.ProcessDirectDamage(DT_CLOSE_COMBAT, this, "", "LandMineExplosion_CarWheel", "0 0 0", 1);
182  Explode(DamageType.EXPLOSION);
183 
184  if (m_UpdateTimer.IsRunning())
185  m_UpdateTimer.Stop();
186 
187  }
188 
189  SetInactive(false);
190  Synch(EntityAI.Cast(obj));
191  }
192 
193  void DeleteThis()
194  {
196  m_DeleteTimer.Run(1, this, "DeleteSafe");
197  }
198 
199  override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
200  {
201  super.OnItemLocationChanged(old_owner, new_owner);
202  }
203 
204  override void EEKilled(Object killer)
205  {
206  super.EEKilled(killer);
207 
208  Explode(DamageType.EXPLOSION);
209  }
210 
212  {
213  if (!GetGame().IsDedicatedServer())
214  {
215  EffectSound sound = SEffectManager.PlaySound("landmineActivate_SoundSet", GetPosition(), 0, 0, false);
216  sound.SetAutodestroy(true);
217  }
218  }
219 
220  override void Explode(int damageType, string ammoType = "")
221  {
222  if (ammoType == "")
223  {
224  ammoType = ConfigGetString("ammoType");
225  }
226 
227  if (ammoType == "")
228  {
229  ammoType = "Dummy_Heavy";
230  }
231 
232  if ( GetGame().IsServer() )
233  {
234  SynchExplosion();
235  vector offset = Vector(0, 0.1, 0); //Vertical offset applied to landmine explosion (in meters)
236  DamageSystem.ExplosionDamage(this, NULL, ammoType, GetPosition() + offset, damageType); //Offset explosion on Y axis
237  DeleteThis();
238  }
239  }
240 
241  override bool CanBeDisarmed()
242  {
243  return true;
244  }
245 
246  override void OnRPC(PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
247  {
248  super.OnRPC(sender, rpc_type, ctx);
249 
250  Param1<bool> p = new Param1<bool>(false);
251 
252  if (!ctx.Read(p))
253  return;
254 
255  bool play = p.param1;
256  switch (rpc_type)
257  {
258  case SoundTypeMine.DISARMING:
259  if (play)
261  else
263 
264  break;
265  }
266  }
267 
269  {
270  if (!m_DisarmingLoopSound || !m_DisarmingLoopSound.IsSoundPlaying())
271  {
272  m_DisarmingLoopSound = SEffectManager.PlaySound("landmine_deploy_SoundSet", GetPosition());
273  }
274  }
275 
277  {
278  m_DisarmingLoopSound.SoundStop();
279  }
280 
281  //================================================================
282  // ADVANCED PLACEMENT
283  //================================================================
284 
285  override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
286  {
287  super.OnPlacementComplete(player, position, orientation);
288 
289  if (GetGame().IsServer())
290  {
291  PlayerBase player_PB = PlayerBase.Cast(player);
292  StartActivate(player_PB);
293  }
294  }
295 
296  override bool IsDeployable()
297  {
298  return true;
299  }
300 
301  override string GetLoopDeploySoundset()
302  {
303  return "landmine_deploy_SoundSet";
304  }
305 
306  override void SetActions()
307  {
308  super.SetActions();
309 
314  }
315 
316 #ifdef DEVELOPER
317  //================================================================
318  // DEBUG
319  //================================================================
320 
321  //Debug menu Spawn Ground Special
322  override void OnDebugSpawn()
323  {
324  StartActivate(null);
325  }
326 
327  override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
328  {
329  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Activate", FadeColors.LIGHT_GREY));
330  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEACTIVATE_ENTITY, "Deactivate", FadeColors.LIGHT_GREY));
331  outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
332 
333  super.GetDebugActions(outputList);
334  }
335 
336  override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
337  {
338  if (super.OnAction(action_id, player, ctx))
339  return true;
340  if (GetGame().IsServer() || !GetGame().IsMultiplayer())
341  {
342  if (action_id == EActions.ACTIVATE_ENTITY)
343  {
344  StartActivate(null);
345  }
346  else if (action_id == EActions.DEACTIVATE_ENTITY)
347  {
348  SetInactive();
349  }
350  }
351  return false;
352  }
353 #endif
354 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
m_TimerLoopSound
enum SoundTypeMine m_TimerLoopSound
~LandMineTrap
void ~LandMineTrap()
Definition: trap_landmine.c:38
m_ClothingDmg
protected ref array< int > m_ClothingDmg
Definition: trapbase.c:46
ActionDeployObject
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
Definition: actiondeployobject.c:9
PlayDisarmingLoopSound
void PlayDisarmingLoopSound()
Definition: trap_landmine.c:268
m_AddDeactivationDefect
bool m_AddDeactivationDefect
Definition: trapbase.c:24
SoundTypeMine
SoundTypeMine
Definition: trap_landmine.c:1
ActionDetach
void ActionDetach()
Definition: actiondetach.c:10
m_SafetyPinSound
protected ref EffectSound m_SafetyPinSound
Definition: trap_landmine.c:9
DeleteThis
void DeleteThis()
Definition: trap_landmine.c:193
StopDisarmingLoopSound
void StopDisarmingLoopSound()
Definition: trap_landmine.c:276
DAMAGE_TRIGGER_MINE
const protected int DAMAGE_TRIGGER_MINE
Definition: trapbase.c:14
CarScript
Definition: civiliansedan.c:1
OnActivatedByItem
override void OnActivatedByItem(notnull ItemBase item)
Called when this item is activated by other.
Definition: trap_landmine.c:61
LandMineTrap
void LandMineTrap()
Definition: trap_landmine.c:17
MAX_BLEED_SOURCE
const private int MAX_BLEED_SOURCE
Definition: trap_landmine.c:15
OnActivate
override void OnActivate()
HumanCommandScript fully scriptable command.
Definition: trap_landmine.c:67
DISARMING
@ DISARMING
Definition: trap_landmine.c:3
Explode
override void Explode(int damageType, string ammoType="")
Definition: trap_landmine.c:220
DamageClothing
protected void DamageClothing(PlayerBase player)
Definition: trapbase.c:691
m_DamagePlayers
float m_DamagePlayers
Definition: trapbase.c:20
ActionTogglePlaceObject
Definition: actiontoggleplaceobject.c:1
BLEED_SOURCE_PROB
const private int BLEED_SOURCE_PROB
Definition: trap_landmine.c:14
OnUpdate
override void OnUpdate(EntityAI victim)
Definition: trap_landmine.c:89
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
IsDeployable
override bool IsDeployable()
Definition: trap_landmine.c:296
PlayerIdentity
The class that will be instanced (moddable)
Definition: gameplay.c:377
OnDebugSpawn
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
Definition: hatchback_02.c:404
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
UPDATE_TIMER_INTERVAL
const protected float UPDATE_TIMER_INTERVAL
Definition: trapbase.c:15
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
GetClosestCarWheel
protected EntityAI GetClosestCarWheel(EntityAI victim)
Definition: trapbase.c:650
EEKilled
override void EEKilled(Object killer)
Definition: trap_landmine.c:204
SetActions
override void SetActions()
Definition: trap_landmine.c:306
SetInactive
override void SetInactive(bool stop_timer=true)
Definition: trap_tripwire.c:160
DamageType
DamageType
exposed from C++ (do not change)
Definition: damagesystem.c:10
OnPlacementComplete
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition: trap_landmine.c:285
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
Object
Definition: objecttyped.c:1
CarWheel
Definition: inventoryitem.c:413
OnSteppedOn
override void OnSteppedOn(EntityAI victim)
Definition: trap_landmine.c:101
CanExplodeInFire
override bool CanExplodeInFire()
Definition: trap_landmine.c:84
GetDebugActions
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition: edible_base.c:744
ActionAttach
ActionAttachWheels ActionAttach
EActions
EActions
Definition: eactions.c:1
OnAction
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition: edible_base.c:755
OnRPC
override void OnRPC(PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
Definition: trap_landmine.c:246
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
BROKEN_LEG_PROB
const private int BROKEN_LEG_PROB
Definition: trap_landmine.c:13
OnSteppedOut
override void OnSteppedOut(EntityAI victim)
Definition: trap_landmine.c:166
StartActivate
override void StartActivate(PlayerBase player)
Definition: trap_landmine.c:44
OnItemLocationChanged
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition: trap_landmine.c:199
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
m_DisarmingLoopSound
protected ref EffectSound m_DisarmingLoopSound
Definition: trap_landmine.c:10
Synch
protected void Synch(EntityAI victim)
keeping "step" here for consistency only
Definition: trapbase.c:298
m_InfoActivationTime
string m_InfoActivationTime
Definition: trapbase.c:40
CanBeDisarmed
override bool CanBeDisarmed()
Definition: trap_landmine.c:241
Timer
Definition: dayzplayerimplement.c:62
OnServerSteppedOn
protected void OnServerSteppedOn(Object obj, string damageZone)
Definition: trap_landmine.c:177
SAT_DEBUG_ACTION
const int SAT_DEBUG_ACTION
Definition: constants.c:424
Math
Definition: enmath.c:6
m_DefectRate
float m_DefectRate
Definition: trapbase.c:19
TSelectableActionInfoWithColor
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition: entityai.c:97
PlaySoundActivate
void PlaySoundActivate()
Definition: trap_landmine.c:211
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
m_InitWaitTime
float m_InitWaitTime
Definition: trapbase.c:17
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EntityAI
Definition: building.c:5
GetLoopDeploySoundset
override string GetLoopDeploySoundset()
Definition: trap_landmine.c:301
TrapBase
Definition: trap_bear.c:1
m_DeleteTimer
protected ref Timer m_DeleteTimer
Definition: trap_landmine.c:11
m_UpdateTimer
protected ref Timer m_UpdateTimer
Definition: radialmenu.c:20