DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ArrowManagerPlayer.c
Go to the documentation of this file.
2{
4
6 {
8 {
10 }
11 }
12
13 private static void InitializeHash()
14 {
16
17 AddArrowTypeToHash("Ammo_HuntingBolt");
18 AddArrowTypeToHash("Ammo_ImprovisedBolt_1");
19 AddArrowTypeToHash("Ammo_ImprovisedBolt_2");
20 AddArrowTypeToHash("Ammo_ImprovisedBolt_3");
21 }
22
23 private static void AddArrowTypeToHash(string ArrowType)
24 {
25 m_TypeHashTable.Insert(ArrowType.Hash(), ArrowType.ToType());
26 }
27
28 private static typename GetArrowTypeFromHash(int hash)
29 {
30 return m_TypeHashTable.Get(hash);
31 }
32
34 {
35 ctx.Write(VERSION);
36 int count = m_Arrows.Count();
37 int i;
38 //TODO MW Delete after find why sometimes arrow missing - most likely Life span
39 for (i = count - 1; i >= 0; i--)
40 {
41 if (!m_Arrows.Get(i))
42 {
43 m_Arrows.Remove(i);
44 }
45 }
46 count = m_Arrows.Count();
47
48 ctx.Write(count);
49
50 for (i = 0; i < count; i++)
51 {
52 EntityAI arrow = m_Arrows.Get(i);
53
54 string type = arrow.GetType();
55 ctx.Write(type.Hash());
56
57 vector angle = arrow.GetLocalYawPitchRoll();
58 vector pos = arrow.GetLocalPosition();
59
60 ctx.Write(angle[0]);
61 ctx.Write(angle[1]);
62 ctx.Write(angle[2]);
63 ctx.Write(pos[0]);
64 ctx.Write(pos[1]);
65 ctx.Write(pos[2]);
66
67 int pivot = arrow.GetHierarchyPivot();
68 ctx.Write(pivot);
69 }
70
71 return true;
72 }
73
74
76 {
77 int version;
78 if (!ctx.Read(version))
79 {
80 return false;
81 }
82
83 int count;
84 if (!ctx.Read(count))
85 {
86 return false;
87 }
88
89 for (int i = 0; i < count; i++)
90 {
91
92 if (version >= 1)
93 {
94 int hash;
95 if (!ctx.Read(hash))
96 {
97 return false;
98 }
99
100 float angleF[3];
101 float posF[3];
102 float value;
103
104 if (!ctx.Read(value))
105 {
106 return false;
107 }
108 angleF[0] = value;
109
110 if (!ctx.Read(value))
111 {
112 return false;
113 }
114 angleF[1] = value;
115
116 if (!ctx.Read(value))
117 {
118 return false;
119 }
120 angleF[2] = value;
121
122 if (!ctx.Read(value))
123 {
124 return false;
125 }
126 posF[0] = value;
127
128 if (!ctx.Read(value))
129 {
130 return false;
131 }
132 posF[1] = value;
133
134 if (!ctx.Read(value))
135 {
136 return false;
137 }
138 posF[2] = value;
139
140 vector angle = "0 0 0";
141 vector pos = "0 0 0";
142
143 angle = vector.ArrayToVec(angleF);
144 pos = vector.ArrayToVec(posF);
145
146 int pivot;
147 if (!ctx.Read(pivot))
148 {
149 return false;
150 }
151
152 if (version >= 2)
153 {
154 #ifdef SERVER
156 #else
158 #endif
159
160 typename arrowType = GetArrowTypeFromHash(hash);
161 EntityAI arrow = EntityAI.Cast(GetGame().CreateObjectEx(arrowType.ToString(), pos, spawnFlags));
162 if (arrow)
163 {
164 arrow.SetQuantityToMinimum();
165 arrow.SetYawPitchRoll(angle);
166 m_Owner.AddChild(arrow, pivot);
167 }
168 }
169 }
170
171 }
172
173 return true;
174 }
175}
const int ECE_LOCAL
const int ECE_KEEPHEIGHT
const int ECE_DYNAMIC_PERSISTENCY
protected EntityAI m_Owner
protected const int VERSION
protected ref array< EntityAI > m_Arrows
void ArrowManagerPlayer(PlayerBase player)
static private void AddArrowTypeToHash(string ArrowType)
bool Load(ParamsReadContext ctx)
static private GetArrowTypeFromHash(int hash)
bool Save(ParamsWriteContext ctx)
static private void InitializeHash()
static private ref map< int, typename > m_TypeHashTable
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
static vector ArrayToVec(float arr[])
Convert static array of floats into a vector.
Definition EnConvert.c:502
proto native CGame GetGame()
proto native ToType()
Returns internal type representation. Can be used in runtime, or cached in variables and used for fas...
proto native int Hash()
Returns hash of string.