DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
InventoryLocation.c
Go to the documentation of this file.
1//@NOTE: DO NOT EDIT! enum values are overwritten from c++
4{
11};
12
13//@NOTE: DO NOT EDIT! enum values are overwritten from c++
16{
18 CARGO,
19 HANDS,
24};
25
28{
34 proto native bool IsValid ();
41 proto native int GetType ();
50 proto native EntityAI GetParent ();
60 proto native EntityAI GetItem ();
69 proto native int GetSlot ();
75 proto native int GetIdx ();
81 proto native int GetRow ();
87 proto native int GetCol ();
93 proto native bool GetFlip ();
99 proto native vector GetPos ();
105 proto native void GetDir (out float dir[4]);
106
113 proto native void SetGround (EntityAI e, vector mat[4]);
121 proto native void SetGroundEx (EntityAI e, vector pos, float dir[4]);
129 proto native void SetAttachment (notnull EntityAI parent, EntityAI e, int slotId);
130
139 proto native void SetCargoAuto (notnull CargoBase cargo, EntityAI e, int row, int col, bool flip);
140
150 proto native void SetCargo (notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip);
163 proto native void SetProxyCargo (notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip);
170 proto native void SetHands (notnull EntityAI parent, EntityAI e);
171
176 proto native void SetParent (notnull EntityAI parent);
181 proto native void SetItem (notnull EntityAI item);
182
183 // direct set methods
184 proto native void SetSlot (int slotId);
185 proto native void SetIndex (int idx);
186 proto native void SetRow (int row);
187 proto native void SetCol (int col);
188 proto native void SetFlip (bool flip);
189
193 proto native void Reset ();
194
195 proto native bool CompareLocationOnly (notnull InventoryLocation other);
196
201 proto native bool CollidesWith (notnull InventoryLocation rhs);
202
209 proto native InventoryLocation Copy (notnull InventoryLocation rhs);
216 proto native InventoryLocation CopyLocationFrom (notnull InventoryLocation rhs, bool copyFlip);
217
219 {
220 if (loc)
221 return loc.DumpToString();
222 return "{ null }";
223 }
224
225 string DumpToString ()
226 {
227 string res = "{ type=" + typename.EnumToString(InventoryLocationType, GetType());
228 switch (GetType())
229 {
230 case InventoryLocationType.UNKNOWN:
231 {
232 break;
233 }
234 case InventoryLocationType.GROUND:
235 {
236 res = res + " item=" + Object.GetDebugName(GetItem());
237 vector pos = GetPos();
238 float dir[4];
239 GetDir(dir);
240 res = res + " pos=(" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")";
241 res = res + " dir=(" + dir[0] + ", " + dir[1] + ", " + dir[2] + ", " + dir[3] + ")";
242 break;
243 }
244 case InventoryLocationType.ATTACHMENT:
245 {
246 res = res + " item=" + Object.GetDebugName(GetItem());
247 res = res + " parent=" + Object.GetDebugName(GetParent());
248 res = res + " slot=" + GetSlot();
249 break;
250 }
251 case InventoryLocationType.CARGO:
252 {
253 res = res + " item=" + Object.GetDebugName(GetItem());
254 res = res + " parent=" + Object.GetDebugName(GetParent());
255 res = res + " idx=" + GetIdx() + " row=" + GetRow() + " col=" + GetCol() + " f=" + GetFlip();
256 break;
257 }
258 case InventoryLocationType.HANDS:
259 {
260 res = res + " item=" + Object.GetDebugName(GetItem());
261 res = res + " parent=" + Object.GetDebugName(GetParent());
262 break;
263 }
264 case InventoryLocationType.PROXYCARGO:
265 {
266 res = res + " item=" + Object.GetDebugName(GetItem());
267 res = res + " parent=" + Object.GetDebugName(GetParent());
268 res = res + " idx=" + GetIdx() + " row=" + GetRow() + " col=" + GetCol() + " f=" + GetFlip();
269 break;
270 }
271 default:
272 {
273 res = res + "??";
274 break;
275 }
276 }
277 res = res + " }";
278 return res;
279 }
280
282 {
283 EntityAI parent;
284 EntityAI item;
285 int type = 0;
286 int idx = -1;
287 int row = -1;
288 int col = -1;
289 bool flp = false;
290 if (!ctx.Read(type))
291 return false;
292
293 switch (type)
294 {
295 case InventoryLocationType.UNKNOWN:
296 {
297 break;
298 }
299 case InventoryLocationType.GROUND:
300 {
301 if (!ctx.Read(item))
302 return false;
303 vector pos;
304 if (!ctx.Read(pos))
305 return false;
306
307 float dir[4];
308 if (!ctx.Read(dir))
309 return false;
310
311 if (!item)
312 break; // item is not in bubble
313
314 SetGroundEx(item, pos, dir);
315 break;
316 }
317 case InventoryLocationType.ATTACHMENT:
318 {
319 if (!ctx.Read(parent))
320 return false;
321 if (!ctx.Read(item))
322 return false;
323 int slot;
324 if (!ctx.Read(slot))
325 return false;
326
327 if (!parent || !item)
328 break; // parent or item is not in bubble
329
330 SetAttachment(parent, item, slot);
331 break;
332 }
333 case InventoryLocationType.CARGO:
334 {
335 if (!ctx.Read(parent))
336 return false;
337 if (!ctx.Read(item))
338 return false;
339 if (!ctx.Read(idx))
340 return false;
341 if (!ctx.Read(row))
342 return false;
343 if (!ctx.Read(col))
344 return false;
345 if (!ctx.Read(flp))
346 return false;
347
348 if (!parent || !item)
349 break; // parent or item is not in bubble
350
351 SetCargo(parent, item, idx, row, col, flp);
352 break;
353 }
354 case InventoryLocationType.HANDS:
355 {
356 if (!ctx.Read(parent))
357 return false;
358 if (!ctx.Read(item))
359 return false;
360
361 if (!parent || !item)
362 break; // parent or item is not in bubble
363
364 SetHands(parent, item);
365 break;
366 }
367 case InventoryLocationType.PROXYCARGO:
368 {
369 if (!ctx.Read(parent))
370 return false;
371 if (!ctx.Read(item))
372 return false;
373 if (!ctx.Read(idx))
374 return false;
375 if (!ctx.Read(row))
376 return false;
377 if (!ctx.Read(col))
378 return false;
379 if (!ctx.Read(flp))
380 return false;
381
382 if (!parent || !item)
383 break; // parent or item is not in bubble
384
385 SetProxyCargo(parent, item, idx, row, col, flp);
386 break;
387 }
388 default:
389 {
390 Error("ReadFromContext - really unknown location type, this should not happen, type=" + type);
391 return false;
392 }
393 }
394 return true;
395 }
396
398 {
399 if (!ctx.Write(GetType()))
400 {
401 Error("InventoryLocation::WriteToContext - cannot write to context! failed to write type");
402 return false;
403 }
404
405 switch (GetType())
406 {
407 case InventoryLocationType.UNKNOWN:
408 {
409 break;
410 }
411 case InventoryLocationType.GROUND:
412 {
413 if (!ctx.Write(GetItem()))
414 {
415 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=item");
416 return false;
417 }
418
419 vector pos = GetPos();
420 if (!ctx.Write(pos))
421 {
422 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=pos");
423 return false;
424 }
425
426 float dir[4];
427 GetDir(dir);
428 if (!ctx.Write(dir))
429 {
430 Error("InventoryLocation::WriteToContext - cannot write to context! failed GND, arg=dir");
431 return false;
432 }
433
434 break;
435 }
436 case InventoryLocationType.ATTACHMENT:
437 {
438 if (!ctx.Write(GetParent()))
439 {
440 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=parent");
441 return false;
442 }
443 if (!ctx.Write(GetItem()))
444 {
445 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=item");
446 return false;
447 }
448 if (!ctx.Write(GetSlot()))
449 {
450 Error("InventoryLocation::WriteToContext - cannot write to context! failed ATT, arg=slot");
451 return false;
452 }
453 break;
454 }
455 case InventoryLocationType.CARGO:
456 {
457 if (!ctx.Write(GetParent()))
458 {
459 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=parent");
460 return false;
461 }
462 if (!ctx.Write(GetItem()))
463 {
464 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=item");
465 return false;
466 }
467 if (!ctx.Write(GetIdx()))
468 {
469 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=idx");
470 return false;
471 }
472 if (!ctx.Write(GetRow()))
473 {
474 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=row");
475 return false;
476 }
477 if (!ctx.Write(GetCol()))
478 {
479 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=col");
480 return false;
481 }
482 if (!ctx.Write(GetFlip()))
483 {
484 Error("InventoryLocation::WriteToContext - cannot write to context! failed CGO, arg=flp");
485 return false;
486 }
487 break;
488 }
489 case InventoryLocationType.HANDS:
490 {
491 if (!ctx.Write(GetParent()))
492 {
493 Error("InventoryLocation::WriteToContext - cannot write to context! failed HND, arg=parent");
494 return false;
495 }
496 if (!ctx.Write(GetItem()))
497 {
498 Error("InventoryLocation::WriteToContext - cannot write to context! failed HND, arg=item");
499 return false;
500 }
501 break;
502 }
503 case InventoryLocationType.PROXYCARGO:
504 {
505 if (!ctx.Write(GetParent()))
506 {
507 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=parent");
508 return false;
509 }
510 if (!ctx.Write(GetItem()))
511 {
512 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=item");
513 return false;
514 }
515 if (!ctx.Write(GetIdx()))
516 {
517 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=idx");
518 return false;
519 }
520 if (!ctx.Write(GetRow()))
521 {
522 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=row");
523 return false;
524 }
525 if (!ctx.Write(GetCol()))
526 {
527 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=col");
528 return false;
529 }
530 if (!ctx.Write(GetFlip()))
531 {
532 Error("InventoryLocation::WriteToContext - cannot write to context! failed PXY, arg=flp");
533 return false;
534 }
535
536 break;
537 }
538 default:
539 {
540 Error("WriteToContext - really unknown location type, this should not happen, type=" + GetType());
541 return false;
542 }
543 }
544 return true;
545 }
546};
547
549{
550 if (loc)
551 {
552 if (!ctx.Write(true))
553 {
554 Error("OptionalLocationWriteToContext - cannot write 1 to context!");
555 return false;
556 }
557 return loc.WriteToContext(ctx);
558 }
559 else
560 {
561 if (!ctx.Write(false))
562 {
563 Error("OptionalLocationWriteToContext - cannot write 0 to context!");
564 return false;
565 }
566 }
567 return true;
568}
569
571{
572 bool present = false;
573 if (!ctx.Read(present))
574 {
575 Error("OptionalLocationReadFromContext - cannot read bool from context!");
576 return false;
577 }
578
579 if (!present)
580 return true;
581
582 loc = new InventoryLocation;
583 if (!loc.ReadFromContext(ctx))
584 {
585 Error("OptionalLocationReadFromContext - cannot read (present) inventorylocation from context!");
586 return false;
587 }
588 return true;
589}
FindInventoryLocationType
flags for searching locations in inventory
@ PROXYCARGO
cargo of a large object (building,...)
@ ANY
ATT | CGO | PXY | HND.
@ ANY_CARGO
CGO | PXY.
@ HANDS
hands of another entity
@ CARGO
cargo of another entity
@ NO_SLOT_AUTO_ASSIGN
skips auto-assign test
@ ATTACHMENT
< ground
bool OptionalLocationReadFromContext(out InventoryLocation loc, notnull ParamsReadContext ctx)
InventoryLocationType
types of Inventory Location
@ UNKNOWN
unknown, usually freshly created object
@ GROUND
bool OptionalLocationWriteToContext(InventoryLocation loc, notnull ParamsWriteContext ctx)
represents base for cargo storage for entities
Definition Cargo.c:7
InventoryLocation.
proto native void SetCol(int col)
proto native int GetType()
returns type of InventoryLocation
proto native vector GetPos()
returns position of item in world if type is Ground
proto native void SetParent(notnull EntityAI parent)
proto native bool IsValid()
verify current set inventory location
proto native void SetRow(int row)
proto native int GetCol()
returns column of cargo if current type is Cargo / ProxyCargo
proto native void SetCargoAuto(notnull CargoBase cargo, EntityAI e, int row, int col, bool flip)
based on Cargo.IsProxyCargo uses SetProxyCargo or SetCargo respectively
proto native void SetGroundEx(EntityAI e, vector pos, float dir[4])
sets current inventory location type to Ground with transformation mat
proto native int GetRow()
returns row of cargo if current type is Cargo / ProxyCargo
proto native void SetCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip)
sets current inventory location type to Cargo with coordinates (idx, row, col)
proto native InventoryLocation CopyLocationFrom(notnull InventoryLocation rhs, bool copyFlip)
copies location to another location without m_item member
proto native void SetGround(EntityAI e, vector mat[4])
sets current inventory location type to Ground with transformation mat
proto native bool CollidesWith(notnull InventoryLocation rhs)
checks if inventory locations collides each with other
proto native bool CompareLocationOnly(notnull InventoryLocation other)
proto native int GetIdx()
returns index of cargo if current type is Cargo / ProxyCargo
proto native void SetProxyCargo(notnull EntityAI parent, EntityAI e, int idx, int row, int col, bool flip)
sets current inventory location type to ProxyCargo with coordinates (idx, row, col) @NOTE: typical us...
proto native void SetHands(notnull EntityAI parent, EntityAI e)
sets current inventory location type to Hands
proto native InventoryLocation Copy(notnull InventoryLocation rhs)
copies location data to another location
proto native void SetIndex(int idx)
proto native void SetSlot(int slotId)
proto native void SetFlip(bool flip)
proto native EntityAI GetParent()
returns parent of current inventory location
bool ReadFromContext(ParamsReadContext ctx)
proto native void SetAttachment(notnull EntityAI parent, EntityAI e, int slotId)
sets current inventory location type to Attachment with slot id set to <slotId>
proto native void GetDir(out float dir[4])
returns direction of item in world if type is Ground
proto native EntityAI GetItem()
returns item of current inventory location
proto native void Reset()
proto native bool GetFlip()
returns flip status of cargo
proto native int GetSlot()
returns slot id if current type is Attachment
static string DumpToStringNullSafe(InventoryLocation loc)
proto native void SetItem(notnull EntityAI item)
bool WriteToContext(ParamsWriteContext ctx)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90