Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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 {
29 m_Player = player;
30 m_InitialSyncSent = false;
31 Init();
32 }
33
34 void Init()
35 {
38 m_HealthMaxValue = m_Player.GetMaxHealth("", "Health");
39 m_BloodMaxValue = m_Player.GetMaxHealth("", "Blood");
40 m_BloodClient = 0;
42 }
43
44 void OnScheduledTick(float deltatime)
45 {
46 #ifdef DIAG_DEVELOPER
47 #ifndef SERVER
48 ShowDebugValues(DiagMenu.GetBool(DiagMenuIDs.TRANSFER_VALUES_SHOW));
49 #endif
50 #endif
51
52 if ( g_Game.IsClient() ) return;
53
54 m_TimeSinceLastTick += deltatime;
55
57 {
59 }
61 {
62 /*
63 Print(m_TimeSinceLastTick.ToString());
64 Print(VALUE_CHECK_INTERVAL.ToString());
65 Print("--------------");
66 */
69
70 // send sync junctures if necessary
71 // TODO: !!!! event is sent too often, please fix it
72 /*
73 float damage = 1 - m_Player.GetHealth("", "") / 100;
74 DayZPlayerSyncJunctures.SendInjury(m_Player, true, damage);
75 */
76 }
77 }
78
80 {
82 CheckBlood();
83 }
84
85 float GetBlood()
86 {
87 return m_BloodClient;
88
89 }
90
91 float GetHealth()
92 {
93 return m_HealthClient;
94 }
95
97 {
98 float health_current = m_Player.GetHealth("","Health");
99 float health_normalized = health_current / m_HealthMaxValue;
100 float difference_normalized = health_normalized - m_LastHealthUpdate;
101 float diff_abs = Math.AbsFloat(difference_normalized);
102
103 if ( diff_abs > ( SENSITIVTY_PERCENTAGE / 100 ) )
104 {
105 SendValue(TYPE_HEALTH, health_normalized);
106 m_LastHealthUpdate = health_normalized;
107 }
108 }
109
111 {
112 float blood_current = m_Player.GetHealth("","Blood");
113 //float blood_normalized = blood_current / m_BloodMaxValue;
114 float blood_normalized = Math.InverseLerp(BLOOD_THRESHOLD_LOW, m_BloodMaxValue, blood_current);
115 blood_normalized = Math.Clamp(blood_normalized,0,1);
116 float difference_normalized = blood_normalized - m_LastBloodUpdate;
117 float diff_abs = Math.AbsFloat(difference_normalized);
118
119 if ( diff_abs > ( SENSITIVTY_PERCENTAGE /100 ) )
120 {
121 SendValue(TYPE_BLOOD, blood_normalized);
122 m_LastBloodUpdate = blood_normalized;
123 }
124 }
125
128 {
129 m_InitialSyncSent = true;
130
131 //HP
132 float health_current = m_Player.GetHealth("","Health");
133 float health_normalized = health_current / m_HealthMaxValue;
134 SendValue(TYPE_HEALTH, health_normalized);
135 m_LastHealthUpdate = health_normalized;
136
137 //Blood
138 float blood_current = m_Player.GetHealth("","Blood");
139 float blood_normalized = Math.InverseLerp(BLOOD_THRESHOLD_LOW, m_BloodMaxValue, blood_current);
140 blood_normalized = Math.Clamp(blood_normalized,0,1);
141 SendValue(TYPE_BLOOD, blood_normalized);
142 m_LastBloodUpdate = blood_normalized;
143 }
144
145 void SendValue(int value_type, float value)
146 {
147 CachedObjectsParams.PARAM2_INT_FLOAT.param1 = value_type;
149
150 g_Game.RPCSingleParam(m_Player, ERPCs.RPC_DAMAGE_VALUE_SYNC, CachedObjectsParams.PARAM2_INT_FLOAT, true, m_Player.GetIdentity());
151 }
152
153 void ReceiveValue(int value_type, float value)
154 {
155 if ( value_type == TYPE_HEALTH )
156 {
157 m_HealthClient = value;
158 }
159 else if ( value_type == TYPE_BLOOD )
160 {
161 m_BloodClient = value;
162 }
163 }
164
166 {
168
169 int value_type = CachedObjectsParams.PARAM2_INT_FLOAT.param1;
170 float value = CachedObjectsParams.PARAM2_INT_FLOAT.param2;
171
172 ReceiveValue(value_type, value);
173 }
174
175 void ShowDebugValues(bool show)
176 {
177 #ifdef DIAG_DEVELOPER
178 if ( show )
179 {
181 DbgUI.Begin("Values", 50, 50);
182
183 DbgUI.Text("Blood: " + m_BloodClient.ToString());
184 DbgUI.Text("Health: " + m_HealthClient.ToString());
185
186 DbgUI.End();
188 }
189 else
190 {
192 DbgUI.Begin("Values", 50, 50);
193 DbgUI.End();
195 }
196 #endif
197 }
198}
static ref Param2< int, float > PARAM2_INT_FLOAT
Definition dbgui.c:60
TODO doc.
Definition enscript.c:118
void SendInitValues()
Sends values on object creation.
static void Init()
float m_HealthClient
const int TYPE_BLOOD
void Init()
float GetBlood()
const int TYPE_HEALTH
void ReceiveValue(int value_type, float value)
float m_BloodMaxValue
float m_HealthMaxValue
PlayerBase m_Player
const float SENSITIVTY_PERCENTAGE
float GetHealth()
float m_LastHealthUpdate
void OnScheduledTick(float deltatime)
float m_BloodClient
void SendValue(int value_type, float value)
void CheckBlood()
const int BLOOD_THRESHOLD_LOW
float m_LastBloodUpdate
void CheckHealth()
void OnRPC(ParamsReadContext ctx)
const float VALUE_CHECK_INTERVAL
float m_TimeSinceLastTick
void ShowDebugValues(bool show)
void CheckValues()
bool m_InitialSyncSent
void TransferValues(PlayerBase player)
Definition enmath.c:7
proto bool Read(void value_in)
DayZGame g_Game
Definition dayzgame.c:3942
DiagMenuIDs
Definition ediagmenuids.c:2
ERPCs
Definition erpcs.c:2
Serializer ParamsReadContext
Definition gameplay.c:15
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto void BeginCleanupScope()
static proto native void Text(string label)
static proto native void EndCleanupScope()
static proto native void End()
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.