mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-14 20:13:13 +03:00
Fix return change overflow check
Thanks @oiad - Added compensation for money which will be removed from gear and backpack - Improved readability
This commit is contained in:
@@ -15,6 +15,8 @@ if (!_justChecking) then {
|
|||||||
_nil = [player, _x , 1] call BIS_fnc_invRemove;
|
_nil = [player, _x , 1] call BIS_fnc_invRemove;
|
||||||
} count _moneyInGear;
|
} count _moneyInGear;
|
||||||
|
|
||||||
|
_moneyInGear = []; // Clear since money is removed now
|
||||||
|
|
||||||
if (count _moneyInBackpack > 0) then {
|
if (count _moneyInBackpack > 0) then {
|
||||||
_nil = [unitBackpack _player, _moneyInBackpack, [], []] call ZUPA_fnc_removeWeaponsAndMagazinesCargo;
|
_nil = [unitBackpack _player, _moneyInBackpack, [], []] call ZUPA_fnc_removeWeaponsAndMagazinesCargo;
|
||||||
};
|
};
|
||||||
@@ -26,7 +28,7 @@ if (!_justChecking) then {
|
|||||||
if (_totalWorth - _toPay == 0) then { // Money in inventory was exact amount
|
if (_totalWorth - _toPay == 0) then { // Money in inventory was exact amount
|
||||||
_success = true;
|
_success = true;
|
||||||
} else {
|
} else {
|
||||||
_success = [_toPay,_totalWorth,_justChecking,_regularMagsToBuy] call Z_returnChange;
|
_success = [_toPay,_totalWorth,_justChecking,_regularMagsToBuy,_moneyInGear,_moneyInBackpack] call Z_returnChange;
|
||||||
};
|
};
|
||||||
|
|
||||||
_success
|
_success
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
// Made for DayZ Epoch by vbawol edited for AdvancedTrading by Zupa
|
// Made for DayZ Epoch by vbawol edited for AdvancedTrading by Zupa
|
||||||
private ["_return_change","_ItemTopaz","_GemTotal","_GemTotal2","_ItemObsidian","_ItemSapphire","_ItemAmethyst","_ItemEmerald","_ItemCitrine","_ItemRuby","_gem","_value","_total","_briefcase_100oz_a","_gold_10oz_a","_gold_10oz_b","_briefcase_100oz","_gold_10oz","_gold_1oz_a","_gold_1oz_b","_gold_1oz","_silver_10oz_a","_silver_10oz_b","_silver_10oz","_silver_1oz_a","_silver_1oz_b","_silver_1oz","_successful","_trade_total","_total_currency","_addRegularMag","_justChecking","_magsAdded","_regularMagsToBuy"];
|
private ["_return_change","_ItemTopaz","_GemTotal","_GemTotal2","_ItemObsidian","_ItemSapphire",
|
||||||
|
"_ItemAmethyst","_ItemEmerald","_ItemCitrine","_ItemRuby","_gem","_value","_total","_briefcase_100oz_a",
|
||||||
|
"_gold_10oz_a","_gold_10oz_b","_briefcase_100oz","_gold_10oz","_gold_1oz_a","_gold_1oz_b","_gold_1oz",
|
||||||
|
"_silver_10oz_a","_silver_10oz_b","_silver_10oz","_silver_1oz_a","_silver_1oz_b","_silver_1oz",
|
||||||
|
"_successful","_trade_total","_total_currency","_addRegularMag","_justChecking","_moneyAdded",
|
||||||
|
"_regularMagsToBuy","_moneyInGear","_moneyInBackpack"];
|
||||||
|
|
||||||
_successful = false;
|
_successful = false;
|
||||||
_trade_total = _this select 0;
|
_trade_total = _this select 0;
|
||||||
_total_currency = _this select 1;
|
_total_currency = _this select 1;
|
||||||
_justChecking = _this select 2;
|
_justChecking = _this select 2;
|
||||||
_regularMagsToBuy = _this select 3;
|
_regularMagsToBuy = _this select 3;
|
||||||
_magsAdded = 0;
|
_moneyInGear = _this select 4;
|
||||||
|
_moneyInBackpack = _this select 5;
|
||||||
|
_moneyAdded = 0;
|
||||||
Z_ChangeInBackpack = false;
|
Z_ChangeInBackpack = false;
|
||||||
Z_ChangeOverflow = false;
|
Z_ChangeOverflow = false;
|
||||||
|
|
||||||
@@ -18,37 +25,43 @@ if (!Z_Selling) then {
|
|||||||
};
|
};
|
||||||
|
|
||||||
_addRegularMag = {
|
_addRegularMag = {
|
||||||
private ["_backpack","_freeBagSpace","_freeSpace","_regularMags","_justChecking","_magsAdded","_item","_gearSpace","_enoughRoom","_regularMagsToBuy"];
|
private ["_backpack","_freeBagSpace","_freeSpace","_regularMags","_justChecking","_moneyAdded","_item","_enoughRoom","_regularMagsToBuy","_moneyInGear","_moneyInBackpack","_freeGearSlots"];
|
||||||
|
|
||||||
_magsAdded = _this select 0;
|
_moneyAdded = _this select 0; // Return change
|
||||||
_justChecking = _this select 1;
|
_justChecking = _this select 1;
|
||||||
_item = _this select 2;
|
_item = _this select 2;
|
||||||
|
if (_justChecking) then {
|
||||||
_regularMagsToBuy = _this select 3;
|
_regularMagsToBuy = _this select 3;
|
||||||
|
_moneyInGear = count (_this select 4); // Will be removed
|
||||||
|
_moneyInBackpack = count (_this select 5); // Will be removed
|
||||||
|
} else {
|
||||||
|
_regularMagsToBuy = 0; // All bought items are already in gear
|
||||||
|
_moneyInGear = 0; // All money was removed in Z_payDefault
|
||||||
|
_moneyInBackpack = 0; // All money was removed in Z_payDefault
|
||||||
|
};
|
||||||
|
|
||||||
_freeBagSpace = 0;
|
|
||||||
_regularMags = {(getNumber (configFile >> "CfgMagazines" >> _x >> "type") == 256)} count (magazines player); // 256 = WeaponSlotItem (normal magazine)
|
_regularMags = {(getNumber (configFile >> "CfgMagazines" >> _x >> "type") == 256)} count (magazines player); // 256 = WeaponSlotItem (normal magazine)
|
||||||
_gearSpace = ((12 - (_regularMags + _regularMagsToBuy)) > 0);
|
_freeGearSlots = 12 - ((_regularMags + _regularMagsToBuy + _moneyAdded) - _moneyInGear);
|
||||||
|
|
||||||
if (_justChecking or !_gearSpace) then {
|
if (_justChecking or _freeGearSlots < 0) then {
|
||||||
|
_freeBagSpace = 0;
|
||||||
_backpack = unitBackpack player;
|
_backpack = unitBackpack player;
|
||||||
if (!isNull _backpack) then {
|
if (!isNull _backpack) then {
|
||||||
_freeSpace = [_backpack,0,0,0,0] call Z_calcFreeSpace;
|
_freeSpace = [_backpack,0,0,0,0] call Z_calcFreeSpace;
|
||||||
_freeBagSpace = (_freeSpace select 4) - (_freeSpace select 0);
|
_freeBagSpace = (_freeSpace select 4) - (_freeSpace select 0);
|
||||||
};
|
};
|
||||||
|
_enoughRoom = (_freeGearSlots + _freeBagSpace + _moneyInBackpack) >= 0;
|
||||||
_enoughRoom = (((12 - (_regularMags + _regularMagsToBuy)) + _freeBagSpace) >= _magsAdded);
|
|
||||||
// Return change into vehicle or on ground is not advised due to potential for theft
|
// Return change into vehicle or on ground is not advised due to potential for theft
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_justChecking) exitWith {_enoughRoom};
|
if (_justChecking) exitWith {_enoughRoom};
|
||||||
|
|
||||||
if (_gearSpace) then {
|
if (_freeGearSlots >= 0) then {
|
||||||
player addMagazine _item;
|
player addMagazine _item;
|
||||||
} else {
|
} else {
|
||||||
if (Z_Selling) then {
|
if (Z_Selling) then {
|
||||||
// Items are removed before change is calculated in sellItems, so exiting sale if _enoughRoom=false; is not an option for now.
|
// Items are removed before change is calculated in sellItems, so exiting sale if _enoughRoom=false; is not an option for now.
|
||||||
// Bandaid: notify player of overflow
|
// Lazy solution: notify player of overflow. Overflow in backpack falls on ground. Overflow in gear does not.
|
||||||
// Overflow in backpack falls on ground. Overflow in gear does not.
|
|
||||||
player addMagazine _item;
|
player addMagazine _item;
|
||||||
Z_ChangeOverflow = true;
|
Z_ChangeOverflow = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -149,76 +162,76 @@ if (_return_change > 0) then {
|
|||||||
|
|
||||||
if (_ItemTopaz > 0) then {
|
if (_ItemTopaz > 0) then {
|
||||||
for "_x" from 1 to _ItemTopaz do {
|
for "_x" from 1 to _ItemTopaz do {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemTopaz",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemTopaz"] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_ItemObsidian > 0) then {
|
if (_ItemObsidian > 0) then {
|
||||||
for "_x" from 1 to _ItemObsidian do {
|
for "_x" from 1 to _ItemObsidian do {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemObsidian",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemObsidian"] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_ItemSapphire > 0) then {
|
if (_ItemSapphire > 0) then {
|
||||||
for "_x" from 1 to _ItemSapphire do {
|
for "_x" from 1 to _ItemSapphire do {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemSapphire",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemSapphire"] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_ItemAmethyst > 0) then {
|
if (_ItemAmethyst > 0) then {
|
||||||
for "_x" from 1 to _ItemAmethyst do {
|
for "_x" from 1 to _ItemAmethyst do {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemAmethyst",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemAmethyst"] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_ItemEmerald > 0) then {
|
if (_ItemEmerald > 0) then {
|
||||||
for "_x" from 1 to _ItemEmerald do {
|
for "_x" from 1 to _ItemEmerald do {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemEmerald",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemEmerald"] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_ItemCitrine > 0) then {
|
if (_ItemCitrine > 0) then {
|
||||||
for "_x" from 1 to _ItemCitrine do {
|
for "_x" from 1 to _ItemCitrine do {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemCitrine",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemCitrine"] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_ItemRuby > 0) then {
|
if (_ItemRuby > 0) then {
|
||||||
for "_x" from 1 to _ItemRuby do {
|
for "_x" from 1 to _ItemRuby do {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemRuby",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemRuby"] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_briefcase_100oz > 0) then {
|
if (_briefcase_100oz > 0) then {
|
||||||
for "_x" from 1 to _briefcase_100oz do {
|
for "_x" from 1 to _briefcase_100oz do {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemBriefcase100oz",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemBriefcase100oz"] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_gold_10oz > 0) then {
|
if (_gold_10oz > 0) then {
|
||||||
if (_gold_10oz == 1) then {
|
if (_gold_10oz == 1) then {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemGoldBar10oz",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemGoldBar10oz"] call _addRegularMag; };
|
||||||
} else {
|
} else {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,format["ItemBriefcase%1oz",floor(_gold_10oz*10)],0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,format["ItemBriefcase%1oz",floor(_gold_10oz*10)]] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_gold_1oz > 0) then {
|
if (_gold_1oz > 0) then {
|
||||||
if (_gold_1oz == 1) then {
|
if (_gold_1oz == 1) then {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemGoldBar",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemGoldBar"] call _addRegularMag; };
|
||||||
} else {
|
} else {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,format["ItemGoldBar%1oz",_gold_1oz],0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,format["ItemGoldBar%1oz",_gold_1oz]] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_silver_10oz > 0) then {
|
if (_silver_10oz > 0) then {
|
||||||
if (_silver_10oz == 1) then {
|
if (_silver_10oz == 1) then {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemSilverBar10oz",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemSilverBar10oz"] call _addRegularMag; };
|
||||||
} else {
|
} else {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,format["ItemBriefcaseS%1oz",floor(_silver_10oz*10)],0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,format["ItemBriefcaseS%1oz",floor(_silver_10oz*10)]] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (_silver_1oz > 0) then {
|
if (_silver_1oz > 0) then {
|
||||||
if (_silver_1oz == 1) then {
|
if (_silver_1oz == 1) then {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,"ItemSilverBar",0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,"ItemSilverBar"] call _addRegularMag; };
|
||||||
} else {
|
} else {
|
||||||
if (_justChecking) then { _magsAdded = _magsAdded + 1; } else { [0,false,format["ItemSilverBar%1oz",_silver_1oz],0] call _addRegularMag; };
|
if (_justChecking) then { _moneyAdded = _moneyAdded + 1; } else { [1,false,format["ItemSilverBar%1oz",_silver_1oz]] call _addRegularMag; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_justChecking) then {
|
if (_justChecking) then {
|
||||||
_successful = [_magsAdded,true,0,_regularMagsToBuy] call _addRegularMag;
|
_successful = [_moneyAdded,true,"",_regularMagsToBuy,_moneyInGear,_moneyInBackpack] call _addRegularMag;
|
||||||
} else {
|
} else {
|
||||||
_successful = true;
|
_successful = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ if (typeName _money == "SCALAR") then {
|
|||||||
_success = [player,_money] call SC_fnc_addCoins;
|
_success = [player,_money] call SC_fnc_addCoins;
|
||||||
systemChat format[localize "STR_EPOCH_TRADE_SUCCESS_CHANGE", _money , CurrencyName];
|
systemChat format[localize "STR_EPOCH_TRADE_SUCCESS_CHANGE", _money , CurrencyName];
|
||||||
} else {
|
} else {
|
||||||
_success = [_money,0,false,0] call Z_returnChange;
|
_success = [_money,0,false,0,[],[]] call Z_returnChange;
|
||||||
_tCost = "";
|
_tCost = "";
|
||||||
_tCost = _money call z_calcDefaultCurrencyNoImg;
|
_tCost = _money call z_calcDefaultCurrencyNoImg;
|
||||||
if (_tCost != "") then { systemChat format[localize "STR_EPOCH_TRADE_SELL_SUCCESS",_tCost]; };
|
if (_tCost != "") then { systemChat format[localize "STR_EPOCH_TRADE_SELL_SUCCESS",_tCost]; };
|
||||||
|
|||||||
Reference in New Issue
Block a user