Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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 
22 class FreshSpawn_Preset extends PresetSpawnBase
23 {
24  override void OnPresetSpawn(PlayerBase player)
25  {
26  FindAndTakeToHandsFromInventory("Plum");
27  }
28 }
29 //---------------------------------------------
30 
31 class Farmer_Preset extends PresetSpawnBase
32 {
33  override void OnPresetSpawn(PlayerBase player)
34  {
35 
36  }
37 }
38 //---------------------------------------------
39 class AntiHazard_Preset extends PresetSpawnBase
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 
55 class Update117_Preset extends PresetSpawnBase
56 {
57  vector randompos;
58  override void OnPresetSpawn(PlayerBase player)
59  {
60  randompos = player.GetPosition();
61  foreach (EntityAI itm : m_ItemsPreset)
62  {
63  if (itm)
64  {
65  vector itempos;
66  itempos[0] = Math.RandomFloat(-1,1);
67  itempos[2] = Math.RandomFloat(-1,1);
68 
69  ItemBase itmBase = ItemBase.Cast(itm);
70 
71  itmBase.SetPosition(randompos + itempos);
72  itmBase.SetQuantity(100);
73  }
74  }
75  }
76 }
77 
78 //---------------------------------------------
79 
80 class Update118_Preset extends PresetSpawnBase
81 {
82  vector randompos;
83  override void OnPresetSpawn(PlayerBase player)
84  {
85  randompos = player.GetPosition();
86  foreach (EntityAI itm : m_ItemsPreset)
87  {
88  if (itm)
89  {
90  vector itempos;
91  itempos[0] = Math.RandomFloat(-1,1);
92  itempos[2] = Math.RandomFloat(-1,1);
93 
94  ItemBase itmBase = ItemBase.Cast(itm);
95 
96  itmBase.SetPosition(randompos + itempos);
97  itmBase.SetQuantity(100);
98  }
99  }
100  }
101 }
102 //---------------------------------------------
103 
104 class BBMaterials_Preset extends PresetSpawnBase
105 {
106  vector randompos;
107  override void OnPresetSpawn(PlayerBase player)
108  {
109  randompos = player.GetPosition();
110  foreach (EntityAI itm : m_ItemsPreset)
111  {
112  if (itm)
113  {
114  vector itempos;
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 
125 class Military_Light_Preset extends PresetSpawnBase
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 
134  FindAndTakeToHandsFromInventory("AK101");
135  }
136 }
137 
138 
139 
140 
141 //---------------------------------------------
142 //------------------ BASE ---------------------
143 //---------------------------------------------
144 
145 class PresetSpawnBase
146 {
147  ref array<EntityAI> m_ItemsInventory = new array<EntityAI>;//inventory items
150  array<EntityAI> m_ItemsPreset;//all items spawned from this preset
151  //---------------------------------------------
152 
153  void Init(PlayerBase player)
154  {
155  m_Player = player;
156  m_Inventory = player.GetHumanInventory();
157  m_ItemsPreset = player.m_PresetItems;
158  m_Inventory.EnumerateInventory(InventoryTraversalType.INORDER, m_ItemsInventory);
159  OnPresetSpawn(player);
160 
161  foreach (auto item:m_ItemsPreset)
162  {
163  Print(item);
164  }
165  }
166 
167  //---------------------------------------------
168 
169  void OnPresetSpawn(PlayerBase player)
170  {
171 
172  }
173  //---------------------------------------------
174 
175  void TakeToHands(EntityAI item)
176  {
177  if (GetGame().IsMultiplayer() && m_Player.GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_SERVER)//throws assert otherwise
178  return;
179  if (GetGame().IsDedicatedServer())
180  {
181  m_Player.TakeEntityToHandsImpl(InventoryMode.SERVER, item);
182  }
183  else
184  {
185  m_Player.TakeEntityToHandsImpl(InventoryMode.PREDICTIVE, item);
186  }
187 
188  }
189 
190  void FindAndTakeToHandsFromInventory(string classname)
191  {
192  m_Inventory.EnumerateInventory(InventoryTraversalType.INORDER, m_ItemsInventory);
193  foreach(EntityAI item:m_ItemsInventory)
194  {
195  if (item.ClassName() == classname)
196  {
197  TakeToHands(item);
198  return;
199  }
200  }
201  }
202 
203  EntityAI FindItem(string classname)
204  {
205  m_Inventory.EnumerateInventory(InventoryTraversalType.INORDER, m_ItemsInventory);
206  foreach(EntityAI item:m_ItemsInventory)
207  {
208  if (item.ClassName() == classname)
209  {
210  return item;
211  }
212  }
213  return null;
214  }
215 
216 }
217 
218 #endif
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
Print
proto void Print(void var)
Prints content of variable to console/log.
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
InventoryMode
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition: inventory.c:21
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
array< EntityAI >
InventoryTraversalType
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Definition: gameplay.c:5
HumanInventory
inventory for plain man/human
Definition: humaninventory.c:9
Math
Definition: enmath.c:6
EntityAI
Definition: building.c:5
m_Inventory
enum ScreenWidthType m_Inventory
DayZPlayerInstanceType
DayZPlayerInstanceType
defined in C++
Definition: dayzplayer.c:1058