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