DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Hand_Guards.c
Go to the documentation of this file.
1
2
7{
13 bool GuardCondition(HandEventBase e) { return true; }
14};
15
16
17class HandGuardAnd extends HandGuardBase
18{
21
22 void HandGuardAnd(HandGuardBase arg0 = null, HandGuardBase arg1 = null) { m_arg0 = arg0; m_arg1 = arg1; }
23
25 {
26 bool result = m_arg0.GuardCondition(e) && m_arg1.GuardCondition(e);
27
28 #ifdef DEVELOPER
30 {
31 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type() + " && " + m_arg1.Type(), "HandGuardAnd" , "n/a", "GuardCondition", e.m_Player.ToString() );
32 }
33 #endif
34
35 return result;
36 }
37};
38
39class HandGuardNot extends HandGuardBase
40{
42
43 void HandGuardNot(HandGuardBase arg0 = null) { m_arg0 = arg0; }
44
46 {
47 bool result = !m_arg0.GuardCondition(e);
48
49 #ifdef DEVELOPER
51 {
52 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type(), "HandGuardNot" , "n/a", "GuardCondition", e.m_Player.ToString() );
53 }
54 #endif
55 return result;
56 }
57};
58
59class HandGuardOr extends HandGuardBase
60{
63
64 void HandGuardOr(HandGuardBase arg0 = null, HandGuardBase arg1 = null) { m_arg0 = arg0; m_arg1 = arg1; }
65
67 {
68 bool result = m_arg0.GuardCondition(e) || m_arg1.GuardCondition(e);
69
70 #ifdef DEVELOPER
72 {
73 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_arg0.Type() + " || " + m_arg1.Type(), "HandGuardOr" , "n/a", "GuardCondition", e.m_Player.ToString() );
74 }
75 #endif
76 return result;
77 }
78};
79
81{
82 protected Man m_Player;
83 void HandGuardHasItemInEvent(Man p = null) { m_Player = p; }
84
86 {
87 EntityAI eai = e.GetSrcEntity();
88 if (eai != NULL /* && CanTakeInHands*/)
89 {
90 #ifdef DEVELOPER
92 {
93 Debug.InventoryHFSMLog("GuardCondition result: true - " + eai, "HandGuardHasItemInEvent" , "n/a", "GuardCondition", m_Player.ToString() );
94 }
95 #endif
96 return true;
97 }
98
99 #ifdef DEVELOPER
101 {
102 Debug.InventoryHFSMLog("GuardCondition result: false - " + eai, "HandGuardHasItemInEvent" , "n/a", "GuardCondition", m_Player.ToString() );
103 }
104 #endif
105
106 return false;
107 }
108};
109
110class HandGuardHasWeaponInEvent extends HandGuardHasItemInEvent
111{
112 void HandGuardHasWeapoonInEvent (Man p = null) { }
113
115 {
116 EntityAI eai = e.GetSrcEntity();
117 bool result = false;
118 if (eai)
119 {
120 if (eai.IsWeapon())
121 {
122 result = true;
123 }
124 }
125 #ifdef DEVELOPER
127 {
128 Debug.InventoryHFSMLog("GuardCondition result: " + result,"HandGuardHasWeaponInEvent", "n/a", "GuardCondition", e.m_Player.ToString() );
129 }
130 #endif
131 return result;
132 }
133};
134
135class HandGuardIsSameItemInHands extends HandGuardBase
136{
137 protected Man m_Player;
138 void HandGuardIsSameItemInHands(Man p = null) { m_Player = p; }
139
141 {
142 bool result = false;
143 if (e.GetSrcEntity() == m_Player.GetHumanInventory().GetEntityInHands())
144 {
145 result = true;
146 }
147
148 #ifdef DEVELOPER
150 {
151 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - srcItem = " + e.GetSrcEntity() + " hnd= " + m_Player.GetHumanInventory().GetEntityInHands(), "HandGuardIsSameItemInHands" , "n/a", "GuardCondition", e.m_Player.ToString() );
152 }
153 #endif
154 return result;
155 }
156};
157
158class HandGuardHasDestroyedItemInHands extends HandGuardBase
159{
160 protected Man m_Player;
161 void HandGuardHasDestroyedItemInHands(Man p = null) { m_Player = p; }
162
164 {
165 EntityAI hnd = m_Player.GetHumanInventory().GetEntityInHands();
166 if (e.GetSrcEntity())
167 {
168 if (e.GetSrcEntity() == hnd)
169 {
170 #ifdef DEVELOPER
172 {
173 Debug.InventoryHFSMLog("GuardCondition result: true - has same entity in hands " + hnd, "HandGuardHasDestroyedItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
174 }
175 #endif
176 return true;
177 }
178
179 if (hnd == null)
180 {
181 #ifdef DEVELOPER
183 {
184 Debug.InventoryHFSMLog("GuardCondition result: true - hands already empty", "HandGuardHasDestroyedItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
185 }
186 #endif
187 return true;
188 }
189 }
190 else
191 {
192 #ifdef DEVELOPER
194 {
195 Debug.InventoryHFSMLog("GuardCondition result: true - hands already empty and item destroyed", "HandGuardHasDestroyedItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
196 }
197 #endif
198 return true;
199 }
200 #ifdef DEVELOPER
202 {
203 Debug.InventoryHFSMLog("GuardCondition result: false - destroyed entity not in hands", "HandGuardHasDestroyedItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
204 }
205 #endif
206 return false;
207 }
208};
209
210class HandGuardHasItemInHands extends HandGuardBase
211{
212 protected Man m_Player;
213 void HandGuardHasItemInHands(Man p = null) { m_Player = p; }
214
216 {
217 bool result = false;
218 if (m_Player.GetHumanInventory().GetEntityInHands())
219 {
220 result = true;
221 }
222
223 #ifdef DEVELOPER
225 {
226 Debug.InventoryHFSMLog("GuardCondition result: " + result + " - " + m_Player.GetHumanInventory().GetEntityInHands(), "HandGuardHasItemInHands" , "n/a", "GuardCondition", m_Player.ToString() );
227 }
228 #endif
229 return result;
230 }
231};
232
233class HandGuardHasRoomForItem extends HandGuardBase
234{
235 protected Man m_Player;
236 void HandGuardHasRoomForItem(Man p = null) { m_Player = p; }
237
239 {
240 if (e.GetDst() && e.GetDst().IsValid())
241 {
242 if ( !GetGame().IsDedicatedServer())
243 {
244 if (m_Player)
245 m_Player.GetHumanInventory().ClearInventoryReservationEx(e.GetDst().GetItem(),e.GetDst());
246 }
247
248 if (!GameInventory.LocationTestAddEntity(e.GetDst(), false, true, true, true, true, false))
249 {
250 #ifdef DEVELOPER
252 {
253 Debug.InventoryHFSMLog("GuardCondition result: false - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()), "HandGuardHasRoomForItem" , "n/a", "GuardCondition", m_Player.ToString() );
254 }
255 #endif
256 //hndDebugPrint("[hndfsm] HandGuardHasRoomForItem - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()));
257 //Error("[hndfsm] HandGuardHasRoomForItem - no room at dst=" + InventoryLocation.DumpToStringNullSafe(e.GetDst()));
258 return false;
259 }
260
261
262 if ( !GetGame().IsDedicatedServer())
263 {
264 if (m_Player)
265 m_Player.GetHumanInventory().AddInventoryReservationEx(e.GetDst().GetItem(), e.GetDst(), GameInventory.c_InventoryReservationTimeoutShortMS);
266 }
267
268 #ifdef DEVELOPER
270 {
271 Debug.InventoryHFSMLog("GuardCondition result: true", "HandGuardHasRoomForItem" , "n/a", "GuardCondition", m_Player.ToString() );
272 }
273 #endif
274 return true;
275 }
276
277 #ifdef DEVELOPER
279 {
280 Debug.InventoryHFSMLog("GuardCondition result: false - e.m_Dst is null", "HandGuardHasRoomForItem" , "n/a", "GuardCondition", m_Player.ToString() );
281 }
282 #endif
283
284 return false;
285 }
286};
287
288class HandGuardCanMove extends HandGuardBase
289{
290 protected Man m_Player;
291 void HandGuardCanMove(Man p = null) { m_Player = p; }
292
294 {
295 HandEventMoveTo es = HandEventMoveTo.Cast(e);
296
297 bool result = GameInventory.LocationCanMoveEntity(es.GetSrc(), es.GetDst());
298
299 #ifdef DEVELOPER
301 {
302 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanMove" , "n/a", "GuardCondition", m_Player.ToString() );
303 }
304 #endif
305
306 return result;
307 }
308};
309
310class HandGuardCanSwap extends HandGuardBase
311{
312 protected Man m_Player;
313 void HandGuardCanSwap(Man p = NULL) { m_Player = p; }
314
316 {
317 HandEventSwap es = HandEventSwap.Cast(e);
318 bool result = GameInventory.CanSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Src2.GetItem());
319
320 #ifdef DEVELOPER
322 {
323 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanSwap" , "n/a", "GuardCondition", m_Player.ToString() );
324 }
325 #endif
326 //hndDebugPrint("[hndfsm] HandGuardCanSwap guard - cannot swap");
327 return result;
328 }
329};
330
331class HandGuardCanForceSwap extends HandGuardBase
332{
333 protected Man m_Player;
334 void HandGuardCanForceSwap(Man p = NULL) { m_Player = p; }
335
337 {
338 HandEventForceSwap es = HandEventForceSwap.Cast(e);
339
340 bool result = GameInventory.CanSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Src2.GetItem());
341 if (!result && es.m_Dst2)
342 result = GameInventory.CanForceSwapEntitiesEx(es.GetSrc().GetItem(), es.m_Dst, es.m_Src2.GetItem(), es.m_Dst2);
343
344 #ifdef DEVELOPER
346 {
347 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardCanForceSwap" , "n/a", "GuardCondition", m_Player.ToString() );
348 }
349 #endif
350
351 return result;
352 }
353};
354
355class HandGuardInstantForceSwap extends HandGuardBase
356{
357 protected Man m_Player;
358 void HandGuardInstantForceSwap(Man p = NULL) { m_Player = p; }
359
361 {
362 HandEventForceSwap es = HandEventForceSwap.Cast(e);
363
364 InventoryLocation src1 = es.m_Src;
365 InventoryLocation dst2 = es.m_Dst2;
366
367 bool result = false;
368 if (src1.GetType() == InventoryLocationType.CARGO && dst2.GetType() == InventoryLocationType.CARGO)
369 {
370 if (src1.GetParent() == dst2.GetParent())
371 {
372 result = true;
373 }
374 }
375
376 #ifdef DEVELOPER
378 {
379 Debug.InventoryHFSMLog("GuardCondition result: " + result, "HandGuardInstantForceSwap" , "n/a", "GuardCondition", m_Player.ToString() );
380 }
381 #endif
382
383 return result;
384 }
385};
386
388
DayZPlayer m_Player
Definition Hand_Events.c:42
InventoryLocationType
types of Inventory Location
Definition Debug.c:14
static void InventoryHFSMLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Definition Debug.c:158
script counterpart to engine's class Inventory
Definition Inventory.c:77
static bool CanForceSwapEntitiesEx(notnull EntityAI item1, InventoryLocation item1_dst, notnull EntityAI item2, out InventoryLocation item2_dst)
Definition Inventory.c:638
const int c_InventoryReservationTimeoutShortMS
Definition Inventory.c:684
static bool CanSwapEntitiesEx(notnull EntityAI item1, notnull EntityAI item2)
Definition Inventory.c:601
static proto native bool LocationCanMoveEntity(notnull InventoryLocation src, notnull InventoryLocation dst)
queries if the entity contained in inv_loc.m_item can be moved to another location This is a shorthan...
static proto native bool LocationTestAddEntity(notnull InventoryLocation inv_loc, bool do_resevation_check, bool do_item_check, bool do_lock_check, bool do_occupancy_test, bool do_script_check, bool do_script_load_check)
test if the entity contained in inv_loc.m_item can be added to ground/attachment/cargo/hands/....
Abstracted event, not to be used, only inherited.
override InventoryLocation GetDst()
override bool GuardCondition(HandEventBase e)
Definition Hand_Guards.c:24
void HandGuardNot(HandGuardBase arg0=null)
Definition Hand_Guards.c:43
void HandGuardCanForceSwap(Man p=NULL)
ref HandGuardBase m_arg0
Definition Hand_Guards.c:19
void HandGuardCanMove(Man p=null)
void HandGuardHasDestroyedItemInHands(Man p=null)
void HandGuardOr(HandGuardBase arg0=null, HandGuardBase arg1=null)
Definition Hand_Guards.c:64
protected Man m_Player
Definition Hand_Guards.c:82
bool GuardCondition(HandEventBase e)
Definition Hand_Guards.c:13
void HandGuardHasItemInEvent(Man p=null)
Definition Hand_Guards.c:83
void HandGuardInstantForceSwap(Man p=NULL)
void HandGuardIsSameItemInHands(Man p=null)
void HandGuardAnd(HandGuardBase arg0=null, HandGuardBase arg1=null)
Definition Hand_Guards.c:22
void HandGuardHasRoomForItem(Man p=null)
ref HandGuardBase m_arg1
Definition Hand_Guards.c:20
void HandGuardCanSwap(Man p=NULL)
void HandGuardHasItemInHands(Man p=null)
override bool GuardCondition(HandEventBase e)
void HandGuardHasWeapoonInEvent(Man p=null)
InventoryLocation.
proto native int GetType()
returns type of InventoryLocation
proto native bool IsValid()
verify current set inventory location
proto native EntityAI GetParent()
returns parent of current inventory location
proto native EntityAI GetItem()
returns item of current inventory location
static string DumpToStringNullSafe(InventoryLocation loc)
static bool IsInventoryHFSMLogEnable()
Definition Debug.c:620
proto native CGame GetGame()