From 382f3bc451016d2425bf81f87d18d2a4c4e2dc07 Mon Sep 17 00:00:00 2001 From: ebaydayz Date: Tue, 2 Aug 2016 14:19:59 -0400 Subject: [PATCH] Add buying to and selling from dayz_onBack Also: - Fixed typo Z_fill(e)TradeTitle - Fixed "not enough slots to accept change" message shows when "not enough money" should show instead --- .../functions/z_at_allowBuying.sqf | 1 + .../AdvancedTrading/functions/z_at_buyItems.sqf | 16 +++++++++++----- .../functions/z_at_checkCloseVehicle.sqf | 4 ++-- .../functions/z_at_displayFreeSpace.sqf | 1 + ...lleTradeTitle.sqf => z_at_fillTradeTitle.sqf} | 2 +- .../functions/z_at_getContainer.sqf | 12 ++++++------ .../functions/z_at_getGearItems.sqf | 1 + .../AdvancedTrading/functions/z_at_sellItems.sqf | 13 +++++++++---- SQF/dayz_code/actions/AdvancedTrading/init.sqf | 2 +- 9 files changed, 33 insertions(+), 19 deletions(-) rename SQF/dayz_code/actions/AdvancedTrading/functions/{z_at_filleTradeTitle.sqf => z_at_fillTradeTitle.sqf} (89%) diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_allowBuying.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_allowBuying.sqf index e94525fe2..69f31c1a4 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_allowBuying.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_allowBuying.sqf @@ -39,6 +39,7 @@ if (_selection == 2) then { //gear _p = primaryWeapon player; _allowedPrimary = if (!isNil "_p" && _p != "") then {0} else {1}; + if (DZE_TwoPrimaries == 2 && dayz_onBack == "") then { _allowedPrimary = _allowedPrimary + 1; }; // (secondaryWeapon player) returns launcher, doesn't work for pistol _allowedSidearm = 1; diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_buyItems.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_buyItems.sqf index 37d8b1a6d..4f9a44b49 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_buyItems.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_buyItems.sqf @@ -1,6 +1,6 @@ private ["_weaponsToBuy","_backpacksToBuy","_toolsToBuy","_sidearmToBuy","_primaryToBuy","_priceToBuy" ,"_enoughMoney","_myMoney","_canBuy","_moneyInfo","_count","_success","_toolClasses","_itemsToLog" -,"_tCost","_bTotal","_backpack","_pistolMagsToBuy","_regularMagsToBuy"]; +,"_tCost","_bTotal","_backpack","_pistolMagsToBuy","_regularMagsToBuy","_hasPrimary","_p"]; if (count Z_BuyingArray < 1) exitWith { systemChat localize "STR_EPOCH_TRADE_BUY_NO_ITEMS"; }; @@ -29,7 +29,7 @@ if (Z_SingleCurrency) then { if ('PistolCore' in _parentClasses) then { _sidearmToBuy = _sidearmToBuy + (_x select 9); } else { - _primaryToBuy = _primaryToBuy + (_x select 9); // _ammount + _primaryToBuy = _primaryToBuy + (_x select 9); // _amount }; }; _priceToBuy = _priceToBuy + ((_x select 9)*(_x select 2)); @@ -115,7 +115,7 @@ if (Z_SingleCurrency) then { // Pre-check if player has enough room to accept change _success = if (Z_SingleCurrency) then { true } else { [player,_priceToBuy,_moneyInfo,true,_regularMagsToBuy] call Z_payDefault }; -if (!_success) exitWith { systemChat localize "STR_EPOCH_TRADE_GEAR_AND_BAG_FULL"; }; // Not enough room in gear or bag to accept change +if (!_success && _enoughMoney) exitWith { systemChat localize "STR_EPOCH_TRADE_GEAR_AND_BAG_FULL"; }; // Not enough room in gear or bag to accept change if (_enoughMoney) then { _bTotal = 0; @@ -205,8 +205,14 @@ if (_enoughMoney) then { { if (_x select 1 == "trade_weapons") then { _count = 0; - while { _count < (_x select 9)} do { - player addWeapon (_x select 0); + while {_count < (_x select 9)} do { + _p = primaryWeapon player; + _hasPrimary = if (!isNil "_p" && _p != "") then {true} else {false}; + if (_hasPrimary && getNumber (configFile >> "CfgWeapons" >> (_x select 0) >> "type") == 1) then { + dayz_onBack = _x select 0; //Add to back + } else { + player addWeapon (_x select 0); + }; _count = _count + 1; }; }; diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_checkCloseVehicle.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_checkCloseVehicle.sqf index a04dbcf60..5bb626570 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_checkCloseVehicle.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_checkCloseVehicle.sqf @@ -17,9 +17,9 @@ if (!isNull _vehicle) then { if (_this) then { // Set trade title, don't set on menu start up since gear is selected initially. systemChat format[localize "STR_EPOCH_TRADE_SELECTED",typeOf Z_vehicle]; if (Z_Selling) then { - [format[localize "STR_EPOCH_TRADE_SELLING_FROM", typeOf Z_vehicle]] call Z_filleTradeTitle; + [format[localize "STR_EPOCH_TRADE_SELLING_FROM", typeOf Z_vehicle]] call Z_fillTradeTitle; } else { - [format[localize "STR_EPOCH_TRADE_BUYING_IN", typeOf Z_vehicle]] call Z_filleTradeTitle; + [format[localize "STR_EPOCH_TRADE_BUYING_IN", typeOf Z_vehicle]] call Z_fillTradeTitle; }; }; }; diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_displayFreeSpace.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_displayFreeSpace.sqf index 70d6261a5..818d8619f 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_displayFreeSpace.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_displayFreeSpace.sqf @@ -13,6 +13,7 @@ if (_selection == 2) then { //gear _p = primaryWeapon player; _allowedPrimary = if (!isNil "_p" && _p != "") then {0} else {1}; + if (DZE_TwoPrimaries == 2 && dayz_onBack == "") then { _allowedPrimary = _allowedPrimary + 1; }; _allowedSidearm = 1; { diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_filleTradeTitle.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_fillTradeTitle.sqf similarity index 89% rename from SQF/dayz_code/actions/AdvancedTrading/functions/z_at_filleTradeTitle.sqf rename to SQF/dayz_code/actions/AdvancedTrading/functions/z_at_fillTradeTitle.sqf index 2b29a83ea..16a3b2b5b 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_filleTradeTitle.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_fillTradeTitle.sqf @@ -1,5 +1,5 @@ /** -* [_text] call Z_filleTradeTitle +* [_text] call Z_fillTradeTitle * * @param String _this select 0 (_text) -> The text you want in the label. * diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_getContainer.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_getContainer.sqf index c3aeafcfb..261f639ed 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_getContainer.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_getContainer.sqf @@ -25,7 +25,7 @@ if (Z_Selling) then { switch (_lbIndex) do { case 0: { //backpack if (!isNull _backpack) then { - [localize "STR_EPOCH_TRADE_SELLING_BACKPACK"] call Z_filleTradeTitle; + [localize "STR_EPOCH_TRADE_SELLING_BACKPACK"] call Z_fillTradeTitle; Z_SellingFrom = 0; call Z_getBackpackItems; } else { @@ -36,7 +36,7 @@ if (Z_Selling) then { case 1: { //vehicle _canBuyInVehicle = true call Z_checkCloseVehicle; if (_canBuyInVehicle) then { - [localize "STR_EPOCH_TRADE_SELLING_VEHICLE"] call Z_filleTradeTitle; + [localize "STR_EPOCH_TRADE_SELLING_VEHICLE"] call Z_fillTradeTitle; Z_SellingFrom = 1; call Z_getVehicleItems; } else { @@ -45,7 +45,7 @@ if (Z_Selling) then { }; }; case 2: { //gear - [localize "STR_EPOCH_TRADE_SELLING_GEAR"] call Z_filleTradeTitle; + [localize "STR_EPOCH_TRADE_SELLING_GEAR"] call Z_fillTradeTitle; Z_SellingFrom = 2; call Z_getGearItems; }; @@ -57,7 +57,7 @@ if (Z_Selling) then { case 0: { //backpack if (!isNull _backpack) then { Z_SellingFrom = 0; - [localize "STR_EPOCH_TRADE_BUYING_BACKPACK"] call Z_filleTradeTitle; + [localize "STR_EPOCH_TRADE_BUYING_BACKPACK"] call Z_fillTradeTitle; [0] call Z_displayFreeSpace; } else { ctrlSetText [Z_AT_TRADERLINE1, localize "STR_EPOCH_TRADE_NO_BACKPACK"]; @@ -68,7 +68,7 @@ if (Z_Selling) then { _canBuyInVehicle = true call Z_checkCloseVehicle; if (_canBuyInVehicle) then { Z_SellingFrom = 1; - [localize "STR_EPOCH_TRADE_BUYING_VEHICLE"] call Z_filleTradeTitle; + [localize "STR_EPOCH_TRADE_BUYING_VEHICLE"] call Z_fillTradeTitle; [1] call Z_displayFreeSpace; } else { ctrlSetText [Z_AT_TRADERLINE1, localize "STR_EPOCH_PLAYER_245"]; @@ -77,7 +77,7 @@ if (Z_Selling) then { }; case 2: { //gear Z_SellingFrom = 2; - [localize "STR_EPOCH_TRADE_BUYING_GEAR"] call Z_filleTradeTitle; + [localize "STR_EPOCH_TRADE_BUYING_GEAR"] call Z_fillTradeTitle; [2] call Z_displayFreeSpace; }; }; diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_getGearItems.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_getGearItems.sqf index ef0860301..519a6b569 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_getGearItems.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_getGearItems.sqf @@ -11,6 +11,7 @@ Z_SellArray = []; Z_SellableArray = []; _mags = magazines player; _weaps = weapons player; +_weaps set [count _weaps,dayz_onBack]; _bag = unitBackpack player; _bags = if (isNull _bag) then {[]} else {[typeOf _bag]}; diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_sellItems.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_sellItems.sqf index 621de4efd..eebf75996 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_sellItems.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_sellItems.sqf @@ -107,11 +107,11 @@ _tSold = _itemsArray + _weaponsArray + _bpArray + _vehArray; if (Z_SellingFrom == 0) then { _outcome = [unitBackpack player,_itemsArray,_weaponsArray, _vehArray] call ZUPA_fnc_removeWeaponsAndMagazinesCargo; - systemchat format[localize "STR_EPOCH_TRADE_SELL_IN_BACKPACK",count _tSold]; + systemChat format[localize "STR_EPOCH_TRADE_SELL_IN_BACKPACK",count _tSold]; }; if (Z_SellingFrom == 1) then { _outcome = [Z_vehicle,_itemsArray,_weaponsArray,_vehArray] call ZUPA_fnc_removeWeaponsAndMagazinesCargo; - systemchat format[localize "STR_EPOCH_TRADE_SELL_IN_VEHICLE",count _tSold,typeOf Z_vehicle]; + systemChat format[localize "STR_EPOCH_TRADE_SELL_IN_VEHICLE",count _tSold,typeOf Z_vehicle]; }; _itemsToLog set [0,(_itemsArray + _weaponsArray + _bpArray + [typeOf Z_vehicle])]; @@ -140,7 +140,12 @@ if (Z_SellingFrom == 2) then { _type = _x select 1; if (_type == "trade_items") then {_name = configFile >> "CfgMagazines" >> _name;}; if (_type == "trade_weapons") then {_name = configFile >> "CfgWeapons" >> _name;}; - _localResult = [player,_name,1] call BIS_fnc_invRemove; // Use config for BIS_fnc_invRemove + if (_x select 0 == dayz_onBack) then { + dayz_onBack = ""; // Remove from back + _localResult = 1; + } else { + _localResult = [player,_name,1] call BIS_fnc_invRemove; // Use config for BIS_fnc_invRemove + }; if (_localResult != 1) then { if (_x select 1 == "trade_items") then { _mA set [count(_mA),0]; @@ -168,7 +173,7 @@ if (Z_SellingFrom == 2) then { if (_bagTraded) then { _outcome set [2,[1]]; }; - systemchat format[localize "STR_EPOCH_TRADE_SELL_IN_GEAR",count _tSold]; + systemChat format[localize "STR_EPOCH_TRADE_SELL_IN_GEAR",count _tSold]; }; {_itemsToLog set [1, (_itemsToLog select 1) + _x]} forEach _outcome; diff --git a/SQF/dayz_code/actions/AdvancedTrading/init.sqf b/SQF/dayz_code/actions/AdvancedTrading/init.sqf index 7b1bc492b..99032fc45 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/init.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/init.sqf @@ -55,7 +55,7 @@ if (isNil "Z_AdvancedTradingInit") then { ZUPA_fnc_removeWeaponsAndMagazinesCargo = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\zupa_fnc_removeWeaponsAndMagazinesCargo.sqf"); - Z_filleTradeTitle = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\z_at_filleTradeTitle.sqf"); + Z_fillTradeTitle = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\z_at_fillTradeTitle.sqf"); Z_clearLists = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\z_at_clearLists.sqf"); Z_clearSellableList = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\z_at_clearSellableList.sqf"); Z_clearBuyList = compile preprocessFileLineNumbers (Z_AT_FolderLocation + "\functions\z_at_clearBuyList.sqf");