Jump to content
austin_medic

Bit of an issue with 'buying' different types of items from a Listbox

Recommended Posts

Alright so I'm trying to get buying things working from a listbox, but this only 'semi-works' and it seems to be quite messy since that was the only way i could even get it semi-functional with destorying the balance value completely.

 

Another problem I'm having is if I click too fast inside the GUI to add things, it splits the items into multiple stacks of the same item or breaks the icon of the item completely.

_gear = _this select 0;
_crate = AUSMD_buyBox;

_isWep = isClass (configFile >> "CfgWeapons" >> (_gear select 0));
if(!_isWep) then
{
	_isMag = isClass (configFile >> "CfgMagazines" >> (_gear select 0));
	_isItem = isClass (configFile >> "CfgWeapons" >> (_gear select 0));
	_isBag = isClass (configFile >> "CfgVehicles" >> (_gear select 0));
};
_isMag = isClass (configFile >> "CfgMagazines" >> (_gear select 0));
if(!_isMag) then
{
	_isItem = isClass (configFile >> "CfgWeapons" >> (_gear select 0));
	_isBag = isClass (configFile >> "CfgVehicles" >> (_gear select 0));
};
_isItem = isClass (configFile >> "CfgWeapons" >> (_gear select 0));
if(!_isItem) then
{
	_isBag = isClass (configFile >> "CfgVehicles" >> (_gear select 0));
};

if (_isWep) then {
	_arrPath = ([Sand_Weapons,(_gear select 0)] call BIS_fnc_findNestedElement);
	_selectOne = _arrPath select 0;
	hint format ["weps %1 \n\n %2",_arrPath,_selectOne];
	_pathPrice = Sand_Weapons select _selectOne select 1;
	_price = _pathPrice;
	if(_price > GV_Sand_Balance) exitWith {hint "You cannot afford Weapons!";};
	GV_Sand_Balance = GV_Sand_Balance - _price;
	publicVariable "GV_Sand_Balance";
	_crate addWeaponCargoGlobal [(_gear select 0), (_gear select 1)];
	//hint format ["Purchased for $ %1",_price];
};
if(_isMag) then
{
	_arrPath = ([Sand_Magazines,(_gear select 0)]) call BIS_fnc_findNestedElement;
	_selectOne = _arrPath select 0;
	hint format ["mags %1 \n\n %2",_arrPath,_selectOne];
	_pathPrice = Sand_Magazines select _selectOne select 1;
	_price = _pathPrice;
	if(_price > GV_Sand_Balance) exitWith {hint "You cannot afford Mags!";};
	GV_Sand_Balance = GV_Sand_Balance - _price;
	publicVariable "GV_Sand_Balance";
	_crate addMagazineCargoGlobal [(_gear select 0), (_gear select 1)];
	//hint format ["Purchased for $ %1",_price];
};
if(_isItem) then
{
	_arrPath = ([Sand_Items,(_gear select 0)]) call BIS_fnc_findNestedElement;
	_selectOne = _arrPath select 0;
	hint format ["items %1 \n\n %2",_arrPath,_selectOne];
	_pathPrice = Sand_Items select _selectOne select 1;
	_price = _pathPrice;
	if(_price > GV_Sand_Balance) exitWith {hint "You cannot afford Items!";};
	GV_Sand_Balance = GV_Sand_Balance - _price;
	publicVariable "GV_Sand_Balance";
	_crate addItemCargoGlobal [(_gear select 0), (_gear select 1)];
	//hint format ["Purchased for $ %1",_price];
};
if(_isBackpack) then
{
	_arrPath = ([Sand_Backpacks,(_gear select 0)]) call BIS_fnc_findNestedElement;
	_selectOne = _arrPath select 0;
	hint format ["backpacks %1 \n\n %2",_arrPath,_selectOne];
	_pathPrice = Sand_Backpacks select _selectOne select 1;
	_price = _pathPrice;
	if(_price > GV_Sand_Balance) exitWith {hint "You cannot afford Items!";};
	GV_Sand_Balance = GV_Sand_Balance - _price;
	publicVariable "GV_Sand_Balance";
	_crate addBackpackCargoGlobal [(_gear select 0), (_gear select 1)];
	//hint format ["Purchased for $ %1",_price];
};
if(GV_Sand_Balance < 0 || isNil "GV_Sand_Balance") then
{
	GV_Sand_Balance = 0;
	publicVariable "GV_Sand_Balance";
};

There is an attempt for me to debug the problem as you can see but that doesn't seem to be the issue.

 

Any Ideas?

 

EDIT: Weapons seem to have no trouble being added to the box, but others do (they still have the problem of seperating into mutliple stacks though).

Share this post


Link to post
Share on other sites

After a couple of hours of bashing my head off the wall i found the problem was with how Bohemia set up their configs to include items guns and uniforms under the same category.....

Share this post


Link to post
Share on other sites

BIS_fnc_itemType may help you.

Im not sure of your exact structure but something like...

_gear = _this select 0;
_crate = AUSMD_buyBox;

_itemType = ( _gear select 0 ) call BIS_fnc_itemType;
_itemType = switch (_itemType select 0) do {
	case "Equipment" : {
		if ( _itemType select 1 isEqualTo "Backpack" ) then {
			_itemType select 1
		}else{
			"Item"
		};
	};
	default {
		_itemType select 0
	};
};

if !( _itemType isEqualTo "" ) then {
	_sandArray = missionNamespace getVariable format[ "Sand_%1s", _itemtype ];
	_arrPath = ([_sandArray,(_gear select 0)] call BIS_fnc_findNestedElement);
	_selectOne = _arrPath select 0;
	hint format ["%1 %2 \n\n %3",_itemType,_arrPath,_selectOne];
	_price = _sandArray select _selectOne select 1;
	if(_price > GV_Sand_Balance) exitWith {hint format[ "You cannot afford %1s!", _itemType ];};
	GV_Sand_Balance = GV_Sand_Balance - _price;
	publicVariable "GV_Sand_Balance";
	call compile format [ "_crate add%1CargoGlobal [(_gear select 0), (_gear select 1)]", _itemType ];
	//hint format ["Purchased for $ %1",_price];
};

if( isNil "GV_Sand_Balance" || { GV_Sand_Balance < 0 } ) then
{
	GV_Sand_Balance = 0;
	publicVariable "GV_Sand_Balance";
};
Also swapped your final if statement around because if GV_Sand_Balance is nil then having the greater than check first would cause you a undefined error.

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

×