DayZ 1.24
Loading...
Searching...
No Matches
TransferValues.c
Go to the documentation of this file.
1class TransferValues extends Managed
2{
3 const int TYPE_HEALTH = 1;
4 const int TYPE_BLOOD = 2;
5
6 const float VALUE_CHECK_INTERVAL = 5;
7 const float SENSITIVTY_PERCENTAGE = 1;//how much the value needs to change up/down from previous update to trigger a new update(in percent)
8
9 const int BLOOD_THRESHOLD_LOW = 3000;
12
15
16 //float m_CumulatedHealthDiff;
17 //float m_CumulatedBloodDiff;
18
21
24
25 protected bool m_InitialSyncSent;
26
28 {
30 m_InitialSyncSent = false;
31 Init();
32 }
33
34 void Init()
35 {
37 m_LastBloodUpdate = 0;
38 m_HealthMaxValue = m_Player.GetMaxHealth("", "Health");
39 m_BloodMaxValue = m_Player.GetMaxHealth("", "Blood");
40 m_BloodClient = 0;
41 m_HealthClient = 0;
42 }
43
45 {
46#ifdef DIAG_DEVELOPER
47#ifndef SERVER
48 ShowDebugValues(DiagMenu.GetBool(DiagMenuIDs.TRANSFER_VALUES_SHOW));
49#endif
50#endif
51
52 if (GetGame().IsClient()) return;
53
55
56 if (!m_InitialSyncSent)
59 {
60 /*
61 Print(m_TimeSinceLastTick.ToString());
62 Print(VALUE_CHECK_INTERVAL.ToString());
63 Print("--------------");
64 */
67
68 // send sync junctures if necessary
69 // TODO: !!!! event is sent too often, please fix it
70 /*
71 float damage = 1 - m_Player.GetHealth("", "") / 100;
72 DayZPlayerSyncJunctures.SendInjury(m_Player, true, damage);
73 */
74 }
75 }
76
78 {
80 CheckBlood();
81 }
82
83 float GetBlood()
84 {
85 return m_BloodClient;
86
87 }
88
89 float GetHealth()
90 {
91 return m_HealthClient;
92 }
93
107
108 /*void CheckBlood()
109 {
110 float blood_current = m_Player.GetHealth("","Blood");
111 //float blood_normalized = blood_current / m_BloodMaxValue;
112 float blood_normalized = Math.InverseLerp(BLOOD_THRESHOLD_LOW, m_BloodMaxValue, blood_current);
113 blood_normalized = Math.Clamp(blood_normalized,0,1);
114 float difference_normalized = blood_normalized - m_LastBloodUpdate;
115 float diff_abs = Math.AbsFloat(difference_normalized);
116 m_CumulatedBloodDiff += diff_abs;
117
118 //Print("DbgBlood | CheckBlood | m_CumulatedBloodDiff: " + m_CumulatedBloodDiff);
119 if( m_CumulatedBloodDiff > ( SENSITIVTY_PERCENTAGE /100 ) )
120 {
121 SendValue(TYPE_BLOOD, blood_normalized);
122 m_LastBloodUpdate = blood_normalized;
123 //Print("DbgBlood | CheckBlood | Sending blood: " + blood_normalized);
124 m_CumulatedBloodDiff = 0;
125 }
126 else
127 {
128 //Print("DbgBlood | CheckBlood | unsent values blood: " + blood_normalized);
129 }
130 }*/
131
133 {
134 float blood_current = m_Player.GetHealth("", "Blood");
135 //float blood_normalized = blood_current / m_BloodMaxValue;
136 float blood_normalized = Math.InverseLerp(BLOOD_THRESHOLD_LOW, m_BloodMaxValue, blood_current);
140
141 if (diff_abs > (SENSITIVTY_PERCENTAGE / 100))
142 {
143 SendValue(TYPE_BLOOD, blood_normalized);
144 m_LastBloodUpdate = blood_normalized;
145 }
146 }
147
150 {
151 m_InitialSyncSent = true;
152
153 //HP
154 float health_current = m_Player.GetHealth("", "Health");
156 SendValue(TYPE_HEALTH, health_normalized);
158
159 //Blood
160 float blood_current = m_Player.GetHealth("", "Blood");
161 float blood_normalized = Math.InverseLerp(BLOOD_THRESHOLD_LOW, m_BloodMaxValue, blood_current);
163 //Print("DbgBlood | SendInitValues | blood_normalized: " + blood_normalized);
164 SendValue(TYPE_BLOOD, blood_normalized);
165 m_LastBloodUpdate = blood_normalized;
166 }
167
168 void SendValue(int value_type, float value)
169 {
172
173 GetGame().RPCSingleParam(m_Player, ERPCs.RPC_DAMAGE_VALUE_SYNC, CachedObjectsParams.PARAM2_INT_FLOAT, true, m_Player.GetIdentity());
174 }
175
177 {
178 if (value_type == TYPE_HEALTH)
179 m_HealthClient = value;
180 else if (value_type == TYPE_BLOOD)
181 m_BloodClient = value;
182 }
183
193
194 void ShowDebugValues(bool show)
195 {
196#ifdef DIAG_DEVELOPER
197 if (show)
198 {
200 DbgUI.Begin("Values", 50, 50);
201
202 DbgUI.Text("Blood: " + m_BloodClient.ToString());
203 DbgUI.Text("Health: " + m_HealthClient.ToString());
204
205 DbgUI.End();
207 }
208 else
209 {
211 DbgUI.Begin("Values", 50, 50);
212 DbgUI.End();
214 }
215#endif
216 }
217}
DiagMenuIDs
Definition EDiagMenuIDs.c:2
ERPCs
Definition ERPCs.c:2
DayZPlayer m_Player
Definition Hand_Events.c:42
eInjuryHandlerLevels m_LastHealthUpdate
float m_HealthMaxValue
const float SENSITIVTY_PERCENTAGE
enum eInjuryHandlerLevels VALUE_CHECK_INTERVAL
float m_TimeSinceLastTick
static ref Param2< int, float > PARAM2_INT_FLOAT
Definition DbgUI.c:60
TODO doc.
Definition EnScript.c:118
void OnRPC(ParamsReadContext ctx)
float m_BloodMaxValue
static void Init()
void ShowDebugValues(bool show)
float GetBlood()
float m_LastBloodUpdate
float m_BloodClient
void ReceiveValue(int value_type, float value)
void CheckHealth()
void Init()
float GetHealth()
void CheckValues()
void SendValue(int value_type, float value)
PlayerBase m_Player
void OnScheduledTick(float deltatime)
float m_HealthClient
void CheckBlood()
float m_HealthMaxValue
void SendInitValues()
Sends values on object creation.
bool m_InitialSyncSent
float m_LastHealthUpdate
void TransferValues(PlayerBase player)
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto string ToString()
proto native CGame GetGame()
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
static proto void BeginCleanupScope()
static proto native void EndCleanupScope()
static proto bool GetBool(int id, bool reverse=false)
Get value as bool from the given script id.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
static proto float AbsFloat(float f)
Returns absolute value.