DayZ 1.24
Loading...
Searching...
No Matches
PlayerSpawnHandler Class Reference
Collaboration diagram for PlayerSpawnHandler:
[legend]

Static Private Member Functions

static bool LoadData ()
 
static bool IsInitialized ()
 
static PlayerSpawnPreset GetRandomCharacterPreset ()
 
static bool ProcessEquipmentData (PlayerBase player, PlayerSpawnPreset data)
 equips character with the chosen preset
 
static void ProcessSlotsEquipment (PlayerBase player, PlayerSpawnPreset data)
 iterates over each object and spawns alternatives
 
static bool SelectAndSpawnSlotEquipment (PlayerBase player, PlayerSpawnPresetSlotData slotData)
 selects weighted slot equipment variant
 
static void ProcessCargoEquipment (PlayerBase player, PlayerSpawnPreset data)
 chooses one object from the array
 
static bool SelectAndSpawnCargoSet (PlayerBase player, PlayerSpawnPreset data)
 
static bool SpawnDiscreteCargoItemSet (PlayerBase player, PlayerSpawnPresetDiscreteCargoSetData csd)
 
static bool SpawnDiscreteSlotItemSet (PlayerBase player, PlayerSpawnPresetDiscreteItemSetSlotData dis, int slotID)
 
static bool SpawnComplexChildrenItems (EntityAI parent, notnull PlayerSpawnPresetItemSetBase data)
 could spawn other items recursively. Parent item is guaranteed here.
 
static bool SpawnSimpleChildrenItems (EntityAI parent, PlayerSpawnPresetItemSetBase data)
 
static void HandleNewItem (notnull ItemBase item, PlayerSpawnPresetItemSetBase data)
 
static EntityAI CreateChildItem (EntityAI parent, string type)
 
static void ApplyAttributes (ItemBase item, PlayerSpawnAttributesData attributes)
 

Static Private Attributes

static bool m_Initialized
 
static ref PlayerSpawnJsonData m_Data = new PlayerSpawnJsonData()
 

Detailed Description

Definition at line 1 of file CfgPlayerSpawnHandler.c.

Member Function Documentation

◆ ApplyAttributes()

static void PlayerSpawnHandler::ApplyAttributes ( ItemBase item,
PlayerSpawnAttributesData attributes )
inlinestaticprivate

Definition at line 273 of file CfgPlayerSpawnHandler.c.

274 {
275 if (!attributes)
276 return;
277
278 float health01 = Math.RandomFloatInclusive(attributes.healthMin, attributes.healthMax);
279 item.SetHealth01("", "Health", health01);
280
281 float quantity01 = Math.RandomFloatInclusive(attributes.quantityMin, attributes.quantityMax);
282 if (item.IsMagazine())
283 {
284 Magazine mag = Magazine.Cast(item);
285 //todo: magazine bullet customization?
286 /*if (attributes.magazineAmmoOrdered && attributes.magazineAmmoOrdered.Count() > 0)
287 {
288 mag.ServerSetAmmoCount(0);
289 foreach (string bulletType : attributes.magazineAmmoOrdered)
290 {
291 mag.ServerStoreCartridge(health01,bulletType);
292 }
293 mag.SetSynchDirty();
294 }
295 else*/
296 {
297 int ammoQuantity = (int)Math.Lerp(0, mag.GetAmmoMax(), quantity01);
298 mag.ServerSetAmmoCount(ammoQuantity);
299 }
300 }
301 else //'varQuantityDestroyOnMin' quantity safeguard
302 {
303 float quantityAbsolute = Math.Lerp(item.GetQuantityMin(), item.GetQuantityMax(), quantity01);
304 quantityAbsolute = Math.Round(quantityAbsolute); //avoids weird floats
305 if (quantityAbsolute <= item.GetQuantityMin() && item.ConfigGetBool("varQuantityDestroyOnMin"))
307 item.SetQuantity(quantityAbsolute);
308 }
309 }
Param3 int
Definition EnMath.c:7
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:106
static proto float Round(float f)
Returns mathematical round of value.

References Math::Lerp(), Math::RandomFloatInclusive(), and Math::Round().

Referenced by HandleNewItem(), and SpawnSimpleChildrenItems().

◆ CreateChildItem()

static EntityAI PlayerSpawnHandler::CreateChildItem ( EntityAI parent,
string type )
inlinestaticprivate

Definition at line 248 of file CfgPlayerSpawnHandler.c.

249 {
252 if (Class.CastTo(player, parent)) //special behavior
253 {
254 int count = player.GetInventory().AttachmentCount();
255 if (Class.CastTo(newItem, player.GetInventory().CreateInInventory(type)))
256 return newItem;
257
258 Debug.Log("FAILED spawning item: " + type + ", it fits in no cargo or attachment on any worn item", "n/a", "n/a", "CreateChildItem");
259 return null;
260 }
261
262 //weapon magazine exception
263 if (GetGame().ConfigIsExisting(CFG_MAGAZINESPATH + " " + type) && parent.IsWeapon())
264 {
266 if (Class.CastTo(wep, parent))
267 return wep.SpawnAttachedMagazine(type);
268 }
269
270 return parent.GetInventory().CreateInInventory(type);
271 }
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const string CFG_MAGAZINESPATH
Definition constants.c:211

References Class::CastTo(), CFG_MAGAZINESPATH, GetGame(), and Debug::Log().

Referenced by SpawnComplexChildrenItems(), and SpawnSimpleChildrenItems().

◆ GetRandomCharacterPreset()

static PlayerSpawnPreset PlayerSpawnHandler::GetRandomCharacterPreset ( )
inlinestaticprivate

Definition at line 40 of file CfgPlayerSpawnHandler.c.

41 {
43 int count = m_Data.presets.Count();
45 for (int i = 0; i < count; i++)
46 {
47 p = m_Data.presets[i];
48 if (p.IsValid())
49 {
50 for (int j = 0; j < p.spawnWeight; j++)
52 }
53 }
54
55 return m_Data.presets.Get(weightedPresetIndexes.GetRandomElement());
56 }
static ref PlayerSpawnJsonData m_Data

References m_Data.

Referenced by MissionBase::OnClientNewEvent().

◆ HandleNewItem()

static void PlayerSpawnHandler::HandleNewItem ( notnull ItemBase item,
PlayerSpawnPresetItemSetBase data )
inlinestaticprivate

Definition at line 236 of file CfgPlayerSpawnHandler.c.

237 {
238 ApplyAttributes(item, data.attributes);
239
241 if (Class.CastTo(player, item.GetHierarchyRootPlayer()) && data.GetQuickbarIdx() > -1)
242 player.SetQuickBarEntityShortcut(item, data.GetQuickbarIdx());
243
246 }
static void ApplyAttributes(ItemBase item, PlayerSpawnAttributesData attributes)
static bool SpawnSimpleChildrenItems(EntityAI parent, PlayerSpawnPresetItemSetBase data)
static bool SpawnComplexChildrenItems(EntityAI parent, notnull PlayerSpawnPresetItemSetBase data)
could spawn other items recursively. Parent item is guaranteed here.

References ApplyAttributes(), Class::CastTo(), SpawnComplexChildrenItems(), and SpawnSimpleChildrenItems().

Referenced by SpawnComplexChildrenItems(), and SpawnDiscreteSlotItemSet().

◆ IsInitialized()

static bool PlayerSpawnHandler::IsInitialized ( )
inlinestaticprivate

Definition at line 35 of file CfgPlayerSpawnHandler.c.

36 {
37 return m_Initialized;
38 }

References m_Initialized.

Referenced by MissionBase::OnClientNewEvent().

◆ LoadData()

static bool PlayerSpawnHandler::LoadData ( )
inlinestaticprivate

Definition at line 6 of file CfgPlayerSpawnHandler.c.

7 {
9 if (!spawnGearPresetFiles || (spawnGearPresetFiles && spawnGearPresetFiles.Count() == 0))
10 return false;
11
12 m_Data.presets = {};
13
14 foreach (string spawnPresetFile : spawnGearPresetFiles)
15 {
17 string path = "$mission:" + spawnPresetFile;
18
19 string errorMessage;
21 {
23 return false;
24 }
25
26 if (preset != null)
27 m_Data.presets.Insert(preset);
28 }
29
30 m_Initialized = m_Data.presets.Count() > 0;
31
32 return true;
33 }
static TStringArray GetPlayerSpawnGearPresetFiles()
enum ShapeType ErrorEx

References ErrorEx, CfgGameplayHandler::GetPlayerSpawnGearPresetFiles(), m_Data, m_Initialized, and path.

Referenced by MissionBase::OnInit().

◆ ProcessCargoEquipment()

static void PlayerSpawnHandler::ProcessCargoEquipment ( PlayerBase player,
PlayerSpawnPreset data )
inlinestaticprivate

chooses one object from the array

Definition at line 114 of file CfgPlayerSpawnHandler.c.

115 {
116 if (!data.HasDiscreteUnsortedItemSetsDefined())
117 {
118 Debug.Log("No non-empty 'discreteUnsortedItemSets' array found. Skipping cargo spawns", "n/a", "n/a", "ProcessCargoEquipment");
119 return;
120 }
121
123 }
static bool SelectAndSpawnCargoSet(PlayerBase player, PlayerSpawnPreset data)

References Debug::Log(), and SelectAndSpawnCargoSet().

Referenced by ProcessEquipmentData().

◆ ProcessEquipmentData()

static bool PlayerSpawnHandler::ProcessEquipmentData ( PlayerBase player,
PlayerSpawnPreset data )
inlinestaticprivate

equips character with the chosen preset

Definition at line 59 of file CfgPlayerSpawnHandler.c.

60 {
61 if (data.IsValid())
62 {
65 }
66
67 return true;
68 }
static void ProcessSlotsEquipment(PlayerBase player, PlayerSpawnPreset data)
iterates over each object and spawns alternatives
static void ProcessCargoEquipment(PlayerBase player, PlayerSpawnPreset data)
chooses one object from the array

References ProcessCargoEquipment(), and ProcessSlotsEquipment().

Referenced by MissionBase::OnClientNewEvent().

◆ ProcessSlotsEquipment()

static void PlayerSpawnHandler::ProcessSlotsEquipment ( PlayerBase player,
PlayerSpawnPreset data )
inlinestaticprivate

iterates over each object and spawns alternatives

Definition at line 71 of file CfgPlayerSpawnHandler.c.

72 {
73 if (!data.HasAttachmentSlotSetsDefined())
74 {
75 Debug.Log("No non-empty 'attachmentSlotItemSets' array found. Skipping slot spawns", "n/a", "n/a", "ProcessSlotsEquipment");
76 return;
77 }
78
79 foreach (PlayerSpawnPresetSlotData slotData : data.attachmentSlotItemSets)
81 }
static bool SelectAndSpawnSlotEquipment(PlayerBase player, PlayerSpawnPresetSlotData slotData)
selects weighted slot equipment variant

References Debug::Log(), and SelectAndSpawnSlotEquipment().

Referenced by ProcessEquipmentData().

◆ SelectAndSpawnCargoSet()

static bool PlayerSpawnHandler::SelectAndSpawnCargoSet ( PlayerBase player,
PlayerSpawnPreset data )
inlinestaticprivate

Definition at line 125 of file CfgPlayerSpawnHandler.c.

126 {
128 int count = data.discreteUnsortedItemSets.Count();
130 for (int i = 0; i < count; i++)
131 {
132 csd = data.discreteUnsortedItemSets[i];
133
134 if (csd.IsValid()) //only when the spawnWeight is set
135 {
136 for (int j = 0; j < csd.spawnWeight; j++)
138 }
139 }
140
141 csd = null;
142 if (weightedDiscreteSetIndexes.Count() > 0)
143 csd = data.discreteUnsortedItemSets.Get(weightedDiscreteSetIndexes.GetRandomElement());
145 }
static bool SpawnDiscreteCargoItemSet(PlayerBase player, PlayerSpawnPresetDiscreteCargoSetData csd)

References SpawnDiscreteCargoItemSet().

Referenced by ProcessCargoEquipment().

◆ SelectAndSpawnSlotEquipment()

static bool PlayerSpawnHandler::SelectAndSpawnSlotEquipment ( PlayerBase player,
PlayerSpawnPresetSlotData slotData )
inlinestaticprivate

selects weighted slot equipment variant

Definition at line 84 of file CfgPlayerSpawnHandler.c.

85 {
86 int slotID;
87 if (!slotData.TranslateAndValidateSlot(player, slotID))
88 return false;
89
90 if (!slotData.IsValid())
91 return false;
92
94 int count = slotData.discreteItemSets.Count();
96 for (int i = 0; i < count; i++)
97 {
98 dis = slotData.discreteItemSets[i];
99
100 if (dis.IsValid()) //only when the type exists and spawnWeight is set
101 {
102 for (int j = 0; j < dis.spawnWeight; j++)
104 }
105 }
106
107 dis = null;
108 if (weightedDiscreteSetIndexes.Count() > 0)
109 dis = slotData.discreteItemSets.Get(weightedDiscreteSetIndexes.GetRandomElement());
111 }
static bool SpawnDiscreteSlotItemSet(PlayerBase player, PlayerSpawnPresetDiscreteItemSetSlotData dis, int slotID)

References SpawnDiscreteSlotItemSet().

Referenced by ProcessSlotsEquipment().

◆ SpawnComplexChildrenItems()

static bool PlayerSpawnHandler::SpawnComplexChildrenItems ( EntityAI parent,
notnull PlayerSpawnPresetItemSetBase data )
inlinestaticprivate

could spawn other items recursively. Parent item is guaranteed here.

Definition at line 180 of file CfgPlayerSpawnHandler.c.

181 {
182 if (!data.complexChildrenTypes || data.complexChildrenTypes.Count() < 1) //no children defined, still valid!
183 return false;
184
185 foreach (PlayerSpawnPresetComplexChildrenType cct : data.complexChildrenTypes)
186 {
187 //todo: slotID option over nyah?
188 if (cct.itemType == string.Empty)
189 {
190 Debug.Log("Empty item type found in 'complexChildrenTypes' of parent : " + parent, "n/a", "n/a", "SpawnSimpleChildrenItems");
191 continue;
192 }
193
195 Class.CastTo(item, CreateChildItem(parent, cct.itemType));
196
197 if (item)
199 else
200 Debug.Log("FAILED spawning item: " + cct.itemType + " of parent: " + parent, "n/a", "n/a", "SpawnComplexChildrenItems");
201 }
202
203 return true;
204 }
static void HandleNewItem(notnull ItemBase item, PlayerSpawnPresetItemSetBase data)
static EntityAI CreateChildItem(EntityAI parent, string type)
used for specific hierarchical child spawning

References Class::CastTo(), CreateChildItem(), HandleNewItem(), and Debug::Log().

Referenced by HandleNewItem(), and SpawnDiscreteCargoItemSet().

◆ SpawnDiscreteCargoItemSet()

static bool PlayerSpawnHandler::SpawnDiscreteCargoItemSet ( PlayerBase player,
PlayerSpawnPresetDiscreteCargoSetData csd )
inlinestaticprivate

Definition at line 147 of file CfgPlayerSpawnHandler.c.

148 {
151 return true;
152 }

References SpawnComplexChildrenItems(), and SpawnSimpleChildrenItems().

Referenced by SelectAndSpawnCargoSet().

◆ SpawnDiscreteSlotItemSet()

static bool PlayerSpawnHandler::SpawnDiscreteSlotItemSet ( PlayerBase player,
PlayerSpawnPresetDiscreteItemSetSlotData dis,
int slotID )
inlinestaticprivate

Definition at line 154 of file CfgPlayerSpawnHandler.c.

155 {
156 if (!dis)
157 {
158 Debug.Log("No PlayerSpawnPresetDiscreteItemSet found. Skipping spawn for slot: " + InventorySlots.GetSlotName(slotID), "n/a", "n/a", "SpawnDiscreteSlotItemSet");
159 return false;
160 }
161
163 if (slotID == InventorySlots.HANDS) //hands exception
164 item = ItemBase.Cast(player.GetHumanInventory().CreateInHands(dis.itemType));
165 else
166 item = ItemBase.Cast(player.GetInventory().CreateAttachmentEx(dis.itemType, slotID));
167
168 if (item)
170 else if (dis.itemType != string.Empty)
171 {
172 Debug.Log("FAILED spawning item type: " + dis.itemType + " into slot: " + InventorySlots.GetSlotName(slotID) + " of parent: " + player, "n/a", "n/a", "SpawnDiscreteSlotItemSet");
173 return false;
174 }
175
176 return item != null;
177 }
provides access to slot configuration
static proto native owned string GetSlotName(int id)
converts slot_id to string

References InventorySlots::GetSlotName(), HandleNewItem(), and Debug::Log().

Referenced by SelectAndSpawnSlotEquipment().

◆ SpawnSimpleChildrenItems()

static bool PlayerSpawnHandler::SpawnSimpleChildrenItems ( EntityAI parent,
PlayerSpawnPresetItemSetBase data )
inlinestaticprivate

Definition at line 206 of file CfgPlayerSpawnHandler.c.

207 {
208 if (!data || !data.simpleChildrenTypes || data.simpleChildrenTypes.Count() < 1) //no children defined, still valid!
209 return false;
210
211 int count = data.simpleChildrenTypes.Count();
212 string itemType;
213 for (int i = 0; i < count; i++)
214 {
215 itemType = data.simpleChildrenTypes[i];
216 if (itemType == string.Empty)
217 {
218 Debug.Log("Empty item type found at idx: " + i.ToString() + " of 'simpleChildrenTypes' array. Skipping", "n/a", "n/a", "SpawnSimpleChildrenItems");
219 continue;
220 }
221
223 Class.CastTo(item, CreateChildItem(parent, itemType));
224
225 if (item)
226 {
227 if (!data.simpleChildrenUseDefaultAttributes)
228 ApplyAttributes(item, data.attributes);
229 }
230 else
231 Debug.Log("FAILED spawning item type: " + itemType + " to parent: " + parent, "n/a", "n/a", "SpawnSimpleChildrenItems");
232 }
233 return true;
234 }
Empty
Definition Hand_States.c:14

References ApplyAttributes(), Class::CastTo(), CreateChildItem(), Empty, and Debug::Log().

Referenced by HandleNewItem(), and SpawnDiscreteCargoItemSet().

Member Data Documentation

◆ m_Data

ref PlayerSpawnJsonData PlayerSpawnHandler::m_Data = new PlayerSpawnJsonData()
staticprivate

Definition at line 4 of file CfgPlayerSpawnHandler.c.

Referenced by GetRandomCharacterPreset(), and LoadData().

◆ m_Initialized

bool PlayerSpawnHandler::m_Initialized
staticprivate

Definition at line 3 of file CfgPlayerSpawnHandler.c.

Referenced by IsInitialized(), and LoadData().


The documentation for this class was generated from the following file: