DayZ 1.24
Loading...
Searching...
No Matches
PresetHandlers.c
Go to the documentation of this file.
1#ifdef DEVELOPER
2//----------------------------------------------------------
3//Class names need to match the preset name + _Preset suffix
4//----------------------------------------------------------
5
6
7//TEMPLATE:
8/*
9
10 class Farmer_Preset extends PresetSpawnBase
11 {
12 override void OnPresetSpawn(PlayerBase player)
13 {
14 //m_ItemsInventory -> contains all items in player inventory
15 }
16 }
17
18*/
19
20//---------------------------------------------
21
23{
24 override void OnPresetSpawn(PlayerBase player)
25 {
27 }
28}
29//---------------------------------------------
30
32{
33 override void OnPresetSpawn(PlayerBase player)
34 {
35
36 }
37}
38//---------------------------------------------
40{
41 override void OnPresetSpawn(PlayerBase player)
42 {
43 EntityAI mask = FindItem("AirborneMask");
44
45 if (mask)
46 {
47 auto debugParams = DebugSpawnParams.WithPlayer(player);
48 mask.OnDebugSpawnEx(debugParams);
49 }
50
51 }
52}
53//---------------------------------------------
54
56{
58 override void OnPresetSpawn(PlayerBase player)
59 {
60 randompos = player.GetPosition();
61 foreach (EntityAI itm : m_ItemsPreset)
62 {
63 if (itm)
64 {
66 itempos[0] = Math.RandomFloat(-1, 1);
67 itempos[2] = Math.RandomFloat(-1, 1);
68
70
71 itmBase.SetPosition(randompos + itempos);
72 itmBase.SetQuantity(100);
73 }
74 }
75 }
76}
77
78//---------------------------------------------
79
81{
83 override void OnPresetSpawn(PlayerBase player)
84 {
85 randompos = player.GetPosition();
86 foreach (EntityAI itm : m_ItemsPreset)
87 {
88 if (itm)
89 {
91 itempos[0] = Math.RandomFloat(-1, 1);
92 itempos[2] = Math.RandomFloat(-1, 1);
93
95
96 itmBase.SetPosition(randompos + itempos);
97 itmBase.SetQuantity(100);
98 }
99 }
100 }
101}
102//---------------------------------------------
103
105{
107 override void OnPresetSpawn(PlayerBase player)
108 {
109 randompos = player.GetPosition();
110 foreach (EntityAI itm : m_ItemsPreset)
111 {
112 if (itm)
113 {
115 itempos[0] = Math.RandomFloat(-1, 1);
116 itempos[2] = Math.RandomFloat(-1, 1);
117 itm.SetPosition(randompos + itempos);
118 }
119 }
120 }
121}
122//---------------------------------------------
123
124
126{
127 override void OnPresetSpawn(PlayerBase player)
128 {
129 EntityAI weapon = FindItem("AK101");
130
131 auto debugParams = DebugSpawnParams.WithPlayer(player);
132 weapon.OnDebugSpawnEx(debugParams);
133
135 }
136}
137
138
139//---------------------------------------------
140//------------------ BASE ---------------------
141//---------------------------------------------
142
143class PresetSpawnBase
144{
148 array<EntityAI> m_ItemsPreset;//all items spawned from this preset
149 //---------------------------------------------
150
152 {
154 m_Inventory = player.GetHumanInventory();
155 m_ItemsPreset = player.m_PresetItems;
156 m_Inventory.EnumerateInventory(InventoryTraversalType.INORDER, m_ItemsInventory);
158
159 foreach (auto item: m_ItemsPreset)
160 Print(item);
161 }
162
163 //---------------------------------------------
164
166 {
167
168 }
169 //---------------------------------------------
170
172 {
173 if (GetGame().IsMultiplayer() && m_Player.GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_SERVER)//throws assert otherwise
174 return;
175 if (GetGame().IsDedicatedServer())
176 m_Player.TakeEntityToHandsImpl(InventoryMode.SERVER, item);
177 else
178 m_Player.TakeEntityToHandsImpl(InventoryMode.PREDICTIVE, item);
179
180 }
181
183 {
184 m_Inventory.EnumerateInventory(InventoryTraversalType.INORDER, m_ItemsInventory);
186 {
187 if (item.ClassName() == classname)
188 {
190 return;
191 }
192 }
193 }
194
196 {
197 m_Inventory.EnumerateInventory(InventoryTraversalType.INORDER, m_ItemsInventory);
199 {
200 if (item.ClassName() == classname)
201 return item;
202 }
203 return null;
204 }
205
206}
207
208#endif
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition Inventory.c:22
override Widget Init()
Definition DayZGame.c:120
DayZPlayer m_Player
Definition Hand_Events.c:42
enum ScreenWidthType m_Inventory
inventory for plain man/human
Definition EnMath.c:7
DayZPlayerInstanceType
defined in C++
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Definition gameplay.c:6
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].