Jump to content
palatine

Help: noob script: transfer dead unit inventory

Recommended Posts

Hi guys, im trying to create a script that transfers inventory of dead soldier to a container name "MyBox";

 

1) Im trying this, but it will only transfer the main weapon of dead unit to "MyBox"

{
  [_x, MyBox] call W_fnc_doTransfer; // this function using simple addItemCargo from _x to _Dest
} forEach (nearestObjects [getPos player, ["WeaponHolderSimulated", "GroundWeaponHolder", "Default"], 400] );


 

2) I'm trying this below, but it won't transfer from dead unit inventory. When trying in alive unit, it work.

 

{
  _source = _this select 0;
  _dest = _this select 1;

  if (!alive _x) then {
    // sample code to transfer from Vest to Box
    _itemSource = count (vestItems (_source));
    systemChat format ["VEST -> Target: %1 items.", _itemSource];

    _itemDest = count (itemCargo _dest) + count (magazineCargo _dest) + count (weaponCargo _dest);
    {
      _dest addItemCargo [_x, 1];
    } forEach vestItems (_source);
            
    if ( (_itemDest + _itemSource) == (count (itemCargo _dest) + count (magazineCargo _dest) + count (weaponCargo _dest)) ) then {
      clearItemCargo vestContainer (_source);
      clearMagazineCargo vestContainer (_source);
      clearWeaponCargo vestContainer (_source);
      systemChat format ["%1 item(s) transferred.", _itemSource];
    } else {
      systemChat format ["Error detected during items transfer."];
    };
  };
} forEach ( (position player) nearEntities ["Man", 400] );

 

Any suggestion?

Thanks

 

  • Like 1

Share this post


Link to post
Share on other sites

Try these commands to get stuff off from dead unit:

 

weapons _man;
magazinesAmmoFull _man;
items _man;

 

Share this post


Link to post
Share on other sites
3 hours ago, palatine said:

1) Im trying this, but it will only transfer the main weapon of dead unit to "MyBox"

 

the "WeaponHolderSimulated" only holds the rifle (or maybe other weapon) which the unit dropped at death.

 

Share this post


Link to post
Share on other sites
2 hours ago, gc8 said:

Try these commands to get stuff off from dead unit:

 


weapons _man;
magazinesAmmoFull _man;
items _man;

 

 

Hi @gc8, thanks... but no luck :(
I tried something like this and so for magazinesAmmoFull _x and items _x;

{
  if (!alive _x) then {
    _Array = weapons _x; 
    {
      MyBox addWeaponCargo [_x, 1];
    } forEach _Array;
  };
} forEach ( (position player) nearEntities ["Man", 400] );

Also, do you think my "forEach" criteria is okay?

 

Share this post


Link to post
Share on other sites

I know what the problem is, it's nearEntities. the command doesn't seem to return dead units. So use nearestObjects instead, like so:

 

nearestObjects [position player, ["Man"], 400]

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
29 minutes ago, gc8 said:

I know what the problem is, it's nearEntities. the command doesn't seem to return dead units. So use nearestObjects instead, like so:

 


nearestObjects [position player, ["Man"], 400]

 

Hi @gc8 yes you're right.. it worked. I need to tidy up all my messy codes little bit, and will see if there are another problem that might need your expertise related to this.. thanks :)

Share this post


Link to post
Share on other sites

Hi @gc8, just a question: is there any way to move a container (e.g: backpack) to another container (e.g: car) by using reference?

For example: a backpack contain "1 pistol + 5 mags" - need to be transferred into a car. in game, we can easily do this by equipping the backpack and drop the backpack to car inventory. the content would remain.

However if using "addWeaponCargo, addMagazineCargo, and stuff" it would take some try and error to correctly doing this.

Any suggestion on the best way to do this?

If it has to be done using "everyContainer, addWeaponCargo, additemCargo, addmagazineCargo... then it's ok.. I just wonder if there are any simple and better way :D

Share this post


Link to post
Share on other sites

Also you might consider using this command : getUnitLoadout

 

There is also setUnitLoadout which can be used to set the previously got loadout to a given unit, but it may not suit your needs here.

Share this post


Link to post
Share on other sites

@palatine I dont know if there is a such command that can move the backpack from one place to another. Hopefully someone else knows.

 

If there's no command you just need to get the stuff out of the backpack manually. Use backpack, addBackpack, backpackItems, addItemToBackpack, etc. for this.

 

Share this post


Link to post
Share on other sites

No simple solution to this.

You could probably spawn a dummy unit somewhere off map, use getUnitloadout on the dead one, use setUnitloadout on the dummy and then have it put every single item in a crate with the Put action or whatever it's called.

Not really pretty or fast.

 

Cheers

Share this post


Link to post
Share on other sites

Hi @palatine, did you manage to make this work? I want something like this myself but all I get is empty arrays out dead bodies

Share this post


Link to post
Share on other sites
22 minutes ago, b3lx said:

Hi @palatine, did you manage to make this work? I want something like this myself but all I get is empty arrays out dead bodies

nevermind, i was missing something

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×