DayZ 1.24
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.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 {
38 }
39 }
40
41 override void CreateTrigger()
42 {
43 super.CreateTrigger();
44
45 vector mins = "-0.1 -0.05 -0.1";
46 vector maxs = "0.1 0.4 0.1";
47
48 m_TrapTrigger.SetOrientation(GetOrientation());
51 }
52
53 override void OnUpdate(EntityAI victim)
54 {
55 if (victim && victim.IsInherited(CarScript))
56 {
58 if (wheel)
60 }
61 }
62
64 {
65 if (GetGame().IsServer() && victim)
66 {
67 if (!victim.GetAllowDamage())
68 return;
69
70 if (victim.IsInherited(CarScript))
71 {
74 m_UpdateTimer.Run(UPDATE_TIMER_INTERVAL, this, "OnUpdate", params, true);
75
76 return;
77 }
78 else
79 {
81 {
83 vector raycastEnd = "0 0.5 0" + raycastStart;
84
86 rayInput.flags = CollisionFlags.ALLOBJECTS;
88 rayInput.radius = 0.05;
90
92 {
94 {
95 if (result.obj && !result.obj.IsDamageDestroyed() && !result.obj.IsAnyInherited({ItemBase, Plant}))
96 {
97 OnServerSteppedOn(result.obj, result.obj.GetDamageZoneNameByComponentIndex(result.component));
98 return;
99 }
100 }
101 }
102 }
103
104 OnServerSteppedOn(victim, "zone_leg_random");
105 }
106 }
107 else if (!GetGame().IsDedicatedServer())
108 {
109 if (victim)
110 {
111 if (victim.IsInherited(PlayerBase))
112 victim.SpawnDamageDealtEffect();
113
115 }
116 }
117 }
118
120 {
121 if (victim.IsInherited(CarScript))
122 {
123 if (m_UpdateTimer && m_UpdateTimer.IsRunning())
124 m_UpdateTimer.Stop();
125 }
126 }
127
128 protected void OnServerSteppedOn(Object obj, string damageZone)
129 {
130 if (obj.IsInherited(CarWheel))
131 {
132 obj.ProcessDirectDamage(DamageType.CLOSE_COMBAT, this, damageZone, "BearTrapHit_CarWheel", "0 0 0", 1);
133 if (m_UpdateTimer.IsRunning())
134 m_UpdateTimer.Stop();
135
136 SetInactive(false);
137 Synch(EntityAI.Cast(obj));
138
139 return;
140 }
141
142 if (obj.IsDamageDestroyed())
143 return;
144
145 string zoneUsed = damageZone;
146 if (damageZone == "zone_leg_random")
147 {
148 zoneUsed = "LeftLeg";
149 if (Math.RandomIntInclusive(0, 1) == 1)
150 zoneUsed = "RightLeg";
151 }
152
155 if (obj.IsInherited(PlayerBase) || (Class.CastTo(zombie, obj) && !zombie.IsCrawling() && Math.RandomIntInclusive(0, 1) == 1))
157
158 obj.ProcessDirectDamage(DamageType.CLOSE_COMBAT, this, zoneUsed, "BearTrapHit", "0 0 0", 1);
159
160 SetInactive(false);
161 Synch(EntityAI.Cast(obj));
162 }
163
164 // Causes the player to start limping. This is temporary and should at some point be replaced by broken legs
166 {
169 if (Class.CastTo(player, obj))
170 {
171 player.DamageAllLegs(player.GetMaxHealth() * 2); //reduce legs health (not regular DamageSystem damage, does not transfer!)
172 }
173 else if (Class.CastTo(zombie, obj))
174 {
175 zombie.SetHealth("LeftLeg", "Health", 0.0);
176 zombie.SetHealth("RightLeg", "Health", 0.0);
177 }
178 }
179
181 {
182 EffectSound sound = SEffectManager.PlaySound("beartrapCloseDamage_SoundSet", GetPosition(), 0, 0, false);
183 sound.SetAutodestroy(true);
184 }
185
187 {
188 EffectSound sound = SEffectManager.PlaySound("beartrapClose_SoundSet", GetPosition(), 0, 0, false);
189 sound.SetAutodestroy(true);
190 }
191
193 {
194 EffectSound sound = SEffectManager.PlaySound("beartrapOpen_SoundSet", GetPosition(), 0, 0, false);
195 sound.SetAutodestroy(true);
196 }
197
198 override void OnActivate()
199 {
200#ifndef SERVER
202#endif
203 }
204
205 override void OnDisarm()
206 {
207#ifndef SERVER
209#endif
210 }
211
212 //================================================================
213 // ADVANCED PLACEMENT
214 //================================================================
215
216 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
217 {
218 super.OnPlacementComplete(player, position, orientation);
219
220 if (GetGame().IsServer())
221 {
224 }
225 }
226
227 override bool IsDeployable()
228 {
229 return true;
230 }
231
232 override string GetLoopDeploySoundset()
233 {
234 return "beartrap_deploy_SoundSet";
235 }
236
237 override void SetActions()
238 {
239 super.SetActions();
240
243 AddAction(ActionDeployObject);
244 }
245
246#ifdef DEVELOPER
247 //================================================================
248 // DEBUG
249 //================================================================
250
251 //Debug menu Spawn Ground Special
252 override void OnDebugSpawn()
253 {
255 }
256
258 {
259 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Activate", FadeColors.LIGHT_GREY));
260 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEACTIVATE_ENTITY, "Deactivate", FadeColors.LIGHT_GREY));
261 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.LIGHT_GREY));
262
263 super.GetDebugActions(outputList);
264 }
265
266 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
267 {
268 if (super.OnAction(action_id, player, ctx))
269 return true;
270 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
271 {
272 if (action_id == EActions.ACTIVATE_ENTITY)
274 else if (action_id == EActions.DEACTIVATE_ENTITY)
275 SetInactive();
276 }
277 return false;
278 }
279#endif
280}
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition EntityAI.c:97
void AddAction(typename actionName)
vector GetOrientation()
DamageType
exposed from C++ (do not change)
EActions
Definition EActions.c:2
class GP5GasMask extends MaskBase ItemBase
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition ItemBase.c:6834
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition ItemBase.c:6792
ref Timer m_UpdateTimer
Definition RadialMenu.c:20
string m_AnimationPhaseTriggered
Definition TrapBase.c:34
float m_DefectRate
Definition TrapBase.c:19
void Synch(EntityAI victim)
keeping "step" here for consistency only
Definition TrapBase.c:280
string m_AnimationPhaseGrounded
Definition TrapBase.c:32
const float UPDATE_TIMER_INTERVAL
Definition TrapBase.c:15
EntityAI GetClosestCarWheel(EntityAI victim)
Definition TrapBase.c:612
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
float m_DamagePlayers
Definition TrapBase.c:20
void StartActivate(PlayerBase player)
Definition TrapBase.c:431
float m_DamageOthers
Definition TrapBase.c:21
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
Definition EnMath.c:7
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 PlaySoundOpen()
Definition Trap_Bear.c:192
void OnServerSteppedOn(Object obj, string damageZone)
Definition Trap_Bear.c:128
override void OnSteppedOn(EntityAI victim)
Definition Trap_Bear.c:63
override void CreateTrigger()
Definition Trap_Bear.c:41
override string GetLoopDeploySoundset()
Definition Trap_Bear.c:232
override void OnActivate()
Definition Trap_Bear.c:198
static const vector m_RaycastSources[RAYCAST_SOURCES_COUNT]
Definition Trap_Bear.c:6
void PlaySoundBiteEmpty()
Definition Trap_Bear.c:186
void BearTrap()
Definition Trap_Bear.c:14
void PlaySoundBiteLeg()
Definition Trap_Bear.c:180
override void OnDisarm()
Definition Trap_Bear.c:205
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition Trap_Bear.c:216
override void OnUpdate(EntityAI victim)
Definition Trap_Bear.c:53
override bool CanBeDisarmed()
Definition Trap_Bear.c:25
override bool IsDeployable()
Definition Trap_Bear.c:227
override void SetActions()
Definition Trap_Bear.c:237
void CauseVictimToStartLimping(Object obj, string damagedZone)
Definition Trap_Bear.c:165
static const int RAYCAST_SOURCES_COUNT
Definition Trap_Bear.c:3
override void OnSteppedOut(EntityAI victim)
Definition Trap_Bear.c:119
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition Trap_Bear.c:30
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 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:757
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54
const int SAT_DEBUG_ACTION
Definition constants.c:424