Jump to content
Stinger505

Scripting Query - on AI Death Inventory Modification

Recommended Posts

Hello, is their anyone out there can help me with a script i'm setting up for a custom mission i'm making.

 

I've been building a civilian story mission, and what i'm trying to do is block any player from getting ammunition from any AI that die, especially in the staged fire fights between opposing units. 

I've done my research and I just about understand the  addMissionEventHandler and setting up required parameters and thanks to a Loot Stop script on here about the removeAllWeapons command which removes all weapons and magazines on the unit.

 

However that removes the entire units inventory, when i would like players to still be able to pick up smoke grenades and medical equipment (I use ace, so no first aid kits), 

 

Is there a scripting command i'm missing, that will allow me to remove the specific primary weapon type ammo, from the units inventory on death, thus leaving the units primary weapon unloaded and no ammo available to pickup or will i need to use an item array, or add back in items to the units inventory if forced to use removeAllWeapons?

 

Share this post


Link to post
Share on other sites

Maybe a better approach than just removing magazines from enemies:

Attach a InventoryClosed-Eventhandler to the player and everytime he closes his inventory, you run a script that moves all weapons and ammo in a newly created WeaponHolder (an invisible ammo box used to place items on the ground).

So the result will be: When the player picksup a weapon, he instantly drops it on the ground again. Maybe with a radio message like "Why can't I hold all these weapons?" :P

 

The script could be like this (just from the top of my head, not tested):

params["_unit","_container"];

private _holder = "WeaponHolderSimulated" createvehicle getpos _unit;
{
	_unit removeweapon _x;
	_holder addweaponcargo [_x,1];
} foreach weapons _unit;

And the players init: 

player/this addEventHandler ["InventoryClosed", {
	_this call tag_fnc_dropWeaponsScriptAbove;
}];

 

Share this post


Link to post
Share on other sites

Or you make it CBA dependant:

var_removeMagazinesDead = true;
["CAManBase", "Killed", {
	params ["_unit"];
	if (!isPlayer _unit && var_removeMagazinesDead) then {
		{_unit removeMagazine _x} count magazines _unit;
		_unit setAmmo [handgunWeapon _unit, 0];
		_unit setAmmo [primaryWeapon _unit, 0];
	};
}, true, [], true] call CBA_fnc_addClassEventHandler;

 

Share this post


Link to post
Share on other sites

 

21 hours ago, Belbo said:

Or you make it CBA dependant:


var_removeMagazinesDead = true;
["CAManBase", "Killed", {
	params ["_unit"];
	if (!isPlayer _unit && var_removeMagazinesDead) then {
		{_unit removeMagazine _x} count magazines _unit;
		_unit setAmmo [handgunWeapon _unit, 0];
		_unit setAmmo [primaryWeapon _unit, 0];
	};
}, true, [], true] call CBA_fnc_addClassEventHandler;

 


That... is impressive, its exactly what i need.

 

Thank you for so much! It even worked when i tested it in a dedicated server environment!

Share this post


Link to post
Share on other sites

Funny enough, I had the exact same problem the other day. I'm not sure yet, if you should execute it on server only or if it has to be executed on every client and server.

Share this post


Link to post
Share on other sites

I'm not sure if its useful, but i ran it using an if (isServer) execution as a seperate sqf, and was stable on a test with 10 players, deliberately trying to find fault.

 

It also worked on units spawned in and not just units pre placed.

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

×