DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Trap_Bear.c
Go to the documentation of this file.
1class BearTrap extends TrapBase
2{
3 static const int RAYCAST_SOURCES_COUNT = 5;
4 // Raycasts start positions:
5 // Positions are local to model. Vertical offset prevents ground collision.
6 static const vector m_RaycastSources[RAYCAST_SOURCES_COUNT] = {
7 "0.0 0.1 0.0", // center
8 "0.2 0.1 0.2", // north east
9 "-.2 0.1 0.2", // north west
10 "0.2 0.1 -0.2", // south east
11 "-0.2 0.1 -0.2" // south west
12 };
13
14 void BearTrap()
15 {
16 m_DamagePlayers = 5; // How much damage player gets when caught
17 m_DamageOthers = 5; // How much damage other entities(CreatureAI) gets when caught
18 m_DefectRate = 0;
19 m_InitWaitTime = 0; // After this time after deployment, the trap is activated
20 m_AnimationPhaseGrounded = "placing";
21 m_AnimationPhaseSet = "BearTrap_Set";
22 m_AnimationPhaseTriggered = "placing";
23 }
24
25 override bool CanBeDisarmed()
26 {
27 return true;
28 }
29
30 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
31 {
32 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
33
34 if (GetGame().IsServer())
35 {
36 if (newLevel == GameConstants.STATE_RUINED)
37 {
39 }
40 }
41 }
42
43 override void CreateTrigger()
44 {
45 super.CreateTrigger();
46
47 vector mins = "-0.1 -0.05 -0.1";
48 vector maxs = "0.1 0.4 0.1";
49
50 m_TrapTrigger.SetOrientation(GetOrientation());
51 m_TrapTrigger.SetExtents(mins, maxs);
53 }
54
55 override void OnUpdate(EntityAI victim)
56 {
57 if (victim && victim.IsInherited(CarScript))
58 {
59 EntityAI wheel = GetClosestCarWheel(victim);
60 if (wheel)
61 {
62 OnServerSteppedOn(wheel, "");
63 }
64 }
65 }
66
67 override void OnSteppedOn(EntityAI victim)
68 {
69 if (GetGame().IsServer() && victim)
70 {
71 if (!victim.GetAllowDamage())
72 return;
73
74 if (victim.IsInherited(CarScript))
75 {
77 Param1<EntityAI> params = new Param1<EntityAI>(victim);
78 m_UpdateTimer.Run(UPDATE_TIMER_INTERVAL, this, "OnUpdate", params, true);
79
80 return;
81 }
82 else
83 {
84 foreach (vector raycastSourcePosition: m_RaycastSources)
85 {
86 vector raycastStart = ModelToWorld(raycastSourcePosition);
87 vector raycastEnd = "0 0.5 0" + raycastStart;
88
89 RaycastRVParams rayInput = new RaycastRVParams(raycastStart, raycastEnd, this);
90 rayInput.flags = CollisionFlags.ALLOBJECTS;
91 rayInput.type = ObjIntersectFire;
92 rayInput.radius = 0.05;
94
95 if (DayZPhysics.RaycastRVProxy(rayInput, results))
96 {
97 foreach (RaycastRVResult result: results)
98 {
99 if (result.obj && !result.obj.IsDamageDestroyed() && !result.obj.IsAnyInherited({ItemBase, Plant}))
100 {
101 OnServerSteppedOn(result.obj, result.obj.GetDamageZoneNameByComponentIndex(result.component));
102 return;
103 }
104 }
105 }
106 }
107
108 OnServerSteppedOn(victim, "zone_leg_random");
109 }
110 }
111 else if (!GetGame().IsDedicatedServer())
112 {
113 if (victim)
114 {
115 if (victim.IsInherited(PlayerBase))
116 {
117 victim.SpawnDamageDealtEffect();
118 }
119
121 }
122 }
123 }
124
125 override void OnSteppedOut(EntityAI victim)
126 {
127 if (victim.IsInherited(CarScript))
128 {
129 if (m_UpdateTimer && m_UpdateTimer.IsRunning())
130 {
132 }
133 }
134 }
135
136 protected void OnServerSteppedOn(Object obj, string damageZone)
137 {
138 if (obj.IsInherited(CarWheel))
139 {
140 obj.ProcessDirectDamage(DamageType.CLOSE_COMBAT, this, damageZone, "BearTrapHit_CarWheel", "0 0 0", 1);
141 if (m_UpdateTimer.IsRunning())
142 {
144 }
145
146 SetInactive(false);
147 Synch(EntityAI.Cast(obj));
148
149 return;
150 }
151
152 string zoneUsed = damageZone;
153 if (damageZone == "zone_leg_random")
154 {
155 zoneUsed = "LeftLeg";
156 if (Math.RandomIntInclusive(0, 1) == 1)
157 {
158 zoneUsed = "RightLeg";
159 }
160 }
161
163 ZombieBase zombie;
164 if (obj.IsInherited(PlayerBase) || (Class.CastTo(zombie,obj) && !zombie.IsCrawling() && Math.RandomIntInclusive(0, 1) == 1))
165 {
167 }
168
169 obj.ProcessDirectDamage(DamageType.CLOSE_COMBAT, this, zoneUsed, "BearTrapHit", "0 0 0", 1);
170
171 SetInactive(false);
172 Synch(EntityAI.Cast(obj));
173 }
174
175 // Causes the player to start limping. This is temporary and should at some point be replaced by broken legs
176 void CauseVictimToStartLimping(Object obj, string damagedZone)
177 {
178 PlayerBase player;
179 ZombieBase zombie;
180 if (Class.CastTo(player,obj))
181 {
182 player.DamageAllLegs(player.GetMaxHealth() * 2); //reduce legs health (not regular DamageSystem damage, does not transfer!)
183 }
184 else if (Class.CastTo(zombie,obj))
185 {
186 zombie.SetHealth("LeftLeg","Health",0.0);
187 zombie.SetHealth("RightLeg","Health",0.0);
188 }
189 }
190
192 {
193 EffectSound sound = SEffectManager.PlaySound("beartrapCloseDamage_SoundSet", GetPosition(), 0, 0, false);
194 sound.SetAutodestroy(true);
195 }
196
198 {
199 EffectSound sound = SEffectManager.PlaySound("beartrapClose_SoundSet", GetPosition(), 0, 0, false);
200 sound.SetAutodestroy(true);
201 }
202
204 {
205 EffectSound sound = SEffectManager.PlaySound("beartrapOpen_SoundSet", GetPosition(), 0, 0, false);
206 sound.SetAutodestroy(true);
207 }
208
209 override void OnActivate()
210 {
211 #ifndef SERVER
213 #endif
214 }
215
216 override void OnDisarm()
217 {
218 #ifndef SERVER
220 #endif
221 }
222
223 //================================================================
224 // ADVANCED PLACEMENT
225 //================================================================
226
227 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
228 {
229 super.OnPlacementComplete(player, position, orientation);
230
231 if (GetGame().IsServer())
232 {
233 PlayerBase player_PB = PlayerBase.Cast(player);
234 StartActivate(player_PB);
235
236 m_TrapTrigger.SetPosition(position);
237 m_TrapTrigger.SetOrientation(orientation);
238 }
239 }
240
241 override bool IsDeployable()
242 {
243 return true;
244 }
245
246 override string GetLoopDeploySoundset()
247 {
248 return "beartrap_deploy_SoundSet";
249 }
250
251 override void SetActions()
252 {
253 super.SetActions();
254
258 }
259
260#ifdef DEVELOPER
261 //================================================================
262 // DEBUG
263 //================================================================
264
265 //Debug menu Spawn Ground Special
266 override void OnDebugSpawn()
267 {
268 StartActivate(null);
269 }
270
271 override void GetDebugButtonNames(out string button1, out string button2, out string button3, out string button4)
272 {
273 button1 = "Activate";
274 button2 = "Deactivate";
275 }
276
277 override void OnDebugButtonPressServer(int button_index)
278 {
279 switch (button_index)
280 {
281 case 1:
282 StartActivate(null);
283 break;
284 case 2:
285 SetInactive();
286 break;
287 }
288 }
289#endif
290}
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
void AddAction(typename actionName)
vector GetOrientation()
DamageType
exposed from C++ (do not change)
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
protected ref Timer m_UpdateTimer
Definition RadialMenu.c:20
string m_AnimationPhaseTriggered
Definition TrapBase.c:34
float m_DefectRate
Definition TrapBase.c:19
protected const float UPDATE_TIMER_INTERVAL
Definition TrapBase.c:15
string m_AnimationPhaseGrounded
Definition TrapBase.c:32
protected void Synch(EntityAI victim)
keeping "step" here for consistency only
Definition TrapBase.c:306
protected EntityAI GetClosestCarWheel(EntityAI victim)
Definition TrapBase.c:680
string m_AnimationPhaseSet
Definition TrapBase.c:33
void SetInactive(bool stop_timer=true)
Definition TrapBase.c:510
int m_InitWaitTime
Definition TrapBase.c:17
float m_DamagePlayers
Definition TrapBase.c:20
void StartActivate(PlayerBase player)
Definition TrapBase.c:487
float m_DamageOthers
Definition TrapBase.c:21
protected TrapTrigger m_TrapTrigger
Definition TrapBase.c:44
class JsonUndergroundAreaTriggerData GetPosition
Super root of all classes in Enforce script.
Definition EnScript.c:11
static proto bool RaycastRVProxy(notnull RaycastRVParams in, out notnull array< ref RaycastRVResult > results, array< Object > excluded=null)
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.
Definition EnMath.c:7
CollisionFlags flags
Definition DayZPhysics.c:60
float radius
radius along the ray tested
Definition DayZPhysics.c:54
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.
override void Stop()
protected void OnServerSteppedOn(Object obj, string damageZone)
Definition Trap_Bear.c:136
override void OnDisarm()
Definition Trap_Bear.c:216
override void OnSteppedOut(EntityAI victim)
Definition Trap_Bear.c:125
override bool CanBeDisarmed()
Definition Trap_Bear.c:25
void PlaySoundBiteLeg()
Definition Trap_Bear.c:191
override void OnUpdate(EntityAI victim)
Definition Trap_Bear.c:55
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
void BearTrap()
Definition Trap_Bear.c:14
void CauseVictimToStartLimping(Object obj, string damagedZone)
Definition Trap_Bear.c:176
override bool IsDeployable()
Definition Trap_Bear.c:241
void PlaySoundOpen()
Definition Trap_Bear.c:203
override void OnActivate()
Definition Trap_Bear.c:209
void PlaySoundBiteEmpty()
Definition Trap_Bear.c:197
static const int RAYCAST_SOURCES_COUNT
Definition Trap_Bear.c:3
override void SetActions()
Definition Trap_Bear.c:251
static const vector m_RaycastSources[RAYCAST_SOURCES_COUNT]
Definition Trap_Bear.c:6
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
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
CollisionFlags
Definition EnDebug.c:141
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const int STATE_RUINED
Definition constants.c:742
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:53