mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-14 04:02:37 +03:00
* Advanced trading fixes Fixes a few issues and a dupe with advanced trading as well as some localization of where a vehicle key is going. Z_at_buyItems: Now adds localization for the key getting added to your toolbelt, backpack and vehicle, this stops players thinking they didn't get a key when infact it was added to their backpack/vehicle. Z_at_canAfford.sqf: This fixes a dupe from a bad copy paste for whomever wrote this script, it was using _backpackMoney in the z_allowTakingMoneyFromVehicle part, changed to the proper variable _vehicleMoney. z_at_fillBuyableList.sqf: this fixes a bug where a vehicle would show green even when it isn't local, just basically added more checking to make sure the vehicle it's making green in the list is a) local, b) alive and that the typeOf == _name. z_at_logTrade.sqf: fixes some tidyness. advancedTrading/init.sqf: adds a z_checkCloseVehicle call otherwise even with Z_AllowTakingMoneyFromVehicle = true it will not get currency from your vehicle until you clicked on the "Vehicle" tab. dayz_server/server_tradeObject.sqf: More tidying as per the z_at_logTrade and removes the useless Player:, as it is obvious a player has bought something not an AI. dayz_server/server_handleSafeGear.sqf: Makes the diag_log at the end more human readable with GPS coordinates as well as the lock code for the safe or the lockbox. * advanced trading fixes. I hate you github WHY U GET MISSED?? STUPID GITHUB. * snappoints changes Fixes the issue @SmokeyBR reported https://github.com/EpochModTeam/DayZ-Epoch/issues/1766#issuecomment-253864795 Adds all floor types to snap list for all barriers so you can snap a sandbag etc to a floor instead of manually lining it up
284 lines
11 KiB
Plaintext
284 lines
11 KiB
Plaintext
private ["_activatingPlayer","_bTotal","_backpack","_backpacksToBuy","_buyVehicle","_buyingType","_canBuy","_count","_dir","_enoughMoney","_hasPrimary","_helipad","_isKeyOK","_item2Add","_itemsToLog","_keyColor","_keyNumber","_keySelected","_location","_moneyInfo","_myMoney","_p","_parentClasses","_part_out","_pistolMagsToBuy","_price","_priceToBuy","_primaryToBuy","_regularMagsToBuy","_sidearmToBuy","_sign","_success","_tCost","_toolAmounts","_toolClasses","_toolsToBuy","_vehiclesToBuy","_weaponsToBuy","_worth"];
|
|
|
|
if (count Z_BuyingArray < 1) exitWith { systemChat localize "STR_EPOCH_TRADE_BUY_NO_ITEMS"; };
|
|
|
|
_pistolMagsToBuy = 0;
|
|
_regularMagsToBuy = 0;
|
|
_weaponsToBuy = 0;
|
|
_backpacksToBuy = 0;
|
|
_toolsToBuy = 0;
|
|
_sidearmToBuy = 0;
|
|
_primaryToBuy = 0;
|
|
_vehiclesToBuy = 0;
|
|
_priceToBuy = 0;
|
|
_toolAmounts = [];
|
|
_toolClasses = [];
|
|
_itemsToLog = [[],[],[],"buy"];
|
|
|
|
if (Z_SingleCurrency) then {
|
|
{
|
|
if (_x select 1 == "trade_weapons") then {
|
|
_parentClasses = [(configFile >> "CfgWeapons" >> (_x select 0)),true] call BIS_fnc_returnParents;
|
|
if ('ItemCore' in _parentClasses || 'Binocular' in _parentClasses) then {
|
|
_toolsToBuy = _toolsToBuy + (_x select 9);
|
|
_toolClasses set [count _toolClasses,(_x select 0)];
|
|
_toolAmounts set [count _toolAmounts,(_x select 9)];
|
|
} else {
|
|
_weaponsToBuy = _weaponsToBuy + (_x select 9);
|
|
if ('PistolCore' in _parentClasses) then {
|
|
_sidearmToBuy = _sidearmToBuy + (_x select 9);
|
|
} else {
|
|
_primaryToBuy = _primaryToBuy + (_x select 9); // _amount
|
|
};
|
|
};
|
|
_priceToBuy = _priceToBuy + ((_x select 9)*(_x select 2));
|
|
};
|
|
if (_x select 1 == "trade_items") then {
|
|
if (getNumber (configFile >> "CfgMagazines" >> (_x select 0) >> "type") == 16) then { // 16 = WeaponSlotHandGunItem (pistol ammo slot)
|
|
_pistolMagsToBuy = _pistolMagsToBuy + (_x select 9);
|
|
} else {
|
|
_regularMagsToBuy = _regularMagsToBuy + (_x select 9);
|
|
};
|
|
_priceToBuy = _priceToBuy + ((_x select 9)*(_x select 2));
|
|
};
|
|
if (_x select 1 == "trade_backpacks") then {
|
|
_backpacksToBuy = _backpacksToBuy + (_x select 9) ;
|
|
_priceToBuy = _priceToBuy + ((_x select 9)*(_x select 2)); // _price * _amount
|
|
};
|
|
if ((_x select 1) in DZE_tradeVehicle) then {
|
|
_vehiclesToBuy = _vehiclesToBuy + (_x select 9) ;
|
|
_priceToBuy = _priceToBuy + ((_x select 9)*(_x select 2)); // _price * _amount
|
|
};
|
|
_itemsToLog set [0, (_itemsToLog select 0) + [_x select 0]];
|
|
_itemsToLog set [1, (_itemsToLog select 1) + [_x select 9]];
|
|
_itemsToLog set [2, (_itemsToLog select 2) + [((_x select 9)*(_x select 2))]];
|
|
} count Z_BuyingArray;
|
|
} else {
|
|
{
|
|
if (_x select 1 == "trade_weapons") then {
|
|
_parentClasses = [(configFile >> "CfgWeapons" >> (_x select 0)),true] call BIS_fnc_returnParents;
|
|
if ('ItemCore' in _parentClasses || 'Binocular' in _parentClasses) then {
|
|
_toolsToBuy = _toolsToBuy + (_x select 9);
|
|
_toolClasses set [count _toolClasses,(_x select 0)];
|
|
_toolAmounts set [count _toolAmounts,(_x select 9)];
|
|
} else {
|
|
_weaponsToBuy = _weaponsToBuy + (_x select 9);
|
|
if ('PistolCore' in _parentClasses) then {
|
|
_sidearmToBuy = _sidearmToBuy + (_x select 9);
|
|
} else {
|
|
_primaryToBuy = _primaryToBuy + (_x select 9);
|
|
};
|
|
};
|
|
_priceToBuy = _priceToBuy + ((_x select 11)*(_x select 2)*(_x select 9)); // _worth * _price * _amount
|
|
};
|
|
if (_x select 1 == "trade_items") then {
|
|
if (getNumber (configFile >> "CfgMagazines" >> (_x select 0) >> "type") == 16) then { // 16 = WeaponSlotHandGunItem (pistol ammo slot)
|
|
_pistolMagsToBuy = _pistolMagsToBuy + (_x select 9);
|
|
} else {
|
|
_regularMagsToBuy = _regularMagsToBuy + (_x select 9);
|
|
};
|
|
_priceToBuy = _priceToBuy + ((_x select 11) *(_x select 2)*(_x select 9));
|
|
};
|
|
if (_x select 1 == "trade_backpacks") then {
|
|
_backpacksToBuy = _backpacksToBuy + (_x select 9) ;
|
|
_priceToBuy = _priceToBuy + ((_x select 11)*(_x select 2)*(_x select 9));
|
|
};
|
|
if ((_x select 1) in DZE_tradeVehicle) then {
|
|
_vehiclesToBuy = _vehiclesToBuy + (_x select 9) ;
|
|
_priceToBuy = _priceToBuy + ((_x select 11)*(_x select 2)*(_x select 9));
|
|
};
|
|
_itemsToLog set [0, (_itemsToLog select 0) + [_x select 0]];
|
|
_itemsToLog set [1, (_itemsToLog select 1) + [_x select 9]];
|
|
_itemsToLog set [2, (_itemsToLog select 2) + [((_x select 11)*(_x select 2)*(_x select 9))]];
|
|
} count Z_BuyingArray;
|
|
};
|
|
|
|
_canBuy = [_weaponsToBuy,[_pistolMagsToBuy,_regularMagsToBuy],_backpacksToBuy,_toolsToBuy,_sidearmToBuy,_primaryToBuy,_vehiclesToBuy,_toolClasses,_toolAmounts] call Z_allowBuying;
|
|
if (!_canBuy) exitWith {}; // Keep systemChat reasons for failure in Z_allowBuying for sanity
|
|
|
|
_myMoney = player getVariable[Z_MoneyVariable,0];
|
|
|
|
_enoughMoney = false;
|
|
|
|
_moneyInfo = [false, [], [], [], 0];
|
|
|
|
if (Z_SingleCurrency) then {
|
|
if (_myMoney >= _priceToBuy) then {
|
|
_enoughMoney = true;
|
|
} else {
|
|
_enoughMoney = false;
|
|
};
|
|
} else {
|
|
_moneyInfo = _priceToBuy call Z_canAfford;
|
|
_enoughMoney = _moneyInfo select 0;
|
|
};
|
|
|
|
// 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 && _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;
|
|
_buyVehicle = {
|
|
private "_location";
|
|
_part_out = _this select 0;
|
|
_buyingType = _this select 1;
|
|
_keySelected = "0";
|
|
_isKeyOK= false;
|
|
if (_buyingType in DZE_tradeVehicleKeyless) then {
|
|
_isKeyOK = true;
|
|
} else {
|
|
_keyColor = ["Green","Red","Blue","Yellow","Black"] call BIS_fnc_selectRandom;
|
|
_keyNumber = (floor(random 2500)) + 1;
|
|
_keySelected = format["ItemKey%1%2",_keyColor,_keyNumber];
|
|
_isKeyOK = isClass(configFile >> "CfgWeapons" >> _keySelected);
|
|
};
|
|
if (!_isKeyOK) exitWith {localize "str_epoch_player_107" call dayz_rollingMessages; "";};
|
|
_activatingPlayer = player;
|
|
_dir = round(random 360);
|
|
_helipad = nearestObjects [player, ["HeliHCivil","HeliHempty"], 100];
|
|
|
|
// Note server now uses createVehicle "NONE" so next closest safePos is found automatically if location is blocked
|
|
if (count _helipad > 0) then {
|
|
_location = getPosATL (_helipad select 0);
|
|
} else {
|
|
_location = [player] call FNC_GetPos;
|
|
};
|
|
|
|
_sign = "Sign_arrow_down_large_EP1" createVehicleLocal [0,0,0];
|
|
_sign setPos _location;
|
|
_location = [_sign] call FNC_GetPos;
|
|
[_part_out,_sign] call fn_waitForObject;
|
|
|
|
if (_buyingType in DZE_tradeVehicleKeyless) then {
|
|
PVDZE_veh_Publish2 = [[_dir,_location],_part_out,true,"0",_activatingPlayer];
|
|
} else {
|
|
PVDZE_veh_Publish2 = [[_dir,_location],_part_out,false,_keySelected,_activatingPlayer];
|
|
};
|
|
publicVariableServer "PVDZE_veh_Publish2";
|
|
_keySelected;
|
|
};
|
|
//systemChat localize "STR_EPOCH_PLAYER_105"; // "Stand still to complete trade". Medic animation loop no longer used.
|
|
|
|
closeDialog 2;
|
|
|
|
if (Z_SellingFrom == 0) then { //backpack
|
|
_backpack = unitBackpack player;
|
|
{
|
|
if (_x select 1 == "trade_weapons") then {
|
|
_backpack addWeaponCargoGlobal [_x select 0, _x select 9];
|
|
};
|
|
if (_x select 1 == "trade_items") then {
|
|
_backpack addMagazineCargoGlobal [_x select 0, _x select 9];
|
|
};
|
|
if ((_x select 1) in DZE_tradeVehicle) then {
|
|
_item2Add = [(_x select 0), (_x select 1)] call _buyVehicle;
|
|
if (_item2Add != "0") then {
|
|
_backpack addWeaponCargoGlobal [_item2Add, 1];
|
|
};
|
|
};
|
|
_bTotal = _bTotal + (_x select 9);
|
|
} count Z_BuyingArray;
|
|
if (_item2Add != "0") then {
|
|
systemChat format[localize "STR_EPOCH_TRADE_BUY_VEH_IN_BACKPACK",(Z_BuyingArray select 0) select 3];
|
|
} else {
|
|
systemChat format[localize "STR_EPOCH_TRADE_BUY_IN_BACKPACK",_bTotal];
|
|
};
|
|
};
|
|
|
|
if (Z_SellingFrom == 1) then { //vehicle
|
|
{
|
|
if (_x select 1 == "trade_weapons") then {
|
|
Z_vehicle addWeaponCargoGlobal [_x select 0, _x select 9];
|
|
};
|
|
if (_x select 1 == "trade_items") then {
|
|
Z_vehicle addMagazineCargoGlobal [_x select 0, _x select 9];
|
|
};
|
|
if (_x select 1 == "trade_backpacks") then {
|
|
Z_vehicle addBackpackCargoGlobal [_x select 0, _x select 9];
|
|
};
|
|
if ((_x select 1) in DZE_tradeVehicle) then {
|
|
_item2Add = [(_x select 0), (_x select 1)] call _buyVehicle;
|
|
if (_item2Add != "0") then {
|
|
Z_vehicle addWeaponCargoGlobal [_item2Add, 1];
|
|
};
|
|
};
|
|
_bTotal = _bTotal + (_x select 9);
|
|
} count Z_BuyingArray;
|
|
if (_item2Add != "0") then {
|
|
systemChat format[localize "STR_EPOCH_TRADE_BUY_VEH_IN_VEHICLE",(Z_BuyingArray select 0) select 3,typeOf (Z_vehicle)];
|
|
} else {
|
|
systemChat format[localize "STR_EPOCH_TRADE_BUY_IN_VEHICLE",_bTotal,typeOf Z_vehicle];
|
|
};
|
|
};
|
|
|
|
if (Z_SellingFrom == 2) then { //gear
|
|
{
|
|
if (_x select 1 == "trade_weapons") then {
|
|
_count = 0;
|
|
while {_count < (_x select 9)} do {
|
|
_p = primaryWeapon player;
|
|
_hasPrimary = if (_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;
|
|
};
|
|
};
|
|
if (_x select 1 == "trade_items") then {
|
|
_count = 0;
|
|
while { _count < (_x select 9)} do {
|
|
player addMagazine (_x select 0);
|
|
_count = _count + 1;
|
|
};
|
|
};
|
|
if (_x select 1 == "trade_backpacks") then {
|
|
player addBackpack (_x select 0);
|
|
};
|
|
if ((_x select 1) in DZE_tradeVehicle) then {
|
|
_item2Add = [(_x select 0), (_x select 1)] call _buyVehicle;
|
|
if (_item2Add != "0") then {
|
|
player addWeapon _item2Add;
|
|
};
|
|
};
|
|
_bTotal = _bTotal + (_x select 9);
|
|
} count Z_BuyingArray;
|
|
if (_item2Add != "0") then {
|
|
systemChat format[localize "STR_EPOCH_TRADE_BUY_VEH_IN_GEAR",(Z_BuyingArray select 0) select 3];
|
|
} else {
|
|
systemChat format[localize "STR_EPOCH_TRADE_BUY_IN_GEAR",_bTotal];
|
|
};
|
|
};
|
|
if (!Z_SingleCurrency) then {
|
|
_success = [player,_priceToBuy,_moneyInfo,false,0] call Z_payDefault;
|
|
if (_success) then {
|
|
_tCost = "";
|
|
_tCost = _priceToBuy call z_calcDefaultCurrencyNoImg;
|
|
if (_tCost != "") then { systemChat format[localize "STR_EPOCH_TRADE_BUY_SUCCESS",_tCost]; };
|
|
} else {
|
|
systemChat localize "STR_EPOCH_TRADE_DEBUG";
|
|
};
|
|
} else {
|
|
_success = [player,_priceToBuy] call SC_fnc_removeCoins;
|
|
if (_success) then {
|
|
systemChat format[localize "STR_EPOCH_TRADE_SUCCESS_COINS",[_priceToBuy] call BIS_fnc_numberText,CurrencyName];
|
|
} else {
|
|
systemChat localize "STR_EPOCH_TRADE_DEBUG";
|
|
};
|
|
};
|
|
_itemsToLog call Z_logTrade;
|
|
call player_forceSave;
|
|
if (Z_SellingFrom == 1) then {
|
|
PVDZ_veh_Save = [Z_vehicle,"gear"];
|
|
publicVariableServer "PVDZ_veh_Save";
|
|
};
|
|
} else {
|
|
if (Z_SingleCurrency) then {
|
|
systemChat format[localize "STR_EPOCH_TRADE_NEED_COINS",[_priceToBuy] call BIS_fnc_numberText,CurrencyName];
|
|
} else {
|
|
systemChat localize "STR_EPOCH_TRADE_NEED_MONEY";
|
|
};
|
|
};
|