Jump to content

Recommended Posts

1 hour ago, davidoss said:

Thank you @Larrow

You are beautiful, you saved my brain.

Its all the beef hula hoops that make @Larrow beautiful.  And his sweet code of course.

  • Haha 1

Share this post


Link to post
Share on other sites

I mind his brain.

Now it is almost done and by the way i just realize that this would be much easily if i would use lbdata to store items classnames to the lb rows instead of holding arrays and iterate throw indexes.

Anyway i am facing another big problem, how to remove items attached to the weapons in vehicle inventory and than add it to the vehicle inventory at load dialog.

I knew it can be done when player holding weapon.

Any idea?

Share this post


Link to post
Share on other sites

Hahaha  beautiful mind strikes again - shot in 10.

Do you have any example what is weaponId, creatorId ?

Share this post


Link to post
Share on other sites

Refresh page, posted wrong command, changed previous post.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

I have doubts again, could that be wrote in some way better?

 

//buttons
private _playerMoney = call (compile (ctrlText _playerMoneyCtrl));
private _currentBalance = call (compile (ctrlText _overallPriceCtrl));
if ((_playerMoney + _currentBalance) > 0) then {

	if (lbSize _traderTradeCtrl > 0) then {
		if (lbSize _playerTradeCtrl > 0) then {
			_buyButtonCtrl ctrlSetText "BUY+SELL";
			_buyButtonCtrl ctrlEnable true;
			_buyButtonCtrl ctrlSetTooltip "Buy and sell selected items";
			_sellButtonCtrl ctrlEnable true;
			_sellButtonCtrl ctrlSetTooltip "Sell selected items";
		} else {
			_buyButtonCtrl ctrlSetText "BUY";
			_buyButtonCtrl ctrlEnable true;
			_buyButtonCtrl ctrlSetTooltip "Buy selected items";
			_sellButtonCtrl ctrlEnable false;
			_sellButtonCtrl ctrlSetTooltip "Nothing to sell";
		};
	} else {
		_buyButtonCtrl ctrlSetText "BUY";
		_buyButtonCtrl ctrlEnable false;
		_buyButtonCtrl ctrlSetTooltip "Nothing to buy";
		if (lbSize _playerTradeCtrl > 0) then {
			_sellButtonCtrl ctrlEnable true;
			_sellButtonCtrl ctrlSetTooltip "Sell selected items";
		} else {
			_sellButtonCtrl ctrlEnable false;
			_sellButtonCtrl ctrlSetTooltip "Nothing to sell";
		};
	};
} else {
	_buyButtonCtrl ctrlSetText str (_playerMoney + _currentBalance);
	_buyButtonCtrl ctrlEnable false;
	_buyButtonCtrl ctrlSetTooltip "Not enough money";
	if (lbSize _playerTradeCtrl > 0) then {
		_sellButtonCtrl ctrlEnable true;
		_sellButtonCtrl ctrlSetTooltip "Sell selected items";
	} else {
		_sellButtonCtrl ctrlEnable false;
		_sellButtonCtrl ctrlSetTooltip "Nothing to sell";
	};
};

 

  • Like 1

Share this post


Link to post
Share on other sites

A little progress on this again:

 

24dd92e7d449aad7750e370587f1b27e-full.jp

 

Now i need to figure out how to count this all and  script buttons actions out.

  • Like 2

Share this post


Link to post
Share on other sites

Update: button "Sell" done!

To do button "Buy"

As usually i wanna ask for any code improvements for:

 

Spoiler

params [["_inventoryArray",[],[[]]]];
private _emptyInv = [[],[],[],[],[],[],"","",[],["","","","","",""]];
player setUnitLoadout _emptyInv;

private _uniforms = _inventoryArray select {_x isKindOf ["Uniform_Base",configfile >> "CfgWeapons"]};
private _vests = _inventoryArray select {_x isKindOf ["Vest_NoCamo_Base",configfile >> "CfgWeapons"] || _x isKindOf ["Vest_Camo_Base",configfile >> "CfgWeapons"] };
private _backpack = _inventoryArray select {_x isKindOf ["bag_base", configFile >> "CfgVehicles"]};

if !(_uniforms isEqualTo []) then {
	player addUniform (_uniforms # 0);
	_inventoryArray deleteAt (_inventoryArray find (_uniforms # 0));
	_uniforms = _uniforms - [(_uniforms # 0)];
};

if !(_vests isEqualTo []) then {
	player addVest (_vests # 0);
	_inventoryArray deleteAt (_inventoryArray find (_vests # 0));
	_vests = _vests - [_vests # 0];
};

if !(_backpack isEqualTo []) then {
	player addBackpack (_backpack # 0);
	_inventoryArray deleteAt (_inventoryArray find (_backpack # 0));
	if !(_uniforms isEqualTo []) then {
		{
			player addItemToBackpack _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		} forEach _uniforms;
	};
	if !(_vests isEqualTo []) then {
		{
			player addItemToBackpack _x;
			_inventoryArray deleteAt (_inventoryArray find _x);	
		} forEach _vests;
	};
};

private _weapons = _inventoryArray select {
	_x isKindOf ["Rifle", configFile >> "CfgWeapons"] ||
	_x isKindOf ["LauncherCore", configFile >> "CfgWeapons"] ||
	_x isKindOf ["pistol", configFile >> "CfgWeapons"]
};

if !(_weapons isEqualTo []) then {

	{
		if (true) then {
			if (_forEachIndex > 0) exitWith {player addItemToBackpack _x; _inventoryArray deleteAt (_inventoryArray find _x)};
			player addWeapon _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		};
	} forEach (_weapons select {_x isKindOf ["Rifle", configFile >> "CfgWeapons"]});

	{
		if (true) then {
			if (_forEachIndex > 0) exitWith {player addItemToBackpack _x; _inventoryArray deleteAt (_inventoryArray find _x)};
			player addWeapon _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		};
	} forEach (_weapons select {_x isKindOf ["pistol", configFile >> "CfgWeapons"]});

	{player addWeapon _x; _inventoryArray deleteAt (_inventoryArray find _x)} forEach (_weapons select {_x isKindOf ["LauncherCore", configFile >> "CfgWeapons"]});

};


private _binoculars = (_inventoryArray select {_x == "Binocular" || _x isKindOf ["Laserdesignator", configFile >> "CfgWeapons"]});
if !(_binoculars isEqualTo []) then {
	{
		private _added = false;
		if (true) then {
			if (_forEachIndex > 0) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
				_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player addWeapon _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		};
	} forEach _binoculars;
};


private _nvgs = (_inventoryArray select {_x == "NVGoggles" || _x isKindOf ["NVGoggles", configFile >> "CfgWeapons"]});
if !(_nvgs isEqualTo []) then {
	{
	private _added = false;
		if (true) then {
			if (_forEachIndex > 0) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
				_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player linkItem _x;
			_inventoryArray deleteAt (_inventoryArray find _x);		
		};
	} forEach _nvgs;
};

private _helmets = _inventoryArray select {	
	_x isKindOf ["H_HelmetB", configFile >> "CfgWeapons"] ||
	_x isKindOf ["HelmetBase", configFile >> "CfgWeapons"]
};
if !(_helmets isEqualTo []) then {
	{
	private _added = false;
		if (true) then {
			if (_forEachIndex > 0) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
			_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player addHeadgear _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		};
	} forEach _helmets;
};

private _goggles = _inventoryArray select {_x isKindOf ["None", configFile >> "CfgGlasses"] || _x isKindOf ["G_Diving", configFile >> "CfgGlasses"]};
if !(_goggles isEqualTo []) then {
	{
	private _added = false;
		if (true) then {
			if (_forEachIndex > 0) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
			_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player addGoggles _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		};
	} forEach _goggles;
};


private _linkedItemsClasses = ["ItemCompass","ItemGPS","ItemMap","ItemRadio","ItemWatch"];
private _ItemCompass = false;
private _ItemGPS = false;
private _ItemMap = false;
private _ItemRadio = false;
private _ItemWatch = false;
private _linkedItems = _inventoryArray select {_x in _linkedItemsClasses};

if !(_linkedItems isEqualTo []) then {
	{
		private _added = false;
		if (_x == "ItemCompass") then {
			if (_ItemCompass) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
			_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player linkItem _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
			_ItemCompass = true;
		};
		if (_x == "ItemGPS") then {
			if (_ItemGPS) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
			_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player linkItem _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
			_ItemGPS = true;
		};
		if (_x == "ItemMap") then {
			if (_ItemMap) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
			_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player linkItem _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
			_ItemMap = true;
		};
		if (_x == "ItemRadio") then {
			if (_ItemRadio) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
			_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player linkItem _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
			_ItemRadio = true;
		};
		if (_x == "ItemWatch") then {
			if (_ItemWatch) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
			_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player linkItem _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
			_ItemWatch = true;
		};
	} forEach _linkedItems;
};


private _itemsAndMags = _inventoryArray select {	
	_x isKindOf ["CA_Magazine", configFile >> "CfgMagazines"] ||
	_x isKindOf ["itemCore", configFile >> "CfgWeapons"]
};

if !(_itemsAndMags isEqualTo []) then {

	{
		switch (true) do {
		
			case (_x isKindOf ["CA_Magazine", configFile >> "CfgMagazines"]): {
				if (player canAdd _x ) then {
					player addMagazine _x;
				} else {
					traderWeaponHolder addMagazineCargoGlobal [_x, 1];
				};
				_inventoryArray deleteAt (_inventoryArray find _x);
			
			};
			case (_x isKindOf ["itemcore", configFile >> "CfgWeapons"]): {
				private _added = false;
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;_inventoryArray deleteAt (_inventoryArray find _x)};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;_inventoryArray deleteAt (_inventoryArray find _x)};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;_inventoryArray deleteAt (_inventoryArray find _x)};
					default {
						traderWeaponHolder addItemCargoGlobal [_x, 1];
						_inventoryArray deleteAt (_inventoryArray find _x)
					};
				};
			};
			default {};
		};
	} forEach _itemsAndMags;
};

0 = [traderWeaponHolder] spawn {
	params [["_weaponHolder",objNull,[objNull]]];
	waitUntil {
		sleep 5;
		((getBackpackCargo _weaponHolder + getMagazineCargo _weaponHolder + getItemCargo _weaponHolder + getWeaponCargo _weaponHolder) isEqualTo [[],[],[],[],[],[],[],[]]) ||
		isNull _weaponHolder
	};
	sleep 15;
	if (!isNull _weaponHolder) then {
		deleteVehicle _weaponHolder;
	};
};

 

 

  • Like 1

Share this post


Link to post
Share on other sites
4 minutes ago, davidoss said:

if !(_binokulars isEqualTo []) then {

 

I don't know code but binoc's spelled wrong?

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

yes thanks its just variable but lets keep this right

Share this post


Link to post
Share on other sites

Only quickly browsed though it...

 

On 1/10/2019 at 9:45 PM, davidoss said:

0 = [traderWeaponHolder] spawn {
	params [["_weaponHolder",objNull,[objNull]]];
	waitUntil {
		sleep 5;
		((getBackpackCargo _weaponHolder + getMagazineCargo _weaponHolder + getItemCargo _weaponHolder + getWeaponCargo _weaponHolder) isEqualTo [[],[],[],[],[],[],[],[]]) ||
		isNull _weaponHolder
	};
	sleep 15;
	if (!isNull _weaponHolder) then {
		deleteVehicle _weaponHolder;
	};
};

 

Use a container closed EH on the traderWeaponHolder. When its closed if its cargo is empty then delete it.

traderWeaponHolder addEventHandler [ "ContainerClosed", {
	params[ "_container", "_unit" ];
	
	if ( weaponCargo _container + magazineCargo _container + itemCargo _container + backpackCargo _container isEqualTo [] ) then {
		deleteVehicle _container;
	};
}];

 

 

On 1/10/2019 at 9:45 PM, davidoss said:

if !(_vests isEqualTo []) then {
	player addVest (_vests # 0);
	_inventoryArray deleteAt (_inventoryArray find (_vests # 0));
	_vests = _vests - [_vests # 0];
};

if !(_backpack isEqualTo []) then {
	player addBackpack (_backpack # 0);
	_inventoryArray deleteAt (_inventoryArray find (_backpack # 0));
	if !(_uniforms isEqualTo []) then {
		{
			player addItemToBackpack _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		} forEach _uniforms;
	};
	if !(_vests isEqualTo []) then {
		{
			player addItemToBackpack _x;
			_inventoryArray deleteAt (_inventoryArray find _x);	
		} forEach _vests;
	};
};

 

If someone bought multiple vests of the same kind and it just happens to be the first found and added to the player, _vests = _vests - [_vests # 0]; would delete them all from the _vests and as such the extras would never get added to the backpack.

 

 

On 1/10/2019 at 9:45 PM, davidoss said:

	{
		if (true) then {
			if (_forEachIndex > 0) exitWith {player addItemToBackpack _x; _inventoryArray deleteAt (_inventoryArray find _x)};
			player addWeapon _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		};
	} forEach (_weapons select {_x isKindOf ["Rifle", configFile >> "CfgWeapons"]});

 

Not all weapons can go in a backpack e.g "srifle_DMR_01_ACO_F" wont even fit in a carryAll. Would be better to use canAdd to check first and if not place in your traderWeaponHolder. Plus what happens if the player has not bought a backpack?

 

 

On 1/10/2019 at 9:45 PM, davidoss said:

private _binoculars = (_inventoryArray select {_x == "Binocular" || _x isKindOf ["Laserdesignator", configFile >> "CfgWeapons"]}); if !(_binoculars isEqualTo []) then {

Binoculars, LaserDesignators and RangeFinders are all types of Binocular.

private _binoculars = (_inventoryArray select {_x isKindOf [ "Binocular", configFile >> "CfgWeapons" ] });
if !(_binoculars isEqualTo []) then {

Same for NVGoggles, they are all isKindOf "NVGoggles".

 

 

On 1/10/2019 at 9:45 PM, davidoss said:

private _goggles = _inventoryArray select {_x isKindOf ["None", configFile >> "CfgGlasses"] || _x isKindOf ["G_Diving", configFile >> "CfgGlasses"]};

private _goggles = _inventoryArray select { isClass( configFile >> "CfgGlasses" >> _x ) };

 

 

On 1/10/2019 at 9:45 PM, davidoss said:

private _goggles = _inventoryArray select {_x isKindOf ["None", configFile >> "CfgGlasses"] || _x isKindOf ["G_Diving", configFile >> "CfgGlasses"]};
if !(_goggles isEqualTo []) then {
	{
	private _added = false;
		if (true) then {
			if (_forEachIndex > 0) exitWith {
				switch (true) do {
					case (player canAddItemToUniform _x): {player addItemToUniform _x; _added = true;};
					case (player canAddItemToVest _x && {!_added}): {player addItemToVest _x; _added = true;};
					case (player canAddItemToBackpack _x && {!_added}): {player addItemToBackpack _x;};
					default {traderWeaponHolder addItemCargoGlobal [_x, 1]};
				};
			_inventoryArray deleteAt (_inventoryArray find _x);
			};
			player addGoggles _x;
			_inventoryArray deleteAt (_inventoryArray find _x);
		};
	} forEach _goggles;
};

 

_containers = [ backpackContainer player, vestContainer player, uniformContainer player, traderWeaponHolder ];

private _goggles = _inventoryArray select { isClass( configFile >> "CfgGlasses" >> _x ) };
if !(_goggles isEqualTo []) then {
	{
		_item = _x;
		{
			//If the container exists AND can add item
			if ( !isNull _x && { _x canAdd _item } ) exitWith {
				_x addItemCargoGlobal[ _item, 1 ];
				private _nul = _inventoryArray deleteAt (_inventoryArray find _item);
			};
		}forEach _containers;
	}forEach _goggles;
};

 

 

 

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

    

Quote

Use a container closed EH..

 

Thanks i did not though about..

 

You have right with multi vest this is just logic failure on me. I changed this to deleteAt.

 

For other stuff it will be useful at button BUY for now player can not have more stuff.

He can have only less that at dialog start

Its should work like this:

Player can sell and buy with one button.

In the case if he pull down something from trader and only this ,sell button stays inactive with tooltip "nothing to sale".

If at the same time is something to buy and sell, button sell stays active and button buy changes to buy&sell.

 

 

 

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

×