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