Jump to content
  • 0

Check if player has ... in inventory


Darihon

Question

Hello,

 

I'm working on a script that allows players to upgrade their guns (eg. AK74 to AKS_74_kobra,) when they have the required items in their inventory. For eg. I want an AK74 to be able to upgrade for 2 scrap metal into a AKS_74_kobra, how do I do this? 

 

Something like this?

private [_mags];
_mags = ["Scrap_Metal","Scrap_Metal"]; // Don't mind the classname, only as an example :D

if !(player hasWeapon "AK74") exitWith {
cutText [format["U don't have an AK74!"], "PLAIN DOWN"];
};
 
if !(player has in _mags) exitWith {
cutText [format["U don't have the required items to upgrade: 2x scrap metal"], "PLAIN DOWN"];
};
 
if (player has in _mags) then {
player removeweapon "AK74";
sleep 1;
player addweapon "AKS_74_kobra";
cutText [format["Ur AK74 has been updated to an AKS_74_kobra!"], "PLAIN DOWN"];
};
 

Thanks in advance,

 

Darryl

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Hard option. (if you haven't other optins).

aA4p72N.png

if ("PartGeneric" in magazines player) then {
    player removeMagazine "PartGeneric";
    } else { 
        cutText [format["You need 2xScrap Metal"], "PLAIN DOWN"];
    };
    if ("PartGeneric" in magazines player) then {  
        // do what you want, he have 2 Scrap Metals
	};
        } else { 
            cutText [format["You need 2xScrap Metal"], "PLAIN DOWN"];
            player addMagazine "PartGeneric";
        };
}; 
Link to comment
Share on other sites

  • 0

I went ahead and mocked up a (very messy) working prototype for you to take a look at, you can specify the base gun, the upgraded version and the recipe needed.

private ["_checkingWeapon","_hasWeaponFromList","_neededMaterials","_nextWeapon","_needed","_playerInv","_partsHave","_testPart","_fail","_display","_firstWeapon"];
_hasWeaponFromList = false;
_needed = "";
_partsHave = [];
_fail = false;

_weaponUpsArray = [
["AK_107_kobra","AK_107_pso",[["PartGeneric",2],["PartGlass",1]]]
];


{
    _checkingWeapon = _x select 0;
	if (currentWeapon player == _checkingWeapon) exitWith {
	    _hasWeaponFromList = true;
		_neededMaterials = _x select 2;
		_nextWeapon = _x select 1;
	};
} forEach _weaponUpsArray;

if (!_hasWeaponFromList) then {
    titleText ["This weapon cannot be upgraded","PLAIN DOWN"];
} else {
    _playerInv = [player] call BIS_fnc_invString;
	
	{
	    _testPart = _x;
		{
		    if (_testPart == _x select 0) then {
			    _partsHave set [(count _partsHave),_testPart];
			};
		} forEach _neededMaterials
	} forEach _playerInv;
	
	{
	    _testPart = _x select 0;
	    _qtyCheck = {_x == _testPart; } count _partsHave;
		if (_qtyCheck < _x select 1) exitWith {
		    _fail = true;
			_display = format ["You do not have the materials to perform this upgrade\n%1",_neededMaterials];
		    titleText [_display,"PLAIN DOWN"];
		};
	} forEach _neededMaterials;
	
	if (!_fail) then {
	    {
		    for "_i" from 1 to (_x select 1) do {
			    player removeMagazine (_x select 0);
			};
		} forEach _neededMaterials;
		_firstWeapon = currentWeapon player;
	    player removeWeapon _firstWeapon;
		player addWeapon _nextWeapon;
		_display = format ["You upgraded your %1 to a %2",_firstWeapon,_nextWeapon];
		titleText [_display,"PLAIN DOWN"];
	};
	
};

hopefully, this will help youa out a little bit :)

Link to comment
Share on other sites

  • 0

You can use this for quantity check, it'll notify player of missing parts and amount:

if ([["PartGeneric",2]] call player_checkAndRemoveItems) then {
player removeWeapon "AK74";
sleep 1;
player addWeapon "AKS_74_kobra";
};

You can easily add multiple items this way:

 

if ([["PartGeneric",2], "PartGlass"] call player_checkAndRemoveItems) then {
};

As simple as that. Let me know how it works out for you.

Link to comment
Share on other sites

  • 0

theres something like this availible already here on the forum somewhere ... it works by rightclicking weapon, made by OmigaaaD.

 

he was using a file for each addition (kinda like you are doing) but some was broken and some did not work at all ...

 

however i did a complete rewrite of it and made generic files to do the switch, so i didnt need a file for each weapon/item added, just add a line in the file for custom dropdown menu on rightclick.

 

i think i covered most default epoch weapons aswell ... ill see if i can sort some files without all my server customization, that can be used by normal epoch server owners else try the version the original author of the scripts made, its not too bad when you fix all the minor errors. 

Link to comment
Share on other sites

  • 0
On 6/2/2014 at 6:11 PM, raymix said:

You can use this for quantity check, it'll notify player of missing parts and amount:


if ([["PartGeneric",2]] call player_checkAndRemoveItems) then {
player removeWeapon "AK74";
sleep 1;
player addWeapon "AKS_74_kobra";
};

You can easily add multiple items this way:

 


if ([["PartGeneric",2], "PartGlass"] call player_checkAndRemoveItems) then {
};

As simple as that. Let me know how it works out for you.

I know this is old, but how can i check for weapons.  Toolbelt items nad weapons. I havnt been able to find any documentation on it

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...