DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Battery9V.c
Go to the documentation of this file.
1class Battery9V extends ItemBase
2{
3 private int m_Efficiency0To10; // Synchronized variable
4 static private float m_EfficiencyDecayStart = 0.1; // At this % of maximum energy the output of the battery starts to weaken.
5
6 void Battery9V()
7 {
8 m_Efficiency0To10 = 10;
9 RegisterNetSyncVariableInt("m_Efficiency0To10");
10 }
11
12 //Update Battery energy level before it overrides quantity
13 override void SetCEBasedQuantity()
14 {
15 super.SetCEBasedQuantity();
16 if ( GetCompEM() )
17 GetCompEM().SetEnergy( GetCompEM().GetEnergyMax() * ( GetQuantity() / GetQuantityMax() ) );
18 }
19
22 {
23 return m_Efficiency0To10 / 10;
24 }
25
28 {
30 }
31
32
33 override void OnEnergyConsumed()
34 {
35 super.OnEnergyConsumed();
36
37 if ( GetGame().IsServer() )
38 {
39 float energy_coef = GetCompEM().GetEnergy0To1();
40
41 if ( energy_coef < m_EfficiencyDecayStart && m_EfficiencyDecayStart > 0 )
42 {
43 m_Efficiency0To10 = Math.Round( (energy_coef / m_EfficiencyDecayStart) * 10 );
44 SetSynchDirty();
45 }
46 }
47 }
48
49 // Not needed right now, but it will be useful if we add rechargable batteries.
50 override void OnEnergyAdded()
51 {
52 super.OnEnergyAdded();
53
54 if ( GetGame().IsServer() )
55 {
56 float energy_coef = GetCompEM().GetEnergy0To1();
57
58 if ( energy_coef < m_EfficiencyDecayStart && m_EfficiencyDecayStart > 0)
59 {
60 m_Efficiency0To10 = Math.Round( (energy_coef / m_EfficiencyDecayStart) * 10 );
61 SetSynchDirty();
62 }
63 else
64 {
65 m_Efficiency0To10 = 10;
66 SetSynchDirty();
67 }
68 }
69 }
70
71 override void SetActions()
72 {
73 super.SetActions();
74
76 }
77}
void AddAction(typename actionName)
override float GetQuantity()
Definition ItemBase.c:7967
override int GetQuantityMax()
Definition ItemBase.c:7907
float GetEfficiencyDecayStart()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
Definition Battery9V.c:27
override void OnEnergyAdded()
Definition Battery9V.c:50
static private float m_EfficiencyDecayStart
Definition Battery9V.c:4
override void SetCEBasedQuantity()
Definition Battery9V.c:13
void Battery9V()
Definition Battery9V.c:6
private int m_Efficiency0To10
Definition Battery9V.c:3
float GetEfficiency0To1()
Returns efficiency of this battery. The value is synchronized from server to all clients and is accur...
Definition Battery9V.c:21
override void SetActions()
Definition Battery9V.c:71
override void OnEnergyConsumed()
Definition Battery9V.c:33
Definition EnMath.c:7
proto native CGame GetGame()
static proto float Round(float f)
Returns mathematical round of value.