Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
debugmonitorvalues.c
Go to the documentation of this file.
2 {
3  const int TYPE_HEALTH = 1;
4  const int TYPE_BLOOD = 2;
5  const int TYPE_BODY_TEMP = 3;
6  const int TYPE_POSITION = 4;
7  const int TYPE_LAST_DAMAGE = 5;
8 
9  const int LAST_DAMAGE_FALL = 1;
10  const int LAST_DAMAGE_HIT = 2;
11 
12  const float VALUE_CHECK_INTERVAL = 1;
13  const float SENSITIVTY_PERCENTAGE = 1;//how much the value needs to change up/down from previous update to trigger a new update(in percent)
14 
15  PlayerBase m_Player;
16  float m_TimeSinceLastTick = VALUE_CHECK_INTERVAL + 1;
17 
18  string m_CurrentLastDamage;
19 
20  float m_LastHealthUpdate;
21  float m_LastBloodUpdate;
22  string m_lastDamageUpdate;
23 
24  float m_HealthMaxValue;
25  float m_BloodMaxValue;
26 
27  float m_BloodClient;
28  float m_HealthClient;
29  string m_LastDamageClient;
30 
31  void DebugMonitorValues(PlayerBase player)
32  {
33  m_Player = player;
34  Init();
35  }
36 
37  void Init()
38  {
39  m_HealthMaxValue = m_Player.GetMaxHealth("", "Health");
40  m_BloodMaxValue = m_Player.GetMaxHealth("", "Blood");
41  }
42 
43  void OnScheduledTick(float deltatime)
44  {
45  if ( GetGame().IsClient() ) return;
46  if ( !GetGame().IsDebugMonitor() ) return; // turned off in server config
47 
48  m_TimeSinceLastTick += deltatime;
49 
51  {
53  CheckValues();
54  }
55  }
56 
57  void CheckValues()
58  {
59  CheckHealth();
60  CheckBlood();
61  CheckLastDamage();
62  }
63 
64  float GetBlood()
65  {
66  return m_BloodClient;
67  }
68 
69  float GetHealth()
70  {
71  return m_HealthClient;
72  }
73 
74  string GetLastDamage()
75  {
76  return m_LastDamageClient;
77  }
78 
79  void SetLastDamage(string value)
80  {
81  m_CurrentLastDamage = value;
82  }
83 
84  void CheckHealth()
85  {
86  float health_current = m_Player.GetHealth("","Health");
87  float health_normalized = health_current / m_HealthMaxValue;
88  float difference_normalized = health_normalized - m_LastHealthUpdate;
89  float diff_abs = Math.AbsFloat(difference_normalized);
90 
91  if ( diff_abs > ( SENSITIVTY_PERCENTAGE /100 ) )
92  {
93  Param1<float> param = new Param1<float>( health_current );
94 
95  SendValue(TYPE_HEALTH, param);
96  m_LastHealthUpdate = health_normalized;
97  }
98  }
99 
100  void CheckBlood()
101  {
102  float blood_current = m_Player.GetHealth("","Blood");
103  float blood_normalized = blood_current / m_BloodMaxValue;
104  float difference_normalized = blood_normalized - m_LastBloodUpdate;
105  float diff_abs = Math.AbsFloat(difference_normalized);
106 
107  if ( diff_abs > ( SENSITIVTY_PERCENTAGE /100 ) )
108  {
109  Param1<float> param = new Param1<float>( blood_current );
110 
111  SendValue(TYPE_BLOOD, param);
112  m_LastBloodUpdate = blood_normalized;
113  }
114  }
115 
116  void CheckLastDamage()
117  {
118  if (m_CurrentLastDamage != m_lastDamageUpdate)
119  {
120  Param1<string> param = new Param1<string>(m_CurrentLastDamage);
121  SendValue(TYPE_LAST_DAMAGE, param);
122  m_lastDamageUpdate = m_CurrentLastDamage;
123  }
124  }
125 
126  void SendValue(int value_type, Param param)
127  {
128  switch(value_type)
129  {
130  case DebugMonitorValues.TYPE_HEALTH:
131  case DebugMonitorValues.TYPE_BLOOD:
132  {
133  Param1<float> value_float = Param1<float>.Cast( param );
134 
135  CachedObjectsParams.PARAM2_INT_FLOAT.param1 = value_type;
136  CachedObjectsParams.PARAM2_INT_FLOAT.param2 = value_float.param1;
137  //Print("SendingValue type " + value_type.ToString() + " value " + value_float.ToString());
138  GetGame().RPCSingleParam(m_Player, ERPCs.RPC_DEBUG_MONITOR_FLT, CachedObjectsParams.PARAM2_INT_FLOAT, true, m_Player.GetIdentity());
139  }
140  break;
141  case DebugMonitorValues.TYPE_LAST_DAMAGE:
142  {
143  Param1<string> value_string = Param1<string>.Cast( param );
144 
145  CachedObjectsParams.PARAM2_INT_STRING.param1 = value_type;
146  CachedObjectsParams.PARAM2_INT_STRING.param2 = value_string.param1;
147  //Print("SendingValue type " + value_type.ToString() + " value " + value_string);
148  GetGame().RPCSingleParam(m_Player, ERPCs.RPC_DEBUG_MONITOR_STR, CachedObjectsParams.PARAM2_INT_STRING, true, m_Player.GetIdentity());
149  }
150  break;
151  }
152  }
153 
154  void ReceiveValue(int value_type, Param param)
155  {
156  GetGame().GetMission().CreateDebugMonitor();
157 
158  switch (value_type)
159  {
160  case DebugMonitorValues.TYPE_HEALTH:
161  {
162  Param1<float> valueHealth = Param1<float>.Cast( param );
163  //Print("ReceivedValue health " + valueHealth.param1.ToString());
164  m_HealthClient = valueHealth.param1;
165  }
166  break;
167  case DebugMonitorValues.TYPE_BLOOD:
168  {
169  Param1<float> valueBlood = Param1<float>.Cast( param );
170  //Print("ReceivedValue blood " + valueBlood.param1.ToString());
171  m_BloodClient = valueBlood.param1;
172  }
173  break;
174  case DebugMonitorValues.TYPE_LAST_DAMAGE:
175  {
176  Param1<string> valueLastDamage = Param1<string>.Cast( param );
177  //Print("ReceivedValue lastdamage " + valueLastDamage.param1);
178  m_LastDamageClient = valueLastDamage.param1;
179  }
180  break;
181  }
182  }
183 
184  void OnRPCFloat(ParamsReadContext ctx)
185  {
186  Param1<float> value = new Param1<float>(0);
187 
188  ctx.Read(CachedObjectsParams.PARAM2_INT_FLOAT);
189  int value_type = CachedObjectsParams.PARAM2_INT_FLOAT.param1;
190  value.param1 = CachedObjectsParams.PARAM2_INT_FLOAT.param2;
191 
192  ReceiveValue(value_type, value);
193  }
194 
195  void OnRPCString(ParamsReadContext ctx)
196  {
197  Param1<string> value = new Param1<string>("");
198 
199  ctx.Read(CachedObjectsParams.PARAM2_INT_STRING);
200  int value_type = CachedObjectsParams.PARAM2_INT_STRING.param1;
201  value.param1 = CachedObjectsParams.PARAM2_INT_STRING.param2;
202 
203  ReceiveValue(value_type, value);
204  }
205 };
GetGame
proto native CGame GetGame()
m_TimeSinceLastTick
float m_TimeSinceLastTick
Definition: injuryhandler.c:47
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
DebugMonitorValues
Definition: debugmonitorvalues.c:1
VALUE_CHECK_INTERVAL
enum eInjuryHandlerLevels VALUE_CHECK_INTERVAL
CachedObjectsParams
Definition: utilityclasses.c:9
m_HealthMaxValue
float m_HealthMaxValue
Definition: injuryhandler.c:50
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
PlayerBase
Definition: playerbaseclient.c:1
SENSITIVTY_PERCENTAGE
const float SENSITIVTY_PERCENTAGE
Definition: injuryhandler.c:43
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
m_LastHealthUpdate
eInjuryHandlerLevels m_LastHealthUpdate
Definition: injuryhandler.c:49
ERPCs
ERPCs
Definition: erpcs.c:1
Math
Definition: enmath.c:6