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