DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Trap_LandMine.c
Go to the documentation of this file.
2{
3 DISARMING = 0
5
6class LandMineTrap extends TrapBase
7{
10 protected ref Timer m_DeleteTimer;
11
12 private const int BROKEN_LEG_PROB = 90;
13 private const int BLEED_SOURCE_PROB = 50;
14 private const int MAX_BLEED_SOURCE = 1;
15
17 {
18 m_DefectRate = 15;
19 m_DamagePlayers = 0; //How much damage player gets when caught
20 m_InitWaitTime = 10; //After this time after deployment, the trap is activated
21 m_InfoActivationTime = string.Format("#STR_LandMineTrap0%1#STR_LandMineTrap1", m_InitWaitTime.ToString());
22
24
25 //Order is important and must match clothing array in DamageClothing method
27 m_ClothingDmg.Insert(60); //Trousers
28 m_ClothingDmg.Insert(100); //BackPack
29 m_ClothingDmg.Insert(40); //Vest
30 m_ClothingDmg.Insert(10); //HeadGear
31 m_ClothingDmg.Insert(10); //Mask
32 m_ClothingDmg.Insert(40); //Body
33 m_ClothingDmg.Insert(50); //Feet
34 m_ClothingDmg.Insert(5); //Gloves
35 }
36
38 {
41 }
42
43 override void StartActivate(PlayerBase player)
44 {
45 super.StartActivate(player);
46
47 if (!GetGame().IsDedicatedServer())
48 {
49 EffectSound sound = SEffectManager.PlaySound("landmine_safetyPin_SoundSet", GetPosition(), 0, 0, false);
50 sound.SetAutodestroy( true );
51 m_TimerLoopSound = SEffectManager.PlaySound("landmine_timer2_SoundSet", GetPosition(), 0, 0, true);
52 }
53 }
54
55 override void OnActivatedByItem(notnull ItemBase item)
56 {
57 SetHealth("", "", 0.0);
58 DeleteThis();
59 }
60
61 override void OnActivate()
62 {
63 if (!GetGame().IsDedicatedServer())
64 {
66 {
67 m_TimerLoopSound.SetAutodestroy(true);
68 m_TimerLoopSound.SoundStop();
69 }
70
71 if (GetGame().GetPlayer())
72 {
74 }
75 }
76 }
77
78 override bool CanExplodeInFire()
79 {
80 return true;
81 }
82
83 override void OnUpdate(EntityAI victim)
84 {
85 if (victim && victim.IsInherited(CarScript))
86 {
87 EntityAI wheel = GetClosestCarWheel(victim);
88 if (wheel)
89 {
90 OnServerSteppedOn(wheel, "");
91 }
92 }
93 }
94
95 override void OnSteppedOn(EntityAI victim)
96 {
97 int i;
98
99 if (GetGame().IsServer() && victim)
100 {
101 if (!victim.GetAllowDamage())
102 {
103 return;
104 }
105
106 if (victim.IsInherited(CarScript))
107 {
109 Param1<EntityAI> params = new Param1<EntityAI>(victim);
110 m_UpdateTimer.Run(UPDATE_TIMER_INTERVAL, this, "OnUpdate", params, true);
111
112 return;
113 }
114 else
115 {
116 //Check if we have a player
117 PlayerBase victim_PB = PlayerBase.Cast(victim);
118 if (victim_PB && victim_PB.IsAlive())
119 {
120 int randNum; //value used for probability evaluation
121 randNum = Math.RandomInt(0, 100);
122 if (randNum <= BROKEN_LEG_PROB)
123 {
124 float damage = victim_PB.GetMaxHealth("RightLeg", ""); //deal 100% damage to break legs
125 victim_PB.DamageAllLegs( damage );
126 }
127
128 randNum = Math.RandomInt(0, 100);
129 if (randNum < BLEED_SOURCE_PROB)
130 {
131 for (i = 0; i < MAX_BLEED_SOURCE; i++)
132 {
133 //We add two bleeding sources max to lower half
134 randNum = Math.RandomIntInclusive(0, PlayerBase.m_BleedingSourcesLow.Count() - 1);
135
136 victim_PB.m_BleedingManagerServer.AttemptAddBleedingSourceBySelection(PlayerBase.m_BleedingSourcesLow[randNum]);
137 }
138 }
139
140 DamageClothing(victim_PB);
141 }
142 else
143 {
144 ItemBase victim_IB = ItemBase.Cast(victim);
145 if (victim_IB)
146 {
147 MiscGameplayFunctions.DealAbsoluteDmg(victim_IB, DAMAGE_TRIGGER_MINE);
148 }
149 }
150
151 Explode(DamageType.EXPLOSION);
152 }
153
154 DeleteThis();
155 }
156
157 super.OnSteppedOn(victim);
158 }
159
160 override void OnSteppedOut(EntityAI victim)
161 {
162 if (victim.IsInherited(CarScript))
163 {
164 if (m_UpdateTimer && m_UpdateTimer.IsRunning())
165 {
167 }
168 }
169 }
170
171 protected void OnServerSteppedOn(Object obj, string damageZone)
172 {
173 if (obj.IsInherited(CarWheel))
174 {
175 obj.ProcessDirectDamage(DT_CLOSE_COMBAT, this, "", "LandMineExplosion_CarWheel", "0 0 0", 1);
176 Explode(DamageType.EXPLOSION);
177 if (m_UpdateTimer.IsRunning())
178 {
180 }
181
182 }
183
184 SetInactive(false);
185 Synch(EntityAI.Cast(obj));
186 }
187
189 {
191 m_DeleteTimer.Run(1, this, "DeleteSafe");
192 }
193
194 override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
195 {
196 super.OnItemLocationChanged(old_owner, new_owner);
197 }
198
199 override void EEKilled(Object killer)
200 {
201 super.EEKilled(killer);
202
203 Explode(DamageType.EXPLOSION);
204 }
205
207 {
208 if (!GetGame().IsDedicatedServer())
209 {
210 EffectSound sound = SEffectManager.PlaySound("landmineActivate_SoundSet", GetPosition(), 0, 0, false);
211 sound.SetAutodestroy(true);
212 }
213 }
214
215 override void Explode(int damageType, string ammoType = "")
216 {
217 if (ammoType == "")
218 {
219 ammoType = ConfigGetString("ammoType");
220 }
221
222 if (ammoType == "")
223 {
224 ammoType = "Dummy_Heavy";
225 }
226
227 if ( GetGame().IsServer() )
228 {
229 SynchExplosion();
230 vector offset = Vector(0, 0.1, 0); //Vertical offset applied to landmine explosion (in meters)
231 DamageSystem.ExplosionDamage(this, NULL, ammoType, GetPosition() + offset, damageType); //Offset explosion on Y axis
232 DeleteThis();
233 }
234 }
235
236 override bool CanBeDisarmed()
237 {
238 return true;
239 }
240
241 override void OnRPC(PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
242 {
243 super.OnRPC(sender, rpc_type, ctx);
244
245 Param1<bool> p = new Param1<bool>(false);
246
247 if (!ctx.Read(p))
248 {
249 return;
250 }
251
252 bool play = p.param1;
253
254 switch (rpc_type)
255 {
256 case SoundTypeMine.DISARMING:
257 if (play)
258 {
260 }
261 else
262 {
264 }
265 break;
266 }
267 }
268
270 {
272 {
273 m_DisarmingLoopSound = SEffectManager.PlaySound("landmine_deploy_SoundSet", GetPosition());
274 }
275 }
276
278 {
280 }
281
282 //================================================================
283 // ADVANCED PLACEMENT
284 //================================================================
285
286 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
287 {
288 super.OnPlacementComplete(player, position, orientation);
289
290 if (GetGame().IsServer())
291 {
292 PlayerBase player_PB = PlayerBase.Cast(player);
293 StartActivate(player_PB);
294 }
295 }
296
297 override bool IsDeployable()
298 {
299 return true;
300 }
301
302 override string GetLoopDeploySoundset()
303 {
304 return "landmine_deploy_SoundSet";
305 }
306
307 override void SetActions()
308 {
309 super.SetActions();
310
316 }
317
318#ifdef DEVELOPER
319 //================================================================
320 // DEBUG
321 //================================================================
322
323 //Debug menu Spawn Ground Special
324 override void OnDebugSpawn()
325 {
326 StartActivate(null);
327 }
328
329 override void GetDebugButtonNames(out string button1, out string button2, out string button3, out string button4)
330 {
331 button1 = "Activate";
332 button2 = "Deactivate";
333 }
334
335 override void OnDebugButtonPressServer(int button_index)
336 {
337 switch (button_index)
338 {
339 case 1:
340 StartActivate(null);
341 break;
342 case 2:
343 SetInactive();
344 break;
345 }
346
347 }
348#endif
349}
AttachActionData ActionData ActionAttach()
Definition ActionAttach.c:9
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
void ActionDetach()
void AddAction(typename actionName)
DamageType
exposed from C++ (do not change)
override void EEKilled(Object killer)
protected ref Timer m_DeleteTimer
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
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition ItemBase.c:5779
bool CanExplodeInFire()
Definition ItemBase.c:7001
PlayerBase GetPlayer()
protected ref Timer m_UpdateTimer
Definition RadialMenu.c:20
override void OnActivatedByItem(notnull ItemBase item)
Called when this item is activated by other.
void OnRPC(float stamina, float stamina_cap, bool cooldown)
deprecated use, StaminaHandler uses SyncJunctures now
void LandMineTrap()
override void Explode(int damageType, string ammoType="")
void PlayDisarmingLoopSound()
void ~LandMineTrap()
private const int BROKEN_LEG_PROB
void DeleteThis()
protected ref EffectSound m_DisarmingLoopSound
void PlaySoundActivate()
SoundTypeMine
@ DISARMING
private const int MAX_BLEED_SOURCE
private const int BLEED_SOURCE_PROB
void StopDisarmingLoopSound()
enum SoundTypeMine m_TimerLoopSound
float m_DefectRate
Definition TrapBase.c:19
protected const float UPDATE_TIMER_INTERVAL
Definition TrapBase.c:15
protected void Synch(EntityAI victim)
keeping "step" here for consistency only
Definition TrapBase.c:306
protected void DamageClothing(PlayerBase player)
Definition TrapBase.c:721
protected EntityAI GetClosestCarWheel(EntityAI victim)
Definition TrapBase.c:680
string m_InfoActivationTime
Definition TrapBase.c:40
void SetInactive(bool stop_timer=true)
Definition TrapBase.c:510
protected ref array< int > m_ClothingDmg
Definition TrapBase.c:46
int m_InitWaitTime
Definition TrapBase.c:17
protected const int DAMAGE_TRIGGER_MINE
Definition TrapBase.c:14
float m_DamagePlayers
Definition TrapBase.c:20
void StartActivate(PlayerBase player)
Definition TrapBase.c:487
bool m_AddDeactivationDefect
Definition TrapBase.c:24
class JsonUndergroundAreaTriggerData GetPosition
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
bool IsSoundPlaying()
Get whether EffectSound is currently playing.
void SoundStop()
Stops sound.
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
Definition EnMath.c:7
The class that will be instanced (moddable)
Definition gameplay.c:378
Manager class for managing Effect (EffectParticle, EffectSound)
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
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 Read(void value_in)
override void Stop()
protected void OnServerSteppedOn(Object obj, string damageZone)
Definition Trap_Bear.c:136
override void OnSteppedOut(EntityAI victim)
Definition Trap_Bear.c:125
override bool CanBeDisarmed()
Definition Trap_Bear.c:25
override string GetLoopDeploySoundset()
Definition Trap_Bear.c:246
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 OnActivate()
Definition Trap_Bear.c:209
override void SetActions()
Definition Trap_Bear.c:251
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:53
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 void OnUpdate()
Definition tools.c:338