DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
PlayerStatBase.c
Go to the documentation of this file.
2{
3 int m_Type;
7 float Get();
8 string GetLabel();
9 void SetByFloat(float value);
10 void SetByFloatEx(float value, string system = "" );
11 bool IsSynced();
13 void Init(int id/*, PlayerStats manager*/);
16 float GetMax();
17 float GetMin();
18 int GetType()
19 {
20 return m_Type;
21 }
22};
23
24class PlayerStat<Class T> extends PlayerStatBase
25{
26 protected T m_MinValue;
27 protected T m_MaxValue;
28 protected T m_Value;
29 protected string m_ValueLabel;
30 protected int m_Flags;
31
34
35
36 void PlayerStat(T min, T max,T init, string label, int flags)
37 {
38 m_MinValue = min;
39 m_MaxValue = max;
40 m_Value = init;
41 m_ValueLabel = label;
42 m_Flags = flags;
43
44 m_Records = new array<PlayerStatRecord>;
45 }
46
47 override void Init(int id/*, PlayerStats manager*/)
48 {
49 m_Type = id;
50 //m_Manager = manager;
51 }
52
53 override void SerializeValue(array<ref StatDebugObject> objects, int flags)
54 {
55 objects.Insert( new StatDebugObject(GetLabel(), Get(), eRemoteStatType.PLAYER_STATS) );
56 }
57
59 {
60 return m_Manager;
61 }
62
63 void Set( T value, string system = "" )
64 {
65 /*
66 Print("setting stat: " + this.GetLabel() + "| value:" +value.ToString());
67
68 if( this.GetLabel() == "Toxicity" )
69 {
70 DebugPrint.LogAndTrace("stack");
71 }
72 */
73 if ( value > m_MaxValue )
74 {
76 }
77 else if (value < m_MinValue)
78 {
80 }
81 else
82 {
83 m_Value = value;
84 }
85 //if( GetManager().GetAllowLogs() ) CreateRecord(value, system);
86 }
87
88 void SetByFloat(float value, string system = "" )
89 {
90 T f = value;
91 Set(f,system);
92
93 }
94 override void SetByFloatEx(float value, string system = "" )
95 {
96 SetByFloat(value, system);
97 }
98 /*
99 void SetByParam(Param param, string system = "" )
100 {
101 Class.CastTo(p1, param);
102 T v = p1.param1;
103 Set(v, system);
104 }
105 */
106 void Add( T value, string system = "" )
107 {
108 Set(m_Value+value, system);
109 }
110
111 override float Get()
112 {
113 return m_Value;
114 }
115
116 override string GetLabel()
117 {
118 return m_ValueLabel;
119 }
120
121 override float GetMax()
122 {
123 return m_MaxValue;
124 }
125
126 override float GetMin()
127 {
128 return m_MinValue;
129 }
130
131 override float GetNormalized()
132 {
133 return Math.InverseLerp(GetMin(), GetMax(), Get());
134 }
135
137 {
138 return m_Records;
139 }
140
141 void CreateRecord(float value, string system)
142 {
143 m_Records.Insert( new PlayerStatRecord(value, GetGame().GetTime(), system ) );
144 }
145
146 override void OnStoreSave( ParamsWriteContext ctx )
147 {
148 //ctx.Write(m_ValueLabel);
149 //PrintString("saving " + GetLabel()+" value:" +m_Value);
150 ctx.Write(m_Value);
151 }
152
153 override bool OnStoreLoad( ParamsReadContext ctx)
154 {
155 //string name;
156
157 //ctx.Read(name);
158 T value;
159 if(ctx.Read(value))
160 {
161 m_Value = value;
162 }
163 else
164 {
165 return false;
166 }
167 //PrintString("loading " + GetLabel()+" value:" +m_Value);
168 return true;
169 }
170}
eBleedingSourceType m_Type
enum MagnumStableStateID init
float GetTime()
float m_MaxValue
float m_MinValue
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition EnMath.c:7
override void Init(int id)
void SetByFloat(float value)
void SetByFloatEx(float value, string system="")
override array< PlayerStatRecord > GetRecords()
PlayerStats GetManager()
void SetByFloat(float value, string system="")
override void OnStoreSave(ParamsWriteContext ctx)
void Add(T value, string system="")
float GetNormalized()
override float GetNormalized()
override float GetMax()
override float Get()
protected int m_Flags
override float GetMin()
bool OnStoreLoad(ParamsReadContext ctx)
override void SetByFloatEx(float value, string system="")
override void SerializeValue(array< ref StatDebugObject > objects, int flags)
override bool OnStoreLoad(ParamsReadContext ctx)
protected T m_Value
void Set(T value, string system="")
void PlayerStat(T min, T max, T init, string label, int flags)
void Init(int id)
protected T m_MinValue
void CreateRecord(float value, string system)
void OnRPC(ParamsReadContext ctx)
string GetLabel()
PlayerStats m_Manager
void OnStoreSave(ParamsWriteContext ctx)
override string GetLabel()
ref array< PlayerStatRecord > m_Records
array< PlayerStatRecord > GetRecords()
protected T m_MaxValue
void SerializeValue(array< ref StatDebugObject > objects, int flags)
protected string m_ValueLabel
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
string m_Value
Definition EnEntity.c:806
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...