Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
objectspawner.c
Go to the documentation of this file.
2 {
3  protected static const ref TStringArray VALID_PATHS = {"DZ\\plants","DZ\\plants_bliss","DZ\\rocks","DZ\\rocks_bliss","DZ/plants","DZ/plants_bliss","DZ/rocks","DZ/rocks_bliss"};
4  //---------------------------------------------------------------------------------------
5  static void SpawnObjects()
6  {
7  if (CfgGameplayHandler.GetObjectSpawnersArr() && CfgGameplayHandler.GetObjectSpawnersArr().Count() > 0)
8  {
9  TStringArray arr = CfgGameplayHandler.GetObjectSpawnersArr();
10  foreach (string spawnerFilePath: arr)
11  {
12  string path = "$mission:" + spawnerFilePath;
13 
14  string errorMessage;
15  ObjectSpawnerJson spawner;
16  if (JsonFileLoader<ObjectSpawnerJson>.LoadFile(path, spawner, errorMessage))
17  {
18  foreach (ITEM_SpawnerObject o : spawner.Objects)
19  SpawnObject(o);
20  }
21  else
22  ErrorEx(errorMessage);
23  }
24  }
25  }
26  //---------------------------------------------------------------------------------------
27  static void SpawnObject(ITEM_SpawnerObject item)
28  {
29  Object object;
30 
31  float scale = item.scale;
32  if (scale == 0)
33  scale = 1;
34 
35  if (item.name.Contains("\\") || item.name.Contains("/"))
36  {
37  if (ValidatePath(item.name))
38  object = GetGame().CreateStaticObjectUsingP3D(item.name, vector.ArrayToVec(item.pos), vector.ArrayToVec(item.ypr),scale);
39  }
40  else
41  {
43 
44  if (item.enableCEPersistency)
45  {
46  flags &= ~ECE_DYNAMIC_PERSISTENCY;
47  flags &= ~ECE_NOLIFETIME;
48  }
49 
50  object = GetGame().CreateObjectEx(item.name, vector.ArrayToVec(item.pos), flags, RF_IGNORE);
51  if (object)
52  {
53  object.SetOrientation( vector.ArrayToVec(item.ypr));
54  if (item.scale != 1)
55  object.SetScale(scale);
56  }
57  }
58 
59  if (!object)
60  PrintToRPT("Object spawner failed to spawn "+item.name);
61  }
62  //---------------------------------------------------------------------------------------
63  static void OnGameplayDataHandlerLoad()
64  {
65  SpawnObjects();
66  GetGame().GetWorld().ProcessMarkedObjectsForPathgraphUpdate();
67  }
68 
69  //---------------------------------------------------------------------------------------
70  static bool ValidatePath(string path)
71  {
72  foreach (string p: VALID_PATHS)
73  {
74  if (path.Contains(p))
75  return true;
76  }
77  return false;
78  }
79  //---------------------------------------------------------------------------------------
80 };
81 
83 {
85 };
86 
88 {
89  string name;
90  float pos[3];
91  float ypr[3];
92  float scale;
93  bool enableCEPersistency;
94 };
95 
96 
99 {
101  static string m_Path = "$mission:myspawndata.json";
102 
103  static void SpawnObjects()
104  {
105  Objects.Clear();
106  SpawnInit();
108  j.Objects = Objects;
109 
110  string errorMessage;
111  if (!JsonFileLoader<ObjectSpawnerJson>.SaveFile(m_Path, j, errorMessage))
112  ErrorEx(errorMessage);
113  }
114 
115  static void SpawnInit()
116  {
117  AddSpawnData("Land_Wall_Gate_FenR", "8406.501953 107.736824 12782.338867", "0.000000 0.000000 0.000000");
118  AddSpawnData("Land_Wall_Gate_FenR", "8410.501953 107.736824 12782.338867", "0.000000 0.000000 0.000000");
119  AddSpawnData("Land_Wall_Gate_FenR", "8416.501953 107.736824 12782.338867", "0.000000 0.000000 0.000000");
120  AddSpawnData("Land_Wall_Gate_FenR", "8422.501953 107.736824 12782.338867", "0.000000 0.000000 0.000000");
121  }
122 
123  static void AddSpawnData(string objectName, vector position, vector orientation)
124  {
126  obj.name = objectName;
127  obj.pos[0] = position[0];
128  obj.pos[1] = position[1];
129  obj.pos[2] = position[2];
130 
131  obj.ypr[0] = orientation[0];
132  obj.ypr[1] = orientation[1];
133  obj.ypr[2] = orientation[2];
134 
135  Objects.Insert(obj);
136  }
137 }
GetGame
proto native CGame GetGame()
SpawnDataConverter
Utility class that converts init.c format type of spawn commands to a json file, fill in the SpawnIni...
Definition: objectspawner.c:98
ErrorEx
enum ShapeType ErrorEx
ECE_NOLIFETIME
const int ECE_NOLIFETIME
Definition: centraleconomy.c:29
RF_IGNORE
const int RF_IGNORE
Definition: centraleconomy.c:56
vector
Definition: enconvert.c:105
Object
Definition: objecttyped.c:1
PrintToRPT
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
ObjectSpawnerHandler
Definition: objectspawner.c:1
CfgGameplayHandler
Definition: cfggameplayhandler.c:1
array< string >
ECE_SETUP
const int ECE_SETUP
Definition: centraleconomy.c:9
ECE_UPDATEPATHGRAPH
const int ECE_UPDATEPATHGRAPH
Definition: centraleconomy.c:13
ECE_DYNAMIC_PERSISTENCY
const int ECE_DYNAMIC_PERSISTENCY
Definition: centraleconomy.c:32
ECE_CREATEPHYSICS
const int ECE_CREATEPHYSICS
Definition: centraleconomy.c:16
ObjectSpawnerJson
Definition: objectspawner.c:82
ITEM_SpawnerObject
Definition: objectspawner.c:87
path
string path
Definition: optionselectormultistate.c:135