DayZ 1.24
Loading...
Searching...
No Matches
ChemLight.c
Go to the documentation of this file.
2{
5
6 ChemlightLight m_Light;
7
8 private int m_Efficiency0To10; // Synchronized variable
9 static private float m_EfficiencyDecayStart = 0.05; // At this % of maximum energy the output of the light starts to weaken.
10
13 {
14 return m_Efficiency0To10 / 10;
15 }
16
19 {
21 }
22
23 override void OnEnergyConsumed()
24 {
25 super.OnEnergyConsumed();
26
27 if (GetGame().IsServer())
28 {
29 float energy_coef = GetCompEM().GetEnergy0To1();
30
32 {
34 SetSynchDirty();
35 }
36 }
37 }
38
39 override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
40 {
41 super.EEHealthLevelChanged(oldLevel, newLevel, zone);
42
43 SetObjectMaterial(0, GetMaterialForDamageState(GetCompEM().IsWorking(), newLevel));
44 }
45
47 {
48 //materials
49 array<string> config_materials = GetHiddenSelectionsMaterials();
50
51 if (config_materials.Count() == 2)
52 {
55 }
56 else
57 {
58 string error = "Error! Item " + GetType() + " must have 2 entries in config array hiddenSelectionsMaterials[]. One for the default state, the other one for the glowing state. Currently it has " + config_materials.Count() + ".";
59 Error(error);
60 }
61
63 RegisterNetSyncVariableInt("m_Efficiency0To10");
64 }
65
67 {
68 SetObjectMaterial(0, GetMaterialForDamageState(true)); // must be server side!
69
70 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // client side
71 {
72 m_Light = ChemlightLight.Cast(ScriptedLightBase.CreateLight(ChemlightLight, "0 0 0"));
73 m_Light.AttachOnMemoryPoint(this, "light");
74
75 string type = GetType();
76
77 switch (type)
78 {
79 case "Chemlight_White":
80 m_Light.SetColorToWhite();
81 break;
82 case "Chemlight_Red":
83 m_Light.SetColorToRed();
84 break;
85 case "Chemlight_Green":
86 m_Light.SetColorToGreen();
87 break;
88 case "Chemlight_Blue":
89 m_Light.SetColorToBlue();
90 break;
91 case "Chemlight_Yellow":
92 m_Light.SetColorToYellow();
93 break;
94
95 default: { m_Light.SetColorToWhite(); };
96 }
97 }
98 }
99
100 override void OnWorkStart()
101 {
102
103 }
104
105 // Inventory manipulation
106 override void OnInventoryExit(Man player)
107 {
108 super.OnInventoryExit(player);
109
110 StandUp();
111 }
112
113 void StandUp()
114 {
115 if (GetGame().IsServer() && GetCompEM().IsWorking())
116 {
117 vector ori_rotate = "0 0 0";
118 SetOrientation(ori_rotate);
119 }
120 }
121
122 override void OnWorkStop()
123 {
124 SetObjectMaterial(0, GetMaterialForDamageState(false));
125
126 if (m_Light)
127 m_Light.FadeOut();
128
129 if (GetGame().IsServer())
130 {
131 //Safeguard if item is turned off by another event than running out of energy
132 if (GetCompEM().GetEnergy() > 0)
133 return;
134
135 SetHealth(0);
136 }
137 }
138
139 override void OnWork(float consumed_energy)
140 {
141 if (!m_Light)
142 CreateLight();
143
144 // Handle fade out of chemlight
145 if (m_Light)
146 {
148
149 if (efficiency < 1)
150 m_Light.SetIntensity(efficiency, GetCompEM().GetUpdateInterval());
151 }
152 }
153
154 override void SetActions()
155 {
156 super.SetActions();
157
159 }
160
162 {
164 int suffixIndex;
165 string base;
166
167 if (healthLevel == -1)
168 currentHealthLevel = GetHealthLevel();
169 else
171
172 if (glowing)
174 else
176
177 suffixIndex = base.IndexOf(".rvmat");
178 if (suffixIndex == -1)
179 {
180 Error("Error - no valid rvmat found for chemlight");
181 return "";
182 }
183 base = base.Substring(0, suffixIndex);
184
186 base = base + "_damage";
188 base = base + "_destruct";
189
190 return base + ".rvmat";
191 }
192};
193
eBleedingSourceType GetType()
void AddAction(typename actionName)
float GetEnergy()
Definition ItemBase.c:8140
void Chemlight_ColorBase()
Definition ChemLight.c:46
override void OnWork(float consumed_energy)
Definition ChemLight.c:139
override void OnWorkStop()
Definition ChemLight.c:122
string GetMaterialForDamageState(bool glowing, int healthLevel=-1)
Definition ChemLight.c:161
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition ChemLight.c:39
float m_EfficiencyDecayStart
Definition ChemLight.c:9
float GetEfficiencyDecayStart()
Returns efficiency. The value is synchronized from server to all clients and is accurate down to 0....
Definition ChemLight.c:18
override void SetActions()
Definition ChemLight.c:154
override void OnInventoryExit(Man player)
Definition ChemLight.c:106
override void OnEnergyConsumed()
Definition ChemLight.c:23
string m_DefaultMaterial
Definition ChemLight.c:3
ChemlightLight m_Light
Definition ChemLight.c:6
string m_GlowMaterial
Definition ChemLight.c:4
float GetEfficiency0To1()
Returns efficiency. The value is synchronized from server to all clients and is accurate down to 0....
Definition ChemLight.c:12
override void OnWorkStart()
Definition ChemLight.c:100
Definition EnMath.c:7
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
const int STATE_RUINED
Definition constants.c:757
const int STATE_DAMAGED
Definition constants.c:759
const int STATE_BADLY_DAMAGED
Definition constants.c:758
static proto float Round(float f)
Returns mathematical round of value.