Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
barbedwiretrigger.c
Go to the documentation of this file.
3 {
4  ItemBase m_ParentBarbedWire;
5  const static int SOUNDS_COLLISION_COUNT = 4;
6  const static int SOUNDS_SHOCK_COUNT = 4;
7  const static string m_SoundsCollision[SOUNDS_COLLISION_COUNT] = {"barbedFenceCollision1", "barbedFenceCollision2", "barbedFenceCollision3", "barbedFenceCollision4"};
8  const static string m_SoundsShock[SOUNDS_SHOCK_COUNT] = {"electricFenceShock1", "electricFenceShock2", "electricFenceShock3", "electricFenceShock4"};
9 
10  // When a player / AI touches the Barbed Wire
11  override void OnEnter( Object obj )
12  {
13  if ( g_Game.IsServer() )
14  {
15  if ( m_ParentBarbedWire )
16  {
17  if ( obj.IsInherited(PlayerBase) )
18  {
19  // When a player touches the barbed wire
20  string cfg = "CfgVehicles BarbedWire barbedWireShockEnergyConsumption";
21  float needed_energy = GetGame().ConfigGetFloat(cfg);
22  bool energy_consumed = m_ParentBarbedWire.GetCompEM().ConsumeEnergy(needed_energy);
23  PlayerBase player = PlayerBase.Cast( obj );
24 
25  if ( energy_consumed )
26  {
27  // TO DO:
28  // -Do electrical damage.
29  // -Cause bleeding?
30  // -Do some damage!
31 
32  player.MessageImportant( "*SCRATCH and ELECTROCUTION*" );
33 
34  // Play sound
35  SoundCollision();
36  SoundElectricShock();
37  }
38  else
39  {
40  // TO DO:
41  // -Cause bleeding?
42  // -Do some damage!
43 
44  player.MessageImportant( "*SCRATCH*" );
45 
46  // Play sound
47  SoundCollision();
48  }
49  }
50  else
51  {
52  // When an AI Agent touches the barbed wire
53  if ( obj.IsInherited(ManBase) )
54  {
55  ManBase AI_unit = ManBase.Cast( obj );
56  AI_unit.SetHealth("", "", 0);
57  }
58  }
59  }
60  }
61  }
62 
63  // Sets parent object for this trigger
64  void SetParentObject( ItemBase wire )
65  {
66  if ( g_Game.IsServer() )
67  {
68  m_ParentBarbedWire = wire;
69  }
70  }
71 
72  // Plays an electric shock sound
73  void SoundElectricShock()
74  {
75  int random_index = Math.RandomInt(0, SOUNDS_SHOCK_COUNT);
76  string sound_type = m_SoundsShock[random_index];
77  PlaySound(sound_type, 50);
78  }
79 
80  // Plays a collision sound
81  void SoundCollision()
82  {
83  int random_index = Math.RandomInt(0, SOUNDS_COLLISION_COUNT);
84  string sound_type = m_SoundsCollision[random_index];
85  PlaySound(sound_type, 50);
86  }
87 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
BarbedWireTrigger
DEPRECATED UNUSED prototype for damage by BarbedWire, do not use as example.
Definition: barbedwiretrigger.c:2
PlayerBase
Definition: playerbaseclient.c:1
Trigger
Scripted Trigger.
Definition: hologram.c:1573
ManBase
Definition: playerbase.c:1
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
Object
Definition: objecttyped.c:1
PlaySound
void PlaySound()
Definition: hungersoundhandler.c:38
Math
Definition: enmath.c:6