Jump to content
Sign in to follow this  
Sarge46

Saving Weapons

Recommended Posts

How can I have weapons save after death, so you don't need to run to the box every time.

Share this post


Link to post
Share on other sites

Add this to the player (init line or init.sqf):

_EHkilledIdx = player addEventHandler ["killed", {_this execVM "playerKilled.sqf"}];

Create a file named playerkilled.sqf in your mission folder and write somethink like this in it:

_unit = _this select 0; //the killed unit
_weapons=weapons _unit; //get weapons
_magazines=magazines _unit; //get mags
waituntil {alive _unit}; //waits for the unit to respawn (is alive again)


{_unit addweapon _x;}foreach _weapons; //add weapons
{_unit addmagazine _x;}foreach _magazines; //add magazines

Please note that in MP the old weapons from the body dont get deleted.... so its possible to "cheat" you an infinite amount of weapons/mags with this script.

Share this post


Link to post
Share on other sites

isn't there a way to lock a corpse - could've sworn there was a command for that.

alternatively you could just deletevehicle on the corpse upon respawn.

Share this post


Link to post
Share on other sites
clearweaponcargo _corpse;
clearmagazinecargo _corpse;

That doesn't work with units.

Save the weapons and magazines in an array and then do

removeAllItems _corpse;

removeAllWeapons _corpse;

Furthermore, in the script above there's an error.

If you readd weapons and magazines after the player respawns you have to remove all weapons and items prior adding. Units spawn with a predefined set of weapons and magazines, even civilians respawn with items.

Xeno

Share this post


Link to post
Share on other sites

I've added the eventhandler as suggested above, and am using the script below:

_unit = _this select 0; //the killed unit
_weapons=weapons _unit; //get weapons
_magazines=magazines _unit; //get mags
waituntil {alive _unit}; //waits for the unit to respawn (is alive again)

removeallitems _unit;
removeallweapons _unit;
{_unit addweapon _x;}foreach _weapons; //add weapons
{_unit addmagazine _x;}foreach _magazines; //add magazines

The player does not respawn with their pre-death weapons.

What am I missing?

Share this post


Link to post
Share on other sites

"_unit" will never become alive again. Change that to player, and you will be set.

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  

×