Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
trap_bear.c
Go to the documentation of this file.
1 class 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  {
38  SetInactive();
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 
120  PlaySoundBiteLeg();
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  {
167  CauseVictimToStartLimping(obj, "");
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 
192  void PlaySoundBiteLeg()
193  {
194  EffectSound sound = SEffectManager.PlaySound("beartrapCloseDamage_SoundSet", GetPosition(), 0, 0, false);
195  sound.SetAutodestroy(true);
196  }
197 
198  void PlaySoundBiteEmpty()
199  {
200  EffectSound sound = SEffectManager.PlaySound("beartrapClose_SoundSet", GetPosition(), 0, 0, false);
201  sound.SetAutodestroy(true);
202  }
203 
204  void PlaySoundOpen()
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
213  PlaySoundOpen();
214  #endif
215  }
216 
217  override void OnDisarm()
218  {
219  #ifndef SERVER
220  PlaySoundBiteEmpty();
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.LIGHT_GREY));
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 }
GetGame
proto native CGame GetGame()
ActionDeployObject
PlaceObjectActionReciveData ActionReciveData ActionDeployObject()
Definition: actiondeployobject.c:9
m_DamageOthers
float m_DamageOthers
Definition: trapbase.c:21
CarScript
Definition: civiliansedan.c:1
m_TrapTrigger
protected TrapTrigger m_TrapTrigger
Definition: trapbase.c:44
RaycastRVResult
Definition: dayzphysics.c:98
OnDisarm
void OnDisarm()
also called from RPC on client
OnPlacementComplete
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition: explosivesbase.c:133
m_AnimationPhaseSet
string m_AnimationPhaseSet
Definition: trapbase.c:33
ActionClapBearTrapWithThisItem
Definition: actionclapbeartrapwiththisitem.c:1
m_DamagePlayers
float m_DamagePlayers
Definition: trapbase.c:20
GetLoopDeploySoundset
override string GetLoopDeploySoundset()
Definition: largetent.c:151
ActionTogglePlaceObject
Definition: actiontoggleplaceobject.c:1
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
CollisionFlags
CollisionFlags
Definition: endebug.c:140
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
RaycastRVParams
Definition: dayzphysics.c:49
vector
Definition: enconvert.c:105
GetClosestCarWheel
protected EntityAI GetClosestCarWheel(EntityAI victim)
Definition: trapbase.c:650
CanBeDisarmed
bool CanBeDisarmed()
Definition: explosivesbase.c:231
CreateTrigger
override void CreateTrigger()
Definition: trap_tripwire.c:70
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
OnUpdate
proto native void OnUpdate()
Definition: tools.c:349
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
SetActions
void SetActions()
Definition: advancedcommunication.c:79
GetDebugActions
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition: edible_base.c:744
OnActivate
void OnActivate(DayZPlayerCamera pPrevCamera, DayZPlayerCameraResult pPrevCameraResult)
virtual callback - called when camera is created
Definition: dayzplayer.c:69
m_AnimationPhaseGrounded
string m_AnimationPhaseGrounded
Definition: trapbase.c:32
EActions
EActions
Definition: eactions.c:1
OnAction
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition: edible_base.c:755
array< ref RaycastRVResult >
OnSteppedOut
override void OnSteppedOut(EntityAI victim)
Definition: trap_landmine.c:166
StartActivate
override void StartActivate(PlayerBase player)
Definition: trap_landmine.c:44
IsDeployable
override bool IsDeployable()
Definition: basebuildingbase.c:339
EEHealthLevelChanged
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition: basebuildingbase.c:463
Synch
protected void Synch(EntityAI victim)
keeping "step" here for consistency only
Definition: trapbase.c:298
GameConstants
Definition: constants.c:612
DayZPhysics
Definition: dayzphysics.c:123
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
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
m_DefectRate
float m_DefectRate
Definition: trapbase.c:19
m_AnimationPhaseTriggered
string m_AnimationPhaseTriggered
Definition: trapbase.c:34
TSelectableActionInfoWithColor
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition: entityai.c:97
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
m_InitWaitTime
float m_InitWaitTime
Definition: trapbase.c:17
ZombieBase
Definition: zombiefemalebase.c:1
EntityAI
Definition: building.c:5
TrapBase
Definition: trap_bear.c:1
m_UpdateTimer
protected ref Timer m_UpdateTimer
Definition: radialmenu.c:20
GetOrientation
vector GetOrientation()
Definition: areadamagemanager.c:306