Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
injuryhandler.c
Go to the documentation of this file.
1
class
InjuryHandlerThresholds
2
{
3
const
float
WORN
= 0.5;
4
const
float
DAMAGED
= 0.3;
5
const
float
BADLY_DAMAGED
= 0.2;
6
const
float
RUINED
= 0.1;
7
};
8
9
class
InjuryAnimValues
10
{
11
const
float
LVL0
= 0;
12
const
float
LVL1
= 0.3;
13
const
float
LVL2
= 0.6;
14
const
float
LVL3
= 0.8;
15
const
float
LVL4
= 1;
16
};
17
18
enum
eInjuryHandlerLevels
19
{
20
PRISTINE
,
21
WORN
,
22
DAMAGED
,
23
BADLY_DAMAGED
,
24
RUINED
,
25
}
26
27
enum
eInjuryOverrides
28
{
30
NONE
= 0,
31
MORPHINE
= 1,
32
PAIN_KILLERS_LVL0
= 2,
33
PAIN_KILLERS_LVL1
= 4,
34
BROKEN_LEGS
= 8,
//New
35
BROKEN_LEGS_SPLINT
= 16,
//New
36
PRONE_ANIM_OVERRIDE
= 32,
//Prevent non pristine animation when prone
37
}
38
39
class
InjuryAnimationHandler
40
{
41
42
const
float
VALUE_CHECK_INTERVAL
= 5;
43
const
float
SENSITIVTY_PERCENTAGE
= 1;
//how much the value needs to change up/down from previous update to trigger a new update(in percent)
44
45
ref
ScriptInvoker
m_ChangedStateInvoker
=
new
ScriptInvoker
();
46
47
float
m_TimeSinceLastTick
=
VALUE_CHECK_INTERVAL
+ 1;
48
float
m_LastUpdate
;
49
eInjuryHandlerLevels
m_LastHealthUpdate
;
50
float
m_HealthMaxValue
;
51
52
53
private
PlayerBase
m_Player
;
54
private
bool
m_AnimationChange
=
false
;
55
private
bool
m_InjuryAnimEnabled
=
false
;
56
private
float
m_InjuryAnimDamageValue
= 0;
57
int
m_ForceInjuryAnimMask
;
58
59
void
InjuryAnimationHandler
(
PlayerBase
player)
60
{
61
m_Player
= player;
62
m_HealthMaxValue
=
m_Player
.GetMaxHealth(
""
,
"Health"
);
63
}
64
65
bool
IsInjuryAnimEnabled
()
66
{
67
return
m_InjuryAnimEnabled
;
68
}
69
70
float
GetInjuryAnimValue
()
71
{
72
return
m_InjuryAnimDamageValue
;
73
}
74
75
ScriptInvoker
GetInvoker
()
76
{
77
return
m_ChangedStateInvoker
;
78
}
79
80
void
Update
(
float
deltaT)
81
{
82
if
(
m_AnimationChange
)
83
{
84
m_Player
.GetCommandModifier_Additives().SetInjured(
m_InjuryAnimDamageValue
,
m_InjuryAnimEnabled
);
85
m_AnimationChange
=
false
;
86
}
87
88
if
(
g_Game
.IsClient() )
89
return
;
90
91
m_TimeSinceLastTick
+= deltaT;
92
93
if
(
m_TimeSinceLastTick
>
VALUE_CHECK_INTERVAL
)
94
{
95
CheckValue
();
96
m_TimeSinceLastTick
= 0;
97
}
98
}
99
100
eInjuryHandlerLevels
GetOverrideLevel
(
eInjuryHandlerLevels
unchanged_level)
101
{
102
eInjuryHandlerLevels
override_level = unchanged_level;
103
104
//Whatever the case, prone will always use PRISTINE anim level as alternative anim level(s) are not interesting gameplaywise
105
if
(
m_ForceInjuryAnimMask
& eInjuryOverrides.PRONE_ANIM_OVERRIDE && override_level >
eInjuryHandlerLevels
.PRISTINE )
106
{
107
override_level =
eInjuryHandlerLevels
.PRISTINE;
108
return
override_level;
109
}
110
111
if
(
m_ForceInjuryAnimMask
& eInjuryOverrides.MORPHINE && override_level >
eInjuryHandlerLevels
.PRISTINE )
112
{
113
override_level =
eInjuryHandlerLevels
.PRISTINE;
114
}
115
116
if
(
m_ForceInjuryAnimMask
& eInjuryOverrides.PAIN_KILLERS_LVL1 && override_level >
eInjuryHandlerLevels
.WORN )
117
{
118
override_level =
eInjuryHandlerLevels
.WORN;
119
}
120
121
if
(
m_ForceInjuryAnimMask
& eInjuryOverrides.PAIN_KILLERS_LVL0 && override_level >
eInjuryHandlerLevels
.DAMAGED )
122
{
123
override_level =
eInjuryHandlerLevels
.DAMAGED;
124
}
125
126
if
(
m_ForceInjuryAnimMask
&& override_level >
eInjuryHandlerLevels
.DAMAGED )
127
{
128
override_level =
eInjuryHandlerLevels
.RUINED;
129
}
130
131
//Broken leg overrides
132
if
(
m_ForceInjuryAnimMask
& eInjuryOverrides.BROKEN_LEGS_SPLINT && override_level <
eInjuryHandlerLevels
.DAMAGED )
133
{
134
override_level =
eInjuryHandlerLevels
.DAMAGED;
135
}
136
137
if
(
m_ForceInjuryAnimMask
& eInjuryOverrides.BROKEN_LEGS && override_level <
eInjuryHandlerLevels
.RUINED )
138
{
139
//Average leg health used to determine which animation to use
140
float
avgLegHealth =
m_Player
.GetHealth(
"RightLeg"
,
""
) +
m_Player
.GetHealth(
"LeftLeg"
,
""
) +
m_Player
.GetHealth(
"RightFoot"
,
""
) +
m_Player
.GetHealth(
"LeftFoot"
,
""
);
141
avgLegHealth *= 0.25;
//divide by 4 to make the average leg health;
142
if
(avgLegHealth <=
PlayerConstants
.
BROKEN_LEGS_LOW_HEALTH_THRESHOLD
)
143
override_level =
eInjuryHandlerLevels
.RUINED;
144
else
if
(avgLegHealth >=
PlayerConstants
.
BROKEN_LEGS_HIGH_HEALTH_THRESHOLD
)
145
override_level =
eInjuryHandlerLevels
.WORN;
146
else
147
override_level =
eInjuryHandlerLevels
.DAMAGED;
148
}
149
150
return
override_level;
151
152
}
153
154
void
CheckValue
(
bool
forceUpdate =
false
)
155
{
156
float
health_current_normalized =
m_Player
.GetHealth(
""
,
"Health"
) /
m_HealthMaxValue
;
157
eInjuryHandlerLevels
injury_level =
GetInjuryLevel
(health_current_normalized);
158
159
if
(
m_ForceInjuryAnimMask
)
160
{
161
injury_level =
GetOverrideLevel
(injury_level);
162
}
163
164
if
(
m_LastHealthUpdate
!= injury_level || forceUpdate )
165
{
166
SendValue
(injury_level);
167
m_ChangedStateInvoker
.Invoke(injury_level);
168
m_LastHealthUpdate
= injury_level;
169
Synchronize
(injury_level);
170
}
171
}
172
173
void
Synchronize
(
eInjuryHandlerLevels
level)
174
{
175
m_Player
.m_HealthLevel = level;
176
//Print("m_Player.m_HealthLevel:" + m_Player.m_HealthLevel);
177
m_Player
.SetSynchDirty();
178
}
179
180
void
SendValue
(
eInjuryHandlerLevels
level)
181
{
182
DayZPlayerSyncJunctures
.
SendInjury
(
m_Player
,
true
, level);
183
}
184
185
void
SetInjuryCommandParams
(
bool
enable,
eInjuryHandlerLevels
level)
186
{
187
m_AnimationChange
=
true
;
188
m_InjuryAnimEnabled
= enable;
189
m_InjuryAnimDamageValue
=
GetInjuryValue
(level);
190
}
191
192
eInjuryHandlerLevels
GetInjuryLevel
(
float
health)
193
{
194
if
( health <
InjuryHandlerThresholds
.
RUINED
)
195
{
196
return
eInjuryHandlerLevels
.RUINED;
197
}
198
199
if
( health <
InjuryHandlerThresholds
.
BADLY_DAMAGED
)
200
{
201
return
eInjuryHandlerLevels
.BADLY_DAMAGED;
202
}
203
204
if
( health <
InjuryHandlerThresholds
.
DAMAGED
)
205
{
206
return
eInjuryHandlerLevels
.DAMAGED;
207
}
208
209
if
( health <
InjuryHandlerThresholds
.
WORN
)
210
{
211
return
eInjuryHandlerLevels
.WORN;
212
}
213
214
return
eInjuryHandlerLevels
.PRISTINE;
215
}
216
217
218
float
GetInjuryValue
(
eInjuryHandlerLevels
level)
219
{
220
switch
( level )
221
{
222
case
eInjuryHandlerLevels
.RUINED:
223
{
224
return
InjuryAnimValues
.
LVL4
;
225
}
226
case
eInjuryHandlerLevels
.BADLY_DAMAGED:
227
{
228
return
InjuryAnimValues
.
LVL3
;
229
}
230
case
eInjuryHandlerLevels
.DAMAGED:
231
{
232
return
InjuryAnimValues
.
LVL2
;
233
}
234
case
eInjuryHandlerLevels
.WORN:
235
{
236
return
InjuryAnimValues
.
LVL1
;
237
}
238
case
eInjuryHandlerLevels
.PRISTINE:
239
{
240
return
InjuryAnimValues
.
LVL0
;
241
}
242
default
:
243
Error
(
"Undefined Injury level"
);
244
}
245
return
0;
246
}
247
}
m_Player
map m_Player
DayZPlayerSyncJunctures
Definition
dayzplayersyncjunctures.c:5
DayZPlayerSyncJunctures::SendInjury
static void SendInjury(DayZPlayer pPlayer, bool pEnable, eInjuryHandlerLevels level)
Injury.
Definition
dayzplayersyncjunctures.c:144
InjuryAnimValues
Definition
injuryhandler.c:10
InjuryAnimValues::LVL4
const float LVL4
Definition
injuryhandler.c:15
InjuryAnimValues::LVL2
const float LVL2
Definition
injuryhandler.c:13
InjuryAnimValues::LVL3
const float LVL3
Definition
injuryhandler.c:14
InjuryAnimValues::LVL1
const float LVL1
Definition
injuryhandler.c:12
InjuryAnimValues::LVL0
const float LVL0
Definition
injuryhandler.c:11
InjuryHandlerThresholds
Definition
injuryhandler.c:2
InjuryHandlerThresholds::WORN
const float WORN
Definition
injuryhandler.c:3
InjuryHandlerThresholds::RUINED
const float RUINED
Definition
injuryhandler.c:6
InjuryHandlerThresholds::DAMAGED
const float DAMAGED
Definition
injuryhandler.c:4
InjuryHandlerThresholds::BADLY_DAMAGED
const float BADLY_DAMAGED
Definition
injuryhandler.c:5
PlayerBase
Definition
playerbaseclient.c:2
PlayerConstants
Definition
playerconstants.c:2
PlayerConstants::BROKEN_LEGS_HIGH_HEALTH_THRESHOLD
static const float BROKEN_LEGS_HIGH_HEALTH_THRESHOLD
Definition
playerconstants.c:230
PlayerConstants::BROKEN_LEGS_LOW_HEALTH_THRESHOLD
static const float BROKEN_LEGS_LOW_HEALTH_THRESHOLD
Definition
playerconstants.c:229
ScriptInvoker
ScriptInvoker Class provide list of callbacks usage:
Definition
tools.c:116
Synchronize
void Synchronize()
Definition
combinationlock.c:151
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
BROKEN_LEGS
@ BROKEN_LEGS
Definition
ebrokenlegs.c:4
BROKEN_LEGS_SPLINT
@ BROKEN_LEGS_SPLINT
Definition
ebrokenlegs.c:5
Error
void Error(string err)
Messagebox with error message.
Definition
endebug.c:90
NONE
@ NONE
body is not in simulation, nor in collision world
Definition
simulationstate.c:15
Update
proto native volatile void Update()
Definition
playersoundmanager.c:125
MORPHINE
enum eInjuryHandlerLevels MORPHINE
m_ChangedStateInvoker
ref ScriptInvoker m_ChangedStateInvoker
Definition
injuryhandler.c:45
m_LastUpdate
float m_LastUpdate
Definition
injuryhandler.c:48
GetInvoker
ScriptInvoker GetInvoker()
Definition
injuryhandler.c:75
GetInjuryValue
float GetInjuryValue(eInjuryHandlerLevels level)
Definition
injuryhandler.c:218
m_InjuryAnimDamageValue
float m_InjuryAnimDamageValue
Definition
injuryhandler.c:56
GetOverrideLevel
eInjuryHandlerLevels GetOverrideLevel(eInjuryHandlerLevels unchanged_level)
Definition
injuryhandler.c:100
m_LastHealthUpdate
eInjuryHandlerLevels m_LastHealthUpdate
Definition
injuryhandler.c:49
m_HealthMaxValue
float m_HealthMaxValue
Definition
injuryhandler.c:50
SENSITIVTY_PERCENTAGE
const float SENSITIVTY_PERCENTAGE
Definition
injuryhandler.c:43
CheckValue
void CheckValue(bool forceUpdate=false)
Definition
injuryhandler.c:154
PAIN_KILLERS_LVL0
enum eInjuryHandlerLevels PAIN_KILLERS_LVL0
m_InjuryAnimEnabled
bool m_InjuryAnimEnabled
Definition
injuryhandler.c:55
SetInjuryCommandParams
void SetInjuryCommandParams(bool enable, eInjuryHandlerLevels level)
Definition
injuryhandler.c:185
GetInjuryAnimValue
float GetInjuryAnimValue()
Definition
injuryhandler.c:70
VALUE_CHECK_INTERVAL
enum eInjuryHandlerLevels VALUE_CHECK_INTERVAL
PRONE_ANIM_OVERRIDE
enum eInjuryHandlerLevels PRONE_ANIM_OVERRIDE
eInjuryHandlerLevels
eInjuryHandlerLevels
Definition
injuryhandler.c:19
RUINED
@ RUINED
Definition
injuryhandler.c:24
BADLY_DAMAGED
@ BADLY_DAMAGED
Definition
injuryhandler.c:23
DAMAGED
@ DAMAGED
Definition
injuryhandler.c:22
PRISTINE
@ PRISTINE
Definition
injuryhandler.c:20
WORN
@ WORN
Definition
injuryhandler.c:21
InjuryAnimationHandler
void InjuryAnimationHandler(PlayerBase player)
Definition
injuryhandler.c:59
m_TimeSinceLastTick
float m_TimeSinceLastTick
Definition
injuryhandler.c:47
IsInjuryAnimEnabled
bool IsInjuryAnimEnabled()
Definition
injuryhandler.c:65
PAIN_KILLERS_LVL1
enum eInjuryHandlerLevels PAIN_KILLERS_LVL1
m_ForceInjuryAnimMask
int m_ForceInjuryAnimMask
Definition
injuryhandler.c:57
m_AnimationChange
bool m_AnimationChange
owner
Definition
injuryhandler.c:54
GetInjuryLevel
eInjuryHandlerLevels GetInjuryLevel(float health)
Definition
injuryhandler.c:192
SendValue
void SendValue(eInjuryHandlerLevels level)
Definition
injuryhandler.c:180
Games
Dayz
scripts
4_world
classes
injuryhandler.c
Generated by
1.17.0