Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
chemlight.c
Go to the documentation of this file.
1
class
Chemlight_ColorBase
:
ItemBase
2
{
3
string
m_DefaultMaterial
;
4
string
m_GlowMaterial
;
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
12
float
GetEfficiency0To1
()
13
{
14
return
m_Efficiency0To10
/ 10;
15
}
16
18
float
GetEfficiencyDecayStart
()
19
{
20
return
m_EfficiencyDecayStart
;
21
}
22
23
override
void
OnEnergyConsumed
()
24
{
25
super.OnEnergyConsumed();
26
27
if
(
g_Game
.IsServer() )
28
{
29
float
energy_coef = GetCompEM().GetEnergy0To1();
30
31
if
( energy_coef < m_EfficiencyDecayStart && m_EfficiencyDecayStart > 0 )
32
{
33
m_Efficiency0To10
=
Math
.
Round
( (energy_coef /
m_EfficiencyDecayStart
) * 10 );
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
46
void
Chemlight_ColorBase
()
47
{
48
//materials
49
array<string>
config_materials = GetHiddenSelectionsMaterials();
50
51
if
(config_materials.Count() == 2)
52
{
53
m_DefaultMaterial
= config_materials[0];
54
m_GlowMaterial
= config_materials[1];
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
62
m_Efficiency0To10
= 10;
63
RegisterNetSyncVariableInt(
"m_Efficiency0To10"
);
64
}
65
66
void
CreateLight
()
67
{
68
SetObjectMaterial( 0,
GetMaterialForDamageState
(
true
) );
// must be server side!
69
70
if
( !
g_Game
.IsServer() || !
g_Game
.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
(
g_Game
.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
{
128
m_Light
.FadeOut();
129
}
130
131
if
(
g_Game
.IsServer() )
132
{
133
//Safeguard if item is turned off by another event than running out of energy
134
if
(GetCompEM().
GetEnergy
() > 0)
135
return
;
136
137
SetHealth(0);
138
}
139
}
140
141
override
void
OnWork
(
float
consumed_energy)
142
{
143
if
(!
m_Light
)
144
CreateLight
();
145
146
// Handle fade out of chemlight
147
if
(
m_Light
)
148
{
149
float
efficiency =
GetEfficiency0To1
();
150
151
if
( efficiency < 1 )
152
{
153
m_Light
.SetIntensity( efficiency, GetCompEM().GetUpdateInterval() );
154
}
155
}
156
}
157
158
override
void
SetActions
()
159
{
160
super.SetActions();
161
162
AddAction
(
ActionTurnOnWhileInHands
);
163
}
164
165
string
GetMaterialForDamageState
(
bool
glowing,
int
healthLevel = -1)
166
{
167
int
currentHealthLevel;
168
int
suffixIndex;
169
string
base;
170
171
if
(healthLevel == -1)
172
currentHealthLevel = GetHealthLevel();
173
else
174
currentHealthLevel = healthLevel;
175
176
if
(glowing)
177
base =
m_GlowMaterial
;
178
else
179
base =
m_DefaultMaterial
;
180
181
suffixIndex = base.
IndexOf
(
".rvmat"
);
182
if
(suffixIndex == -1)
183
{
184
Error
(
"Error - no valid rvmat found for chemlight"
);
185
return
""
;
186
}
187
base = base.
Substring
(0,suffixIndex);
188
189
if
(currentHealthLevel ==
GameConstants
.
STATE_BADLY_DAMAGED
|| currentHealthLevel ==
GameConstants
.
STATE_DAMAGED
)
190
{
191
base = base +
"_damage"
;
192
}
193
else
if
(currentHealthLevel ==
GameConstants
.
STATE_RUINED
)
194
{
195
base = base +
"_destruct"
;
196
}
197
198
return
base +
".rvmat"
;
199
}
200
};
201
202
class
Chemlight_White
:
Chemlight_ColorBase
{};
203
class
Chemlight_Red
:
Chemlight_ColorBase
{};
204
class
Chemlight_Green
:
Chemlight_ColorBase
{};
205
class
Chemlight_Blue
:
Chemlight_ColorBase
{};
206
class
Chemlight_Yellow
:
Chemlight_ColorBase
{};
GetType
eBleedingSourceType GetType()
Definition
bleedingsource.c:67
AddAction
void AddAction(typename actionName)
Definition
advancedcommunication.c:220
ActionTurnOnWhileInHands
Definition
actionturnonwhileinhands.c:2
Chemlight_Blue
Definition
chemlight.c:205
Chemlight_ColorBase::m_EfficiencyDecayStart
float m_EfficiencyDecayStart
Definition
chemlight.c:9
Chemlight_ColorBase::m_Light
ChemlightLight m_Light
Definition
chemlight.c:6
Chemlight_ColorBase::GetEfficiencyDecayStart
float GetEfficiencyDecayStart()
Returns efficiency. The value is synchronized from server to all clients and is accurate down to 0....
Definition
chemlight.c:18
Chemlight_ColorBase::OnInventoryExit
override void OnInventoryExit(Man player)
Definition
chemlight.c:106
Chemlight_ColorBase::m_GlowMaterial
string m_GlowMaterial
Definition
chemlight.c:4
Chemlight_ColorBase::Chemlight_ColorBase
void Chemlight_ColorBase()
Definition
chemlight.c:46
Chemlight_ColorBase::StandUp
void StandUp()
Definition
chemlight.c:113
Chemlight_ColorBase::EEHealthLevelChanged
override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
Definition
chemlight.c:39
Chemlight_ColorBase::m_Efficiency0To10
int m_Efficiency0To10
Definition
chemlight.c:8
Chemlight_ColorBase::OnWorkStop
override void OnWorkStop()
Definition
chemlight.c:122
Chemlight_ColorBase::OnWork
override void OnWork(float consumed_energy)
Definition
chemlight.c:141
Chemlight_ColorBase::CreateLight
void CreateLight()
Definition
chemlight.c:66
Chemlight_ColorBase::OnWorkStart
override void OnWorkStart()
Definition
chemlight.c:100
Chemlight_ColorBase::m_DefaultMaterial
string m_DefaultMaterial
Definition
chemlight.c:3
Chemlight_ColorBase::GetMaterialForDamageState
string GetMaterialForDamageState(bool glowing, int healthLevel=-1)
Definition
chemlight.c:165
Chemlight_ColorBase::GetEfficiency0To1
float GetEfficiency0To1()
Returns efficiency. The value is synchronized from server to all clients and is accurate down to 0....
Definition
chemlight.c:12
Chemlight_ColorBase::SetActions
override void SetActions()
Definition
chemlight.c:158
Chemlight_ColorBase::OnEnergyConsumed
override void OnEnergyConsumed()
Definition
chemlight.c:23
Chemlight_Green
Definition
chemlight.c:204
Chemlight_Red
Definition
chemlight.c:203
Chemlight_White
Definition
chemlight.c:202
Chemlight_Yellow
Definition
chemlight.c:206
GameConstants
Definition
constants.c:664
ItemBase
Definition
inventoryitem.c:742
Math
Definition
enmath.c:7
ScriptedLightBase
Definition
pointlightbase.c:2
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
vector
Definition
enconvert.c:119
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
Error
void Error(string err)
Messagebox with error message.
Definition
endebug.c:90
GameConstants::STATE_RUINED
const int STATE_RUINED
Definition
constants.c:851
GameConstants::STATE_BADLY_DAMAGED
const int STATE_BADLY_DAMAGED
Definition
constants.c:852
GameConstants::STATE_DAMAGED
const int STATE_DAMAGED
Definition
constants.c:853
Math::Round
static proto float Round(float f)
Returns mathematical round of value.
string::Substring
proto string Substring(int start, int len)
Substring of 'str' from 'start' position 'len' number of characters.
string::IndexOf
proto native int IndexOf(string sample)
Finds 'sample' in 'str'.
GetEnergy
float GetEnergy()
Definition
itembase.c:8525
Games
Dayz
scripts
4_world
entities
itembase
chemlight.c
Generated by
1.17.0