DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
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 //float profStart = GetGame().GetTime();
9 {
11 foreach (string spawner_json: arr)
12 {
13 string path = "$mission:"+spawner_json;
14
15 if (FileExist( path ))
16 {
17 //float profStartLoad = GetGame().GetTime();
18 ObjectSpawnerJson spawner;
19 JsonFileLoader<ObjectSpawnerJson>.JsonLoadFile( path, spawner );
20
21 //float resultLoad = GetGame().GetTime() - profStartLoad;
22 //Print("LOAD took " + resultLoad);
23 foreach (ITEM_SpawnerObject o: spawner.Objects)
24 {
25 SpawnObject(o);
26 }
27 }
28 }
29 }
30 //float result = GetGame().GetTime() - profStart;
31 //Print("OVERALL took " + result);
32 }
33 //---------------------------------------------------------------------------------------
35 {
36 Object object;
37
38 float scale = item.scale;
39 if (scale == 0)
40 scale = 1;
41
42 if (item.name.Contains("\\") || item.name.Contains("/"))
43 {
44 if (ValidatePath(item.name))
45 object = GetGame().CreateStaticObjectUsingP3D(item.name, vector.ArrayToVec(item.pos), vector.ArrayToVec(item.ypr),scale);
46 }
47 else
48 {
50
51 if (item.enableCEPersistency)
52 {
53 flags &= ~ECE_DYNAMIC_PERSISTENCY;
54 flags &= ~ECE_NOLIFETIME;
55 }
56
57 object = GetGame().CreateObjectEx(item.name, vector.ArrayToVec(item.pos), flags, RF_IGNORE);
58 if ( object )
59 {
60 object.SetOrientation( vector.ArrayToVec(item.ypr));
61 if (item.scale != 1)
62 object.SetScale(scale);
63 }
64 }
65
66 if (!object)
67 PrintToRPT("Object spawner failed to spawn "+item.name);
68 }
69 //---------------------------------------------------------------------------------------
71 {
74 }
75
76 //---------------------------------------------------------------------------------------
77 static bool ValidatePath(string path)
78 {
79 foreach (string p: VALID_PATHS)
80 {
81 if (path.Contains(p))
82 return true;
83 }
84 return false;
85 }
86 //---------------------------------------------------------------------------------------
87};
88
90{
92};
93
95{
96 string name;
97 float pos[3];
98 float ypr[3];
99 float scale;
101};
102
103
106{
108 static string m_Path = "$mission:MySpawnData.json";
109
110 static void SpawnObjects()
111 {
112 Objects.Clear();
113 SpawnInit();
115 j.Objects = Objects;
116 JsonFileLoader<ObjectSpawnerJson>.JsonSaveFile(m_Path, j );
117 }
118
119 static void SpawnInit()
120 {
121 AddSpawnData( "Land_Wall_Gate_FenR", "8406.501953 107.736824 12782.338867", "0.000000 0.000000 0.000000" );
122 AddSpawnData( "Land_Wall_Gate_FenR", "8410.501953 107.736824 12782.338867", "0.000000 0.000000 0.000000" );
123 AddSpawnData( "Land_Wall_Gate_FenR", "8416.501953 107.736824 12782.338867", "0.000000 0.000000 0.000000" );
124 AddSpawnData( "Land_Wall_Gate_FenR", "8422.501953 107.736824 12782.338867", "0.000000 0.000000 0.000000" );
125 }
126
127 static void AddSpawnData(string objectName, vector position, vector orientation)
128 {
130 obj.name = objectName;
131 obj.pos[0] = position[0];
132 obj.pos[1] = position[1];
133 obj.pos[2] = position[2];
134
135 obj.ypr[0] = orientation[0];
136 obj.ypr[1] = orientation[1];
137 obj.ypr[2] = orientation[2];
138
139 Objects.Insert(obj);
140 }
141};
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
proto native Object CreateObjectEx(string type, vector pos, int iFlags, int iRotation=RF_DEFAULT)
Creates object of certain type.
proto native Object CreateStaticObjectUsingP3D(string p3dFilename, vector position, vector orientation, float scale=1.0, bool createLocal=false)
proto native World GetWorld()
static TStringArray GetObjectSpawnersArr()
static void OnGameplayDataHandlerLoad()
static void SpawnObjects()
static void SpawnObject(ITEM_SpawnerObject item)
static bool ValidatePath(string path)
static protected const ref TStringArray VALID_PATHS
ref array< ref ITEM_SpawnerObject > Objects
Utility class that converts init.c format type of spawn commands to a json file, fill in the SpawnIni...
static ref array< ref ITEM_SpawnerObject > Objects
static void SpawnObjects()
static string m_Path
static void AddSpawnData(string objectName, vector position, vector orientation)
static void SpawnInit()
proto native void ProcessMarkedObjectsForPathgraphUpdate()
static vector ArrayToVec(float arr[])
Convert static array of floats into a vector.
Definition EnConvert.c:502
proto native CGame GetGame()
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
proto bool FileExist(string name)
Check existence of file.
bool Contains(string sample)
Returns true if sample is substring of string.
Definition EnString.c:286