DayZ
1.24
Loading...
Searching...
No Matches
PresetHandlers.c
Go to the documentation of this file.
1
#ifdef DEVELOPER
2
//----------------------------------------------------------
3
//Class names need to match the preset name + _Preset suffix
4
//----------------------------------------------------------
5
6
7
//TEMPLATE:
8
/*
9
10
class Farmer_Preset extends PresetSpawnBase
11
{
12
override void OnPresetSpawn(PlayerBase player)
13
{
14
//m_ItemsInventory -> contains all items in player inventory
15
}
16
}
17
18
*/
19
20
//---------------------------------------------
21
22
class
FreshSpawn_Preset
extends
PresetSpawnBase
23
{
24
override
void
OnPresetSpawn
(
PlayerBase
player
)
25
{
26
FindAndTakeToHandsFromInventory
(
"Plum"
);
27
}
28
}
29
//---------------------------------------------
30
31
class
Farmer_Preset
extends
PresetSpawnBase
32
{
33
override
void
OnPresetSpawn
(
PlayerBase
player
)
34
{
35
36
}
37
}
38
//---------------------------------------------
39
class
AntiHazard_Preset
extends
PresetSpawnBase
40
{
41
override
void
OnPresetSpawn
(
PlayerBase
player
)
42
{
43
EntityAI
mask
=
FindItem
(
"AirborneMask"
);
44
45
if
(
mask
)
46
{
47
auto
debugParams
=
DebugSpawnParams
.WithPlayer(
player
);
48
mask
.OnDebugSpawnEx(
debugParams
);
49
}
50
51
}
52
}
53
//---------------------------------------------
54
55
class
Update117_Preset
extends
PresetSpawnBase
56
{
57
vector
randompos
;
58
override
void
OnPresetSpawn
(
PlayerBase
player
)
59
{
60
randompos
=
player
.GetPosition();
61
foreach
(
EntityAI
itm
:
m_ItemsPreset
)
62
{
63
if
(
itm
)
64
{
65
vector
itempos
;
66
itempos
[0] =
Math
.
RandomFloat
(-1, 1);
67
itempos
[2] =
Math
.
RandomFloat
(-1, 1);
68
69
ItemBase
itmBase
=
ItemBase
.Cast(
itm
);
70
71
itmBase
.SetPosition(
randompos
+
itempos
);
72
itmBase
.SetQuantity(100);
73
}
74
}
75
}
76
}
77
78
//---------------------------------------------
79
80
class
Update118_Preset
extends
PresetSpawnBase
81
{
82
vector
randompos
;
83
override
void
OnPresetSpawn
(
PlayerBase
player
)
84
{
85
randompos
=
player
.GetPosition();
86
foreach
(
EntityAI
itm
:
m_ItemsPreset
)
87
{
88
if
(
itm
)
89
{
90
vector
itempos
;
91
itempos
[0] =
Math
.
RandomFloat
(-1, 1);
92
itempos
[2] =
Math
.
RandomFloat
(-1, 1);
93
94
ItemBase
itmBase
=
ItemBase
.Cast(
itm
);
95
96
itmBase
.SetPosition(
randompos
+
itempos
);
97
itmBase
.SetQuantity(100);
98
}
99
}
100
}
101
}
102
//---------------------------------------------
103
104
class
BBMaterials_Preset
extends
PresetSpawnBase
105
{
106
vector
randompos
;
107
override
void
OnPresetSpawn
(
PlayerBase
player
)
108
{
109
randompos
=
player
.GetPosition();
110
foreach
(
EntityAI
itm
:
m_ItemsPreset
)
111
{
112
if
(
itm
)
113
{
114
vector
itempos
;
115
itempos
[0] =
Math
.
RandomFloat
(-1, 1);
116
itempos
[2] =
Math
.
RandomFloat
(-1, 1);
117
itm
.SetPosition(
randompos
+
itempos
);
118
}
119
}
120
}
121
}
122
//---------------------------------------------
123
124
125
class
Military_Light_Preset
extends
PresetSpawnBase
126
{
127
override
void
OnPresetSpawn
(
PlayerBase
player
)
128
{
129
EntityAI
weapon
=
FindItem
(
"AK101"
);
130
131
auto
debugParams
=
DebugSpawnParams
.WithPlayer(
player
);
132
weapon
.OnDebugSpawnEx(
debugParams
);
133
134
FindAndTakeToHandsFromInventory
(
"AK101"
);
135
}
136
}
137
138
139
//---------------------------------------------
140
//------------------ BASE ---------------------
141
//---------------------------------------------
142
143
class
PresetSpawnBase
144
{
145
ref
array<EntityAI>
m_ItemsInventory
=
new
array<EntityAI>
;
//inventory items
146
HumanInventory
m_Inventory
;
147
PlayerBase
m_Player
;
148
array<EntityAI>
m_ItemsPreset
;
//all items spawned from this preset
149
//---------------------------------------------
150
151
void
Init
(
PlayerBase
player
)
152
{
153
m_Player
=
player
;
154
m_Inventory
=
player
.GetHumanInventory();
155
m_ItemsPreset
=
player
.m_PresetItems;
156
m_Inventory
.EnumerateInventory(
InventoryTraversalType
.INORDER,
m_ItemsInventory
);
157
OnPresetSpawn
(
player
);
158
159
foreach
(
auto
item
:
m_ItemsPreset
)
160
Print
(
item
);
161
}
162
163
//---------------------------------------------
164
165
void
OnPresetSpawn
(
PlayerBase
player
)
166
{
167
168
}
169
//---------------------------------------------
170
171
void
TakeToHands
(
EntityAI
item
)
172
{
173
if
(
GetGame
().IsMultiplayer() &&
m_Player
.GetInstanceType() !=
DayZPlayerInstanceType
.INSTANCETYPE_SERVER)
//throws assert otherwise
174
return
;
175
if
(
GetGame
().IsDedicatedServer())
176
m_Player
.TakeEntityToHandsImpl(
InventoryMode
.SERVER,
item
);
177
else
178
m_Player
.TakeEntityToHandsImpl(
InventoryMode
.PREDICTIVE,
item
);
179
180
}
181
182
void
FindAndTakeToHandsFromInventory
(
string
classname
)
183
{
184
m_Inventory
.EnumerateInventory(
InventoryTraversalType
.INORDER,
m_ItemsInventory
);
185
foreach
(
EntityAI
item
:
m_ItemsInventory
)
186
{
187
if
(
item
.ClassName() ==
classname
)
188
{
189
TakeToHands
(
item
);
190
return
;
191
}
192
}
193
}
194
195
EntityAI
FindItem
(
string
classname
)
196
{
197
m_Inventory
.EnumerateInventory(
InventoryTraversalType
.INORDER,
m_ItemsInventory
);
198
foreach
(
EntityAI
item
:
m_ItemsInventory
)
199
{
200
if
(
item
.ClassName() ==
classname
)
201
return
item
;
202
}
203
return
null
;
204
}
205
206
}
207
208
#endif
InventoryMode
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition
Inventory.c:22
Init
override Widget Init()
Definition
DayZGame.c:120
m_Player
DayZPlayer m_Player
Definition
Hand_Events.c:42
m_Inventory
enum ScreenWidthType m_Inventory
EntityAI
Definition
Building.c:6
HumanInventory
inventory for plain man/human
Definition
HumanInventory.c:10
ItemBase
Definition
InventoryItem.c:697
Math
Definition
EnMath.c:7
Param3
Definition
EntityAI.c:95
PlayerBase
Definition
PlayerBaseClient.c:2
vector
Definition
EnConvert.c:106
DayZPlayerInstanceType
DayZPlayerInstanceType
defined in C++
Definition
dayzplayer.c:1049
InventoryTraversalType
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Definition
gameplay.c:6
GetGame
proto native CGame GetGame()
Print
proto void Print(void var)
Prints content of variable to console/log.
Math::RandomFloat
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
scripts
4_World
Classes
Debug
PresetHandlers.c
Generated by
1.10.0