Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
objectspawner.c
Go to the documentation of this file.
1
class
ObjectSpawnerHandler
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
//---------------------------------------------------------------------------------------
33
static
void
SpawnObject
(
ITEM_SpawnerObject
item)
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
=
g_Game
.CreateStaticObjectUsingP3D(item.
name
,
vector
.
ArrayToVec
(item.
pos
),
vector
.
ArrayToVec
(item.
ypr
),scale);
45
}
46
else
47
{
48
int
flags =
ECE_SETUP
|
ECE_UPDATEPATHGRAPH
|
ECE_CREATEPHYSICS
|
ECE_NOLIFETIME
|
ECE_DYNAMIC_PERSISTENCY
;
49
50
if
(item.
enableCEPersistency
)
51
{
52
flags &=
~ECE_DYNAMIC_PERSISTENCY
;
53
flags &=
~ECE_NOLIFETIME
;
54
}
55
56
object
=
g_Game
.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
//---------------------------------------------------------------------------------------
71
static
void
OnGameplayDataHandlerLoad
()
72
{
73
if
(
g_Game
&&
g_Game
.IsServer())
74
{
75
SpawnObjects
();
76
g_Game
.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
95
class
ObjectSpawnerJson
96
{
97
ref
array<ref ITEM_SpawnerObject>
Objects
;
98
};
99
100
class
ITEM_SpawnerObject
101
{
102
string
name
;
103
float
pos
[3];
104
float
ypr
[3];
105
float
scale
;
106
bool
enableCEPersistency
;
107
string
customString
;
108
};
109
110
112
class
SpawnDataConverter
113
{
114
static
ref
array<ref ITEM_SpawnerObject>
Objects
=
new
array<ref ITEM_SpawnerObject>
;
115
static
string
m_Path
=
"$mission:myspawndata.json"
;
116
117
static
void
SpawnObjects
()
118
{
119
Objects
.Clear();
120
SpawnInit
();
121
ObjectSpawnerJson
j =
new
ObjectSpawnerJson
();
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
{
139
ITEM_SpawnerObject
obj =
new
ITEM_SpawnerObject
();
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
}
ECE_SETUP
const int ECE_SETUP
Definition
centraleconomy.c:9
ECE_UPDATEPATHGRAPH
const int ECE_UPDATEPATHGRAPH
Definition
centraleconomy.c:13
RF_IGNORE
const int RF_IGNORE
Definition
centraleconomy.c:56
ECE_DYNAMIC_PERSISTENCY
const int ECE_DYNAMIC_PERSISTENCY
Definition
centraleconomy.c:32
ECE_NOLIFETIME
const int ECE_NOLIFETIME
Definition
centraleconomy.c:29
ECE_CREATEPHYSICS
const int ECE_CREATEPHYSICS
Definition
centraleconomy.c:16
CfgGameplayHandler
Definition
cfggameplayhandler.c:2
CfgGameplayHandler::GetObjectSpawnersArr
static TStringArray GetObjectSpawnersArr()
Definition
cfggameplayhandler.c:141
ITEM_SpawnerObject
Definition
objectspawner.c:101
ITEM_SpawnerObject::ypr
float ypr[3]
Definition
objectspawner.c:104
ITEM_SpawnerObject::scale
float scale
Definition
objectspawner.c:105
ITEM_SpawnerObject::enableCEPersistency
bool enableCEPersistency
Definition
objectspawner.c:106
ITEM_SpawnerObject::pos
float pos[3]
Definition
objectspawner.c:103
ITEM_SpawnerObject::name
string name
Definition
objectspawner.c:102
ITEM_SpawnerObject::customString
string customString
Definition
objectspawner.c:107
Object
Definition
objecttyped.c:2
ObjectSpawnerHandler
Definition
objectspawner.c:2
ObjectSpawnerHandler::OnGameplayDataHandlerLoad
static void OnGameplayDataHandlerLoad()
Definition
objectspawner.c:71
ObjectSpawnerHandler::SpawnObjects
static void SpawnObjects()
Definition
objectspawner.c:11
ObjectSpawnerHandler::SpawnObject
static void SpawnObject(ITEM_SpawnerObject item)
Definition
objectspawner.c:33
ObjectSpawnerHandler::VALID_PATHS
static const ref TStringArray VALID_PATHS
Definition
objectspawner.c:3
ObjectSpawnerHandler::ValidatePath
static bool ValidatePath(string path)
Definition
objectspawner.c:81
ObjectSpawnerJson
Definition
objectspawner.c:96
ObjectSpawnerJson::Objects
ref array< ref ITEM_SpawnerObject > Objects
Definition
objectspawner.c:97
SpawnDataConverter
Utility class that converts init.c format type of spawn commands to a json file, fill in the SpawnIni...
Definition
objectspawner.c:113
SpawnDataConverter::Objects
static ref array< ref ITEM_SpawnerObject > Objects
Definition
objectspawner.c:114
SpawnDataConverter::SpawnObjects
static void SpawnObjects()
Definition
objectspawner.c:117
SpawnDataConverter::m_Path
static string m_Path
Definition
objectspawner.c:115
SpawnDataConverter::AddSpawnData
static void AddSpawnData(string objectName, vector position, vector orientation)
Definition
objectspawner.c:137
SpawnDataConverter::SpawnInit
static void SpawnInit()
Definition
objectspawner.c:129
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
vector
Definition
enconvert.c:119
vector::ArrayToVec
static vector ArrayToVec(float arr[])
Convert static array of floats into a vector.
Definition
enconvert.c:515
g_Game
DayZGame g_Game
Definition
dayzgame.c:3942
PrintToRPT
proto void PrintToRPT(void var)
Prints content of variable to RPT file (performance warning - each write means fflush!...
ErrorEx
enum ShapeType ErrorEx
TStringArray
array< string > TStringArray
Definition
enscript.c:712
string::Contains
bool Contains(string sample)
Returns true if sample is substring of string.
Definition
enstring.c:286
path
string path
Definition
optionselectormultistate.c:142
Games
Dayz
scripts
3_game
objectspawner.c
Generated by
1.17.0