Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
defibrillator.c
Go to the documentation of this file.
1class Defibrillator extends ItemBase
2{
3 static const string CHARGING_SOUND = "defibrillator_charge_SoundSet";
4 static const string CHARGED_AND_READY_SOUND = "defibrillator_ready_SoundSet";
5 static const string SHOCK_SOUND = "defibrillator_shock_SoundSet";
6
7 bool m_IsCharged = false;
8
9 static float m_ChargeTime = 5;
10 static float m_EnergyNeededToCharge = 20;
11
12 ref Timer m_ChargingTimer;
13 EffectSound m_ChargedAlarm;
14 EffectSound m_ChargingSound;
15
16 void Defibrillator()
17 {
18 // Read all config parameters
19 //m_ChargeTime = GetTimeNeededToCharge();
20 m_EnergyNeededToCharge = GetEnergyNeededToCharge();
21 }
22
23 void ~Defibrillator()
24 {
25 SEffectManager.DestroyEffect(m_ChargedAlarm);
26 SEffectManager.DestroyEffect(m_ChargingSound);
27 }
28
29 float GetTimeNeededToCharge()
30 {
31 string cfg_path = "CfgVehicles " + GetType() + " ";
32 return GetGame().ConfigGetFloat (cfg_path + "defibChargeTime");
33 }
34
35 float GetEnergyNeededToCharge()
36 {
37 string cfg_path = "CfgVehicles " + GetType() + " ";
38 return GetGame().ConfigGetFloat (cfg_path + "defibEnergyNeededPerCharge");
39 }
40
41 override void OnWorkStart()
42 {
43 if ( !GetGame().IsDedicatedServer() )
44 m_ChargingSound = SEffectManager.PlaySoundOnObject(CHARGING_SOUND, this, 0, 0.15);
45
46 float energy_needed = m_EnergyNeededToCharge / m_ChargeTime;
47 GetCompEM().SetEnergyUsage(energy_needed);
48
49 if (!m_ChargingTimer)
50 m_ChargingTimer = new Timer( CALL_CATEGORY_GAMEPLAY );
51
52 if ( !m_ChargingTimer.IsRunning() )
53 {
54 m_ChargingTimer.Run(m_ChargeTime, this, "OnIsCharged", NULL, false);
55 }
56 }
57
58 override void OnWorkStop()
59 {
60 GetCompEM().SwitchOff();
61 GetCompEM().ResetEnergyUsage();
62 StopChargingTimer();
63 StopChargedAlarm();
64 StopChargingSound();
65
66 m_IsCharged = false;
67 }
68
69 void OnIsCharged()
70 {
71 if ( GetCompEM().IsWorking() )
72 {
73 if (!GetGame().IsMultiplayer() || GetGame().IsClient())
74 {
75 //m_ChargedAlarm = PlaySoundLoop(CHARGED_AND_READY_SOUND, 40);
76 m_ChargedAlarm = SEffectManager.PlaySoundOnObject(CHARGED_AND_READY_SOUND, this);
77 m_ChargingSound.SoundStop();
78 }
79 GetCompEM().ResetEnergyUsage();
80 m_IsCharged = true;
81 }
82 }
83
84 void StopChargedAlarm()
85 {
86 if (m_ChargedAlarm)
87 {
88 //GetGame().ObjectDelete(m_ChargedAlarm);
89 m_ChargedAlarm.SoundStop();
90 m_ChargedAlarm = NULL;
91 }
92 }
93
94 void StopChargingSound()
95 {
96 if(m_ChargingSound)
97 {
98 m_ChargingSound.SoundStop();
99 }
100 }
101
102 void StopChargingTimer()
103 {
104 if (m_ChargingTimer)
105 {
106 m_ChargingTimer.Stop();
107 m_ChargingTimer = NULL;
108 }
109 }
110
111 bool IsCharged()
112 {
113 return m_IsCharged;
114 }
115
116 void DischargeServer(PlayerBase victim)
117 {
118 /*
119 bool has_heart_attack = victim.m_ModifiersManager.IsModifierActive(eModifiers.MDF_HEART_ATTACK);
120
121 if ( has_heart_attack )
122 {
123 victim.m_ModifiersManager.DeactivateModifier ( eModifiers.MDF_HEART_ATTACK );
124 }
125 else
126 {
127 victim.m_ModifiersManager.ActivateModifier ( eModifiers.MDF_HEART_ATTACK );
128 }
129 */
130 /*
131 if (!GetGame().IsMultiplayer() || GetGame().IsClient())
132 {
133 SEffectManager.PlaySoundOnObject(SHOCK_SOUND, this);
134 }*/
135
136 victim.SetPulseType(!victim.GetPulseType());
137 victim.SetHealth("","Shock",0);
138
139 GetCompEM().SwitchOff();
140 }
141
142 void DischargeClient(PlayerBase victim)
143 {
144 SEffectManager.PlaySoundOnObject(SHOCK_SOUND, this);
145 }
146
147 override void SetActions()
148 {
149 super.SetActions();
150
155 }
156}
eBleedingSourceType GetType()
void AddAction(typename actionName)
void SetActions()
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
void SoundStop()
Stops sound.
override void OnWorkStart()
Definition barbedwire.c:164
override void OnWorkStop()
Definition barbedwire.c:177
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySoundOnObject(string sound_set, Object parent_object, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
proto native CGame GetGame()
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10