Dayz Explorer 1.28.160049
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 {
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);
52 m_TrapTrigger.SetParentObject(this);
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 {
131 m_UpdateTimer.Stop();
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 {
143 m_UpdateTimer.Stop();
144 }
145
146 SetInactive(false);
147 Synch(EntityAI.Cast(obj));
148
149 return;
150 }
151
152 if (obj.IsDamageDestroyed())
153 return;
154
155 string zoneUsed = damageZone;
156 if (damageZone == "zone_leg_random")
157 {
158 zoneUsed = "LeftLeg";
159 if (Math.RandomIntInclusive(0, 1) == 1)
160 zoneUsed = "RightLeg";
161 }
162
164 ZombieBase zombie;
165 if (obj.IsInherited(PlayerBase) || (Class.CastTo(zombie,obj) && !zombie.IsCrawling() && Math.RandomIntInclusive(0, 1) == 1))
166 {
168 }
169
170 obj.ProcessDirectDamage(DamageType.CLOSE_COMBAT, this, zoneUsed, "BearTrapHit", "0 0 0", 1);
171
172 SetInactive(false);
173 Synch(EntityAI.Cast(obj));
174 }
175
176 // Causes the player to start limping. This is temporary and should at some point be replaced by broken legs
177 void CauseVictimToStartLimping(Object obj, string damagedZone)
178 {
179 PlayerBase player;
180 ZombieBase zombie;
181 if (Class.CastTo(player,obj))
182 {
183 player.DamageAllLegs(player.GetMaxHealth() * 2); //reduce legs health (not regular DamageSystem damage, does not transfer!)
184 }
185 else if (Class.CastTo(zombie,obj))
186 {
187 zombie.SetHealth("LeftLeg", "Health", 0.0);
188 zombie.SetHealth("RightLeg", "Health", 0.0);
189 }
190 }
191
193 {
194 EffectSound sound = SEffectManager.PlaySound("beartrapCloseDamage_SoundSet", GetPosition(), 0, 0, false);
195 sound.SetAutodestroy(true);
196 }
197
199 {
200 EffectSound sound = SEffectManager.PlaySound("beartrapClose_SoundSet", GetPosition(), 0, 0, false);
201 sound.SetAutodestroy(true);
202 }
203
205 {
206 EffectSound sound = SEffectManager.PlaySound("beartrapOpen_SoundSet", GetPosition(), 0, 0, false);
207 sound.SetAutodestroy(true);
208 }
209
210 override void OnActivate()
211 {
212 #ifndef SERVER
214 #endif
215 }
216
217 override void OnDisarm()
218 {
219 #ifndef SERVER
221 #endif
222 }
223
224 //================================================================
225 // ADVANCED PLACEMENT
226 //================================================================
227
228 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
229 {
230 super.OnPlacementComplete(player, position, orientation);
231
232 if (GetGame().IsServer())
233 {
234 PlayerBase player_PB = PlayerBase.Cast(player);
235 StartActivate(player_PB);
236 }
237 }
238
239 override bool IsDeployable()
240 {
241 return true;
242 }
243
244 override string GetLoopDeploySoundset()
245 {
246 return "beartrap_deploy_SoundSet";
247 }
248
249 override void SetActions()
250 {
251 super.SetActions();
252
256 }
257
258#ifdef DEVELOPER
259 //================================================================
260 // DEBUG
261 //================================================================
262
263 //Debug menu Spawn Ground Special
264 override void OnDebugSpawn()
265 {
266 StartActivate(null);
267 }
268
269 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
270 {
271 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.ACTIVATE_ENTITY, "Activate", FadeColors.LIGHT_GREY));
272 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DEACTIVATE_ENTITY, "Deactivate", FadeColors.LIGHT_GREY));
273 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
274
275 super.GetDebugActions(outputList);
276 }
277
278 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
279 {
280 if (super.OnAction(action_id, player, ctx))
281 return true;
282 if (GetGame().IsServer() || !GetGame().IsMultiplayer())
283 {
284 if (action_id == EActions.ACTIVATE_ENTITY)
285 {
286 StartActivate(null);
287 }
288 else if (action_id == EActions.DEACTIVATE_ENTITY)
289 {
290 SetInactive();
291 }
292 }
293 return false;
294 }
295#endif
296}
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition entityai.c:97
void AddAction(typename actionName)
vector GetOrientation()
Super root of all classes in Enforce script.
Definition enscript.c:11
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
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:204
void OnServerSteppedOn(Object obj, string damageZone)
Definition trap_bear.c:136
override string GetLoopDeploySoundset()
Definition trap_bear.c:244
override void OnActivate()
Definition trap_bear.c:210
void PlaySoundBiteEmpty()
Definition trap_bear.c:198
void PlaySoundBiteLeg()
Definition trap_bear.c:192
override void OnDisarm()
Definition trap_bear.c:217
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition trap_bear.c:228
override bool IsDeployable()
Definition trap_bear.c:239
override void SetActions()
Definition trap_bear.c:249
void CauseVictimToStartLimping(Object obj, string damagedZone)
Definition trap_bear.c:177
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DamageType
exposed from C++ (do not change)
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition dayzanimal.c:136
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition dayzanimal.c:125
EActions
Definition eactions.c:2
bool CanBeDisarmed()
proto native CGame GetGame()
CollisionFlags
Definition endebug.c:141
const int SAT_DEBUG_ACTION
Definition constants.c:454
class JsonUndergroundAreaTriggerData GetPosition
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition itembase.c:6900
ref Timer m_UpdateTimer
Definition radialmenu.c:20
string m_AnimationPhaseTriggered
Definition trapbase.c:34
float m_DefectRate
Definition trapbase.c:19
void CreateTrigger()
Definition trapbase.c:475
void Synch(EntityAI victim)
keeping "step" here for consistency only
Definition trapbase.c:281
string m_AnimationPhaseGrounded
Definition trapbase.c:32
const float UPDATE_TIMER_INTERVAL
Definition trapbase.c:15
void OnSteppedOut(EntityAI victim)
void OnSteppedOn(EntityAI victim)
Definition trapbase.c:273
EntityAI GetClosestCarWheel(EntityAI victim)
Definition trapbase.c:623
string m_AnimationPhaseSet
Definition trapbase.c:33
void SetInactive(bool stop_timer=true)
Definition trapbase.c:459
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:438
float m_DamageOthers
Definition trapbase.c:21