Jump to content
mat10193

Put player gear in ammo box on death

Recommended Posts

Hello,

 

Is there a way to script it so that when a player dies, their gear goes into an ammo box? 

Share this post


Link to post
Share on other sites
[] spawn 
{
	addMissionEventHandler["MPKilled",
	{
		params["_unit"];
		private _box = "Box_NATO_Wps_F" createVehicle getPosATL _unit; //make new box for things to go into
		clearItemCargoGlobal _box; //clear default config items for box
		clearWeaponCargoGlobal _box; //clear default config weapons  for box
		clearMagazineCargoGlobal _box; //clear default config magazines for box
		clearBackpackCargoGlobal _box; //clear defaultg config backpacks for box
		{_box addMagazineCargoGlobal[_x,1];} forEach (magazines _unit); //add all the items from unit to box
		{_box addWeaponCargoGlobal[_x,1];} forEach (weapons _unit);
		{_box addItemCargoGlobal[_x,1];} forEach (items _unit);
		_box addBackpackCargoGlobal[(backpack _unit),1];
		_box addItemCargoGlobal[(uniform _unit),1];
		_box addItemCargoGlobal[(vest _unit),1];
		deleteVehicle (objectParent _unit); //delete weapon holder created for killed unit
	}];
};

it's a little sloppy, bit gives you the idea

Share this post


Link to post
Share on other sites

Just wondering is all... Why addMissionEventHandler instead of addEventHandler command? Also, why did you add a new thread using spawn?

EDIT: I just realised why I think. I assume this applies to all entities in the mission, yes? Where do you pass the unit/player to this though? Wouldn't MPKilled be triggered for all killed things or no?

NOT TESTED!

player addEventHandler ["MPKilled",
{
	// I think it's better to use "params" which I usually do but I feel lazy! :P
	private _box = "B_supplyCrate_F" createVehicle (getPosATL (_this select 0));
	clearWeaponCargoGlobal _box;
	clearMagazineCargoGlobal _box;
	clearItemCargoGlobal _box;
	clearBackpackCargoGlobal _box;
	// I don't think it will add the magazine in the weapon (if one).
	// If you want to be all fancy and make it perfect then you can use magazinesAmmoFull to check how many bullets in each magazine and then apply it, etc...
	// https://community.bistudio.com/wiki/magazinesAmmoFull
	{_box addWeaponCargoGlobal [_x, 1];} forEach (weapons (_this select 0));
	{_box addMagazineCargoGlobal [_x, 1];} forEach (magazines (_this select 0));
	{_box addItemCargoGlobal [_x, 1];} forEach (items (_this select 0)) + (uniform (_this select 0)) + (vest (_this select 0));
	_box addBackpackCargoGlobal [(backpack (_this select 0)), 1];
	deleteVehicle (objectParent (_this select 0));
}];

https://community.bistudio.com/wiki/magazinesAmmoFull

Share this post


Link to post
Share on other sites

I certainly didn't test it yes, forgot to mention that.

I used spawn because running this in unscheduled would be a nightmare for performance.

MPKilled is ran on every machine at the time of death, not executed on each machine but the mission event handler is ran through each machine upon killtime.

MPKilled is a MPEventHandler only iirc.

I see there are many changes that you have posted, I like yours better. Mine was sloppy, but it got the idea down on paper I suppose 

2 hours ago, HazJ said:

Just wondering is all... Why addMissionEventHandler instead of addEventHandler command? Also, why did you add a new thread using spawn?

EDIT: I just realised why I think. I assume this applies to all entities in the mission, yes? Where do you pass the unit/player to this though? Wouldn't MPKilled be triggered for all killed things or no?

NOT TESTED!


player addEventHandler ["MPKilled",
{
	// I think it's better to use "params" which I usually do but I feel lazy! :P
	private _box = "B_supplyCrate_F" createVehicle (getPosATL (_this select 0));
	clearWeaponCargoGlobal _box;
	clearMagazineCargoGlobal _box;
	clearItemCargoGlobal _box;
	clearBackpackCargoGlobal _box;
	// I don't think it will add the magazine in the weapon (if one).
	// If you want to be all fancy and make it perfect then you can use magazinesAmmoFull to check how many bullets in each magazine and then apply it, etc...
	// https://community.bistudio.com/wiki/magazinesAmmoFull
	{_box addWeaponCargoGlobal [_x, 1];} forEach (weapons (_this select 0));
	{_box addMagazineCargoGlobal [_x, 1];} forEach (magazines (_this select 0));
	{_box addItemCargoGlobal [_x, 1];} forEach (items (_this select 0)) + (uniform (_this select 0)) + (vest (_this select 0));
	_box addBackpackCargoGlobal [(backpack (_this select 0)), 1];
	deleteVehicle (objectParent (_this select 0));
}];

https://community.bistudio.com/wiki/magazinesAmmoFull

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Yeah, I know. I was only just asking so I knew why. To gain knowledge for the future I guess ha. Good job anyway! (:

Share this post


Link to post
Share on other sites
8 minutes ago, HazJ said:

Yeah, I know. I was only just asking so I knew why. To gain knowledge for the future I guess ha. Good job anyway! (:

Hey Thanks, looks like your addition with the items, and vest, uniform. Doesn't work. Seems to not even work when I use toArray with it to add them all to one array.

Here is modified code that works well so far, no support for goggles or anything like that. Just mags, items like FAKS, and weapons, uniforms, vests, and backpacks.

 

/*
	Author : Midnight
	
	Description: moves dead unit's inventory to a box
	
	Parameter(s):
	0 : OBJECT  - Unit to add the killed event handler on

	Returns:
	none

*/

[_this] spawn
{
params["_unit"];
_unit select 0 addEventHandler["Killed",
	{
			params["_unit"];
			private _box = "Box_NATO_Wps_F" createVehicle (getposATL _unit);
			clearWeaponCargo _box;
			clearMagazineCargo _box;
			clearItemCargo _box;
			clearBackpackCargo _box;
			{_box addWeaponCargo[_x,1];} forEach (weapons _unit);
			{_box addMagazineCargo[_x,1];} forEach (magazines _unit);
			{_box addItemCargo[_x,1];} forEach (items _unit);
			_box addItemCargo[(uniform _unit),1];
			_box addItemCargo[(vest _unit),1];
			_box addBackpackCargo[(unitBackpack _unit),1];
			_box addUniform (uniform _unit);
	}];
};
	

Here is a demonstration video:

Youtube - Arma 3 to gear box

Share this post


Link to post
Share on other sites

Oh lol, yeah. It shouldn't work! My bad.

  • Haha 1

Share this post


Link to post
Share on other sites

Midnight,

Did you run this from onplayerkilled.sqf  or somewhere else ?

Share this post


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

Midnight,

Did you run this from onplayerkilled.sqf  or somewhere else ?

initPlayerLocal.sqf works well for this.

Pass any object to it and it'll work just the same outside of initPlayerLocal

  • Like 1

Share this post


Link to post
Share on other sites

Is there anyway to adapt this script so that it is when any NPC unit dies?

 

I can't for the life of me get it to work.

Share this post


Link to post
Share on other sites

So, I've managed to get this working...

 

Quote

[_this] spawn
{
params["_unit"];
addMissionEventHandler ["EntityKilled", 
    {
            params["_unit"];
            if (_unit isKindOf "Man") then {
            private _box = "Box_NATO_Wps_F" createVehicle (getposATL _unit);
            clearWeaponCargo _box;
            clearMagazineCargo _box;
            clearItemCargo _box;
            clearBackpackCargo _box;
            {_box addWeaponCargo[_x,1];} forEach (weapons _unit);
            {_box addMagazineCargo[_x,1];} forEach (magazines _unit);
            {_box addItemCargo[_x,1];} forEach (items _unit);
            _box addItemCargo[(uniform _unit),1];
            _box addItemCargo[(vest _unit),1];
            _box addBackpackCargo[(unitBackpack _unit),1];
            _box addUniform (uniform _unit);
            deleteVehicle _unit;
            };
        }];
    };

 

What would the command be to move their night vision across?

Share this post


Link to post
Share on other sites
Quote

[_this] spawn
{
params["_unit"];
addMissionEventHandler ["EntityKilled", 
    {
            params["_unit"];
            if (_unit isKindOf "Man") then {
            private _box = "Box_NATO_Wps_F" createVehicle (getposATL _unit);
            clearWeaponCargo _box;
            clearMagazineCargo _box;
            clearItemCargo _box;
            clearBackpackCargo _box;
            {_box addItemCargo[_x,1];} forEach (assignedItems _unit);
            {_box addWeaponCargo[_x,1];} forEach (weapons _unit);
            {_box addItemCargo[_x,1];} forEach (vestItems _unit);
            {_box addItemCargo[_x,1];} forEach (uniformItems _unit);
            _box addItemCargo[(uniform _unit),1];
            _box addItemCargo[(vest _unit),1];
            _box addItemCargo[(headgear _unit),1];
            _box addBackpackCargo[(Backpack _unit),1];
            deleteVehicle _unit;
            };
        }];
    };
 

 

 

So i'm running into a new issue, this is working well for ai, my problem now is with it causing a box to spawn for player as well as leaving the players corpse gear equipped.

 

I've tried using addMPEventHandler ["MPKilled" but i'm having 0 luck getting it to work with any object other than player. Any insight?

Share this post


Link to post
Share on other sites

Uh, it will do it for all entities killed, both player and AI, or at least it should. If you don't want it to work for players, put the following after the params part:

if ((isPlayer _unit)) exitWith {};

 

Share this post


Link to post
Share on other sites
15 hours ago, HazJ said:

Uh, it will do it for all entities killed, both player and AI, or at least it should. If you don't want it to work for players, put the following after the params part:


if ((isPlayer _unit)) exitWith {};

 

Eurgh, I had the right command, I was just putting it after

Quote

         if (_unit isKindOf "Man") then {

 

Thanks!

Share this post


Link to post
Share on other sites

@ArmaPants

You can also remove the code out of the if statement (delete the if statement that it was in) and change the isPlayer check to:

if ((isPlayer _unit) || (!(_unit isKindOf "Man"))) exitWith {};

 

Share this post


Link to post
Share on other sites

really like the script idea and its the closest one i have found to what i am looking for. 

 

Is there anyway to adapt this to a trigger of sorts. Im making a mission where you get to choose a load out but i want the inventory you have to be put in a container and not just get deleted. 

 

So you choose your new load out and your old one gets put into a container for you so you dont loose anything.

Share this post


Link to post
Share on other sites
On 11/24/2017 at 12:42 PM, HazJ said:

@ArmaPants

You can also remove the code out of the if statement (delete the if statement that it was in) and change the isPlayer check to:


if ((isPlayer _unit) || (!(_unit isKindOf "Man"))) exitWith {};

 

I would say, that if you're  going to be using this as a mission event handler execution, that you condition in the event handler, so that you can still use the AI portions later on for different concepts, rather than just exiting regardless.

Share this post


Link to post
Share on other sites
On 12/19/2017 at 12:38 AM, Chuc said:

really like the script idea and its the closest one i have found to what i am looking for. 

 

Is there anyway to adapt this to a trigger of sorts. Im making a mission where you get to choose a load out but i want the inventory you have to be put in a container and not just get deleted. 

 

So you choose your new load out and your old one gets put into a container for you so you dont loose anything.

Same thing applies, except thisList (a special variable the trigger passes) can be used

in the execution field: [thisList] call your_fn_here;

your_fn_here = 

{

    params[["_list",[],[[]]];

    {

          if(_x isKindOf "Man") then

         {

            private _box = "Box_NATO_Wps_F" createVehicle getPosATL _unit;
            clearWeaponCargo _box;
            clearMagazineCargo _box;
            clearItemCargo _box;
            clearBackpackCargo _box;
            {_box addItemCargo[_x,1];} forEach (assignedItems _unit);
            {_box addWeaponCargo[_x,1];} forEach (weapons _unit);
            {_box addItemCargo[_x,1];} forEach (vestItems _unit);
            {_box addItemCargo[_x,1];} forEach (uniformItems _unit);
            _box addItemCargo[(uniform _unit),1];
            _box addItemCargo[(vest _unit),1];
            _box addItemCargo[(headgear _unit),1];
            _box addBackpackCargo[(Backpack _unit),1];

         };

    } count _list;

};

 

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

×