Jump to content
greenpeacekiller

Add Items to Player inventory via Addaction

Recommended Posts

I'm trying to make it so that players can use a drop down action on a object to add the items they need in their inventory.

I want to have 2 objects with different items being added

One detects which weapon the player is using and adds a magazine

The other adds a set of items defined in an array

 

I found this code for the magazines:

Fn_Gear_CompatibleMagazines = {
	private _cls = configFile >> "CfgWeapons" >> _this;
	private _res = [];
	{_res pushBack (if (_x == "this")
		then {getArray(_cls >> "magazines")}
		else {getArray(_cls >> _x >> "magazines")});
	} forEach getArray(_cls >> "muzzles");

	_res
};

private _unt = player;

{	if (count _x > 0) then {
		{	if (count _x > 0) then {			
				_unt addMagazine (_x select 0)}
		} foreach (_x call Fn_Gear_CompatibleMagazines)	
	}
} forEach [primaryWeapon _unt, secondaryWeapon _unt, handgunWeapon _unt];

However I myself can understand little of the code and woudlnt know if this is MP compatible or how to trigger this via the addaction menu.

I tried excuting the code in a .sqf via the addaction menu, but it would only work once. So obvioulsy i dun goof

 

As for the medical supplies

I was trying to use 'removeAllItems'  to clear the inventory of the player's uniform

and then use (uniformContainer _unit) addItemCargoGlobal ["FirstAidKit", 15];

But then I would also need it to target the  person it needs to add the items to who is using the addAction menu. Something I do not understand how to do

 

Any help will be very much appriciated

Share this post


Link to post
Share on other sites

Take a look at BIS_fnc_addWeapon, automatically detects compatible magazines and adds them if there's inventory space:

_add = [player,currentWeapon player, 1] call BIS_fnc_addWeapon;

This will add one magazine to the player for his primary weapon, as long as he has space for it.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
20 minutes ago, Grumpy Old Man said:

Take a look at BIS_fnc_addWeapon, automatically detects compatible magazines and adds them if there's inventory space:


_add = [player,currentWeapon player, 1] call BIS_fnc_addWeapon;

This will add one magazine to the player for his primary weapon, as long as he has space for it.

 

Cheers

 

Thanks that was more simple than I expected

 

One question, following the examples provided on the bohiema documentation i am using the code below. I dont have anyone to test this with atm

Will it excute this to the player using the addaction locally or will it select all players?

 

_box = _this select 0
_caller = _this select 1
_id = _this select 2
; Add the magazine to player using adAction
_caller = [player,currentWeapon player, 1] call BIS_fnc_addWeapon;

 

EDIT:

I dun goof again

You can replace player with _caller

Share this post


Link to post
Share on other sites

The code you wrote is inside an addAction command, where the parameters (_this select 0, 1, 2) are identified (see BIKI)

So, you don't have to use player but _caller to make the code work.

On the other hand, as you can read in BIKI also the bis_fnc_addWeapon returns.. a muzzle name of the weapon.

It's a wrong way to attempt to redefine _caller (the player who acts the action) for a muzzle....

 

And I don't understand why you add all this stuff on a crate. Each time you grab a weapon, it's loaded (at least in Vanilla), and you have some extra magazines inside the crate.

So, what is your aim? Why an addAction (with in weapon choice) instead of a standard inventory?

 

Share this post


Link to post
Share on other sites
40 minutes ago, pierremgi said:

The code you wrote is inside an addAction command, where the parameters (_this select 0, 1, 2) are identified (see BIKI)

So, you don't have to use player but _caller to make the code work.

On the other hand, as you can read in BIKI also the bis_fnc_addWeapon returns.. a muzzle name of the weapon.

It's a wrong way to attempt to redefine _caller (the player who acts the action) for a muzzle....

 

And I don't understand why you add all this stuff on a crate. Each time you grab a weapon, it's loaded (at least in Vanilla), and you have some extra magazines inside the crate.

So, what is your aim? Why an addAction (with in weapon choice) instead of a standard inventory?

 

 

It can be used on things other than crates.

 

Mainly the goal is to have an drop down action give you all the items you need instantly without having to go through the inventory.

It would speed up the process every time ~20 players need to gear up

We also use ACE and for medical gear it requires about 5-3x different sets of items.

 

So then I would need this first code for the magazines because everyone uses different weapons

And then I would add an array with items that adds the medical stuff.

 

Im still figuring out how to put the rest of the medical stuff in something readable for the .sqs

 

So far I went ahead and just add this to their init so they have it at the start of the mission

Quote

removeUniform this;
this forceAddUniform "rhs_uniform_FROG01_wd";
this addItemToUniform "ACE_Flashlight_MX991";
this addItemToUniform "ACE_personalAidKit";
for "_i" from 1 to 7 do {this addItemToUniform "ACE_fieldDressing";};
for "_i" from 1 to 7 do {this addItemToUniform "ACE_packingBandage";};
for "_i" from 1 to 7 do {this addItemToUniform "ACE_elasticBandage";};
for "_i" from 1 to 2 do {this addItemToUniform "ACE_tourniquet";};
for "_i" from 1 to 3 do {this addItemToUniform "ACE_morphine";};
for "_i" from 1 to 2 do {this addItemToUniform "ACE_epinephrine";};
for "_i" from 1 to 3 do {this addItemToUniform "ACE_tourniquet";};

 

Share this post


Link to post
Share on other sites
11 hours ago, greenpeacekiller said:

 

It can be used on things other than crates.

 

Mainly the goal is to have an drop down action give you all the items you need instantly without having to go through the inventory.

It would speed up the process every time ~20 players need to gear up

We also use ACE and for medical gear it requires about 5-3x different sets of items.

 

So then I would need this first code for the magazines because everyone uses different weapons

And then I would add an array with items that adds the medical stuff.

 

Im still figuring out how to put the rest of the medical stuff in something readable for the .sqs

 

So far I went ahead and just add this to their init so they have it at the start of the mission

 

 

So it's actually about unit loadouts.

You could define custom loadouts and store them in an array using getUnitLoadout/setUnitLoadout.

In the editor, place a few units, edit their loadouts, then you can paste this into the debug console to grab a units loadout:

copytoclipboard str getUnitLoadout cursorObject;

Then inside some loadouts.sqf file you can save every single loadout as an array and go nuts from there on.

 

Cheers

Share this post


Link to post
Share on other sites

You could also create loadouts in the ACE Arsenal and share them. 

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

×