Jump to content
Sign in to follow this  
travhimself

Adding items to a corpse

Recommended Posts

I've been trying to add an item to a corpse with either onPlayerKilled.sqf or onPlayerRespawn.sqf, both of which have a param that supposedly references the "old unit" (which I take to mean the dead body).

 

onPlayerKilled.sqf

_oldunit = _this select 0;
_oldunit addItem "G_Aviator";

onPlayerRespawn.sqf

_newunit = _this select 0;
_oldunit = _this select 1;
_oldunit addItem "G_Aviator";
However, neither seems to work. In fact, in onPlayerRespawn.sqf, if I diag_log _newunit and _oldunit, they both seem to point to the same object.
 
Is there an extra step needed to get a handle for the corpse itself? And if so, is it possible to add an item to its inventory?
 
Thanks in advance!

Share this post


Link to post
Share on other sites

since unit is dead it might not be possible to use unit directly, however you might want to try to get unit containers and use cargo commands to interact directly with them.

Share this post


Link to post
Share on other sites

Great idea, thanks! Here's what I ended up with. I'm sure there's room for refactoring, but it should at least provide a starting point for anyone else trying to accomplish this:

 

 

onPlayerKilled.sqf

// grab the old unit (corpse)
_oldunit = _this select 0;


// determine which containers the unit has
_uniform = uniformContainer _oldunit;
_vest = vestContainer _oldunit;
_backpack = backpackContainer _oldunit;


_possiblecontainers = [_uniform, _vest, _backpack];


// check each container to see if it a) exists, and b) has space
{
    if ( !(isNull _x) ) then {
        if ( _x canAdd ["ItemWatch", 1] ) exitWith {
            _x addItemCargoGlobal ["ItemWatch", 1];
        };
    };
} foreach _possiblecontainers;

 

As an aside, just wanted to say thanks killzone_kid for all the posts on your blog, the forums, and the wiki -- they've been a tremendous help over the years. Keep up the good work!

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
Sign in to follow this  

×