From f4d770c617b4b207e0367e793f1f756feecc8bc6 Mon Sep 17 00:00:00 2001 From: A Man Date: Wed, 18 May 2022 18:09:29 +0200 Subject: [PATCH] Update maintain functions Thx iben --- SQF/dayz_code/actions/maintain_area.sqf | 281 ++++++++++-------- .../compile/server_maintainArea.sqf | 88 +++--- 2 files changed, 208 insertions(+), 161 deletions(-) diff --git a/SQF/dayz_code/actions/maintain_area.sqf b/SQF/dayz_code/actions/maintain_area.sqf index 7df08da93..888e03c19 100644 --- a/SQF/dayz_code/actions/maintain_area.sqf +++ b/SQF/dayz_code/actions/maintain_area.sqf @@ -17,156 +17,201 @@ Please see configVariables.sqf for the value of gems (DZE_GemWorthArray) and the */ -if (dayz_actionInProgress) exitWith {localize "STR_EPOCH_ACTIONS_2" call dayz_rollingMessages;}; +if (dayz_actionInProgress) exitWith { + localize "STR_EPOCH_ACTIONS_2" call dayz_rollingMessages +}; + dayz_actionInProgress = true; -private ["_maintain","_req","_target","_objects","_requirements","_count","_objects_filtered","_message1","_message2","_option","_line1","_line2","_plotDialog"]; -_target = (([player] call FNC_getPos) nearEntities ["Plastic_Pole_EP1_DZ",15]) select 0; -_objects = nearestObjects [_target, DZE_maintainClasses, DZE_maintainRange]; +local _objects = nearestObjects [ + (([player] call FNC_getPos) nearEntities ["Plastic_Pole_EP1_DZ", 15]) select 0 + ,DZE_maintainClasses, DZE_maintainRange +]; -_objects_filtered = []; -_requirements = []; -_count = 0; -_req = { - private ["_count","_amount","_itemText"]; +local _req = { + if (Z_SingleCurrency) exitWith { + [_this * DZE_maintainCurrencyRate, CurrencyName] + }; - _count = _this; - _amount = _count * DZE_maintainCurrencyRate; - _itemText = if (Z_SingleCurrency) then { CurrencyName } else { [_amount,true] call z_calcCurrency }; - - [_amount,_itemText] + local _amount = _this * DZE_maintainCurrencyRate; + [ + _amount + ,[_amount, true] call z_calcCurrency + ] }; -_maintain = { - private ["_requirements","_count","_amount","_itemText","_wealth","_success","_message1","_message2","_enoughMoney","_moneyInfo","_finished"]; - _count = count (_this select 0); - _requirements = _count call _req; +local _maintain = { + local _count = count _this; + local _requirements = _count call _req; - _amount = _requirements select 0; - _itemText = _requirements select 1; + local _amount = _requirements select 0; + local _itemText = _requirements select 1; - _enoughMoney = false; - _moneyInfo = [false, [], [], [], 0]; + local _enoughMoney = false; + local _moneyInfo = [false, [], [], [], 0]; + local _wealth = 0; + local _message = ""; - if (Z_SingleCurrency) then { - _wealth = player getVariable[(["cashMoney","globalMoney"] select Z_persistentMoney),0]; - _enoughMoney = (_wealth >= _amount); - } else { - Z_Selling = false; // Initialize gem currency before Z_canAfford. - _moneyInfo = _amount call Z_canAfford; - _enoughMoney = _moneyInfo select 0; - }; + if (Z_SingleCurrency) then { + _wealth = player getVariable[["cashMoney", "globalMoney"] select Z_persistentMoney, 0]; + _enoughMoney = _wealth >= _amount; + } else { + Z_Selling = false; // Initialize gem currency before Z_canAfford. + _moneyInfo = _amount call Z_canAfford; + _enoughMoney = _moneyInfo select 0; + }; - _success = if (Z_SingleCurrency) then { true } else { [player,_amount,_moneyInfo,true,0] call Z_payDefault }; + local _success = if (Z_SingleCurrency) then {true} else {[player, _amount, _moneyInfo, true, 0] 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 + // Not enough room in gear or bag to accept change. + if (!_success && {_enoughMoney}) exitWith { + systemChat localize "STR_EPOCH_TRADE_GEAR_AND_BAG_FULL" + }; - if (_enoughMoney) then { + if (_enoughMoney) exitWith { + closeDialog 1; + [player, getPosATL player, DZE_maintainRange, "repair"] spawn fnc_alertZombies; - closeDialog 1; - [player,(getPosATL player),DZE_maintainRange,"repair"] spawn fnc_alertZombies; + if !(["Medic",1] call fn_loopAction) exitWith {}; - _finished = ["Medic",1] call fn_loopAction; - if !(_finished) exitWith {}; + _success = if (Z_SingleCurrency) then {_amount <= _wealth} else {[player, _amount, _moneyInfo, false, 0] call Z_payDefault}; - _success = if (Z_SingleCurrency) then {_amount <= _wealth} else {[player,_amount,_moneyInfo,false,0] call Z_payDefault}; - if (_success) then { - ["Working",0,[100,15,10,0]] call dayz_NutritionSystem; + if (_success) then { + ["Working", 0, [100,15,10,0]] call dayz_NutritionSystem; - PVDZE_maintainArea = [netID player,1,_this select 0]; - publicVariableServer "PVDZE_maintainArea"; + PVDZE_maintainArea = [netId player, 1, _this]; + publicVariableServer "PVDZE_maintainArea"; - if (Z_SingleCurrency) then { - player setVariable[(["cashMoney","globalMoney"] select Z_persistentMoney),(_wealth - _amount),true]; - _message1 = format [localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_SUCCESS",_count,[_amount] call BIS_fnc_numberText,_itemText]; - } else { - _message1 = format [localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_SUCCESS",_count,_itemText,""]; - }; + if (Z_SingleCurrency) then { + player setVariable [["cashMoney", "globalMoney"] select Z_persistentMoney, _wealth - _amount, true]; + _message = format [ + localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_SUCCESS" + ,_count, [_amount] call BIS_fnc_numberText,_itemText + ] + } else { + _message = format [ + localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_SUCCESS" + ,_count, _itemText, "" + ] + }; - call player_forceSave; - _message1 call dayz_rollingMessages; - systemChat _message1; - } else { - systemChat localize "STR_EPOCH_TRADE_DEBUG"; - }; - } else { - if (Z_SingleCurrency) then { - _message1 = format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_FAILED",_count,[_amount] call BIS_fnc_numberText,_itemText]; - } else { - _message1 = format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_FAILED",_count,_itemText,""]; - }; + call player_forceSave; + _message call dayz_rollingMessages + } else { + systemChat localize "STR_EPOCH_TRADE_DEBUG"; + }; - disableSerialization; + }; - _plotDialog = findDisplay 711194; - _line1 = _plotDialog displayCtrl 7012; - _line2 = _plotDialog displayCtrl 7013; - _message2 = " "; - _line1 ctrlSetText _message1; - _line2 ctrlSetText _message2; - }; + if (Z_SingleCurrency) then { + _message = format [ + localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_FAILED" + ,_count, [_amount] call BIS_fnc_numberText, _itemText + ] + } else { + _message = format [ + localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_FAILED" + ,_count, _itemText, "" + ] + }; + + disableSerialization; + local _plotDialog = findDisplay 711194; + + (_plotDialog displayCtrl 7012) ctrlSetText _message; + (_plotDialog displayCtrl 7013) ctrlSetText ""; }; + +// We don't need to count objects damaged >= _DZE_DamageBeforeMaint nor filter them out. +if (_this == "force") exitWith { + local _allObjects = []; + + { + _allObjects set [count _allObjects, netId _x] + } count _objects; + + _allObjects call _maintain; + dayz_actionInProgress = false +}; + + +// For 'maintain' and 'preview', number of objects damaged >= _DZE_DamageBeforeMaint has to be known. +local _objects_filtered = []; +local _DZE_DamageBeforeMaint = DZE_DamageBeforeMaint; + { - if (damage _x >= DZE_DamageBeforeMaint) then { - _objects_filtered set [count _objects_filtered,netID _x]; - _count = _count + 1; - }; + if (damage _x >= _DZE_DamageBeforeMaint) then { + _objects_filtered set [count _objects_filtered, netId _x] + } } count _objects; -_option = _this; +local _countFiltered = count _objects_filtered; -call { - if (_option == "maintain") exitwith { - if (_count != 0) then { - [_objects_filtered] call _maintain; - } else { - systemChat localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_NONE"; - }; - }; - if (_option == "force") exitwith { - _count = 0; - _objects_filtered = []; - { - _objects_filtered set [count _objects_filtered,netID _x]; - _count = _count + 1; - } count _objects; - [_objects_filtered] call _maintain; - }; - if (_option == "preview") exitwith { - disableSerialization; +if (_this == "preview") exitWith { + disableSerialization; + local _plotDialog = findDisplay 711194; - _plotDialog = findDisplay 711194; - _line1 = _plotDialog displayCtrl 7012; - _line2 = _plotDialog displayCtrl 7013; + local _requirements = []; - if (_count == 0) then { - _message1 = localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_NONE"; - _line1 ctrlSetText _message1; - } else { - _requirements = _count call _req; + if (_countFiltered == 0) then { + (_plotDialog displayCtrl 7012) ctrlSetText (localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_NONE") + } else { + local _message1 = ""; + _requirements = _countFiltered call _req; - if (Z_SingleCurrency) then { - _message1 = format [localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_PRICE", _count,[_requirements select 0] call BIS_fnc_numberText,_requirements select 1]; - } else { - _message1 = format [localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_PRICE", _count,_requirements select 1,""]; - }; - _line1 ctrlSetText _message1; - }; - _requirements = count _objects call _req; - if (Z_SingleCurrency) then { - _message2 = format [localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_FORCE",count _objects,[_requirements select 0] call BIS_fnc_numberText,_requirements select 1]; - } else { - _message2 = format [localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_FORCE",count _objects,_requirements select 1,""]; - }; - if (_count != count _objects) then { - _line2 ctrlSetText _message2; - }; - }; + if (Z_SingleCurrency) then { + _message1 = format [ + localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_PRICE" + ,_countFiltered, [_requirements select 0] call BIS_fnc_numberText, _requirements select 1 + ] + } else { + _message1 = format [ + localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_PRICE" + ,_countFiltered, _requirements select 1, "" + ] + }; + + (_plotDialog displayCtrl 7012) ctrlSetText _message1 + }; + + if (_countFiltered != count _objects) then { + local _message2 = ""; + _requirements = count _objects call _req; + + if (Z_SingleCurrency) then { + _message2 = format [ + localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_FORCE" + ,count _objects, [_requirements select 0] call BIS_fnc_numberText, _requirements select 1 + ] + } else { + _message2 = format [ + localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_FORCE" + ,count _objects, _requirements select 1, "" + ] + }; + + (_plotDialog displayCtrl 7013) ctrlSetText _message2 + }; + + dayz_actionInProgress = false }; -dayz_actionInProgress = false; + +if (_this == "maintain") exitWith { + if (_countFiltered != 0) then { + _objects_filtered call _maintain + } else { + systemChat localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_NONE" + }; + + dayz_actionInProgress = false +}; + + +// Wrong option. +diag_log format ["DEBUG: Wrong maintanance option keyword. Expected: ('maintain', 'force', 'preview'). Received: '%1'.", _this] diff --git a/SQF/dayz_server/compile/server_maintainArea.sqf b/SQF/dayz_server/compile/server_maintainArea.sqf index 5c2a813f4..63a33805e 100644 --- a/SQF/dayz_server/compile/server_maintainArea.sqf +++ b/SQF/dayz_server/compile/server_maintainArea.sqf @@ -1,49 +1,51 @@ -/* Maintain Area - written by Skaronator */ -/* +/* Maintain Area - written by Skaronator + Updated by iben + 1: PVDZE_maintainArea = [netID player,1,[netID Object,netID Object,netID Object,...etc]]; 2: PVDZE_maintainArea = [netID player,2,[netID Object]]; */ -private ["_player","_option","_obj","_name","_objectsInfo","_UID","_ID","_key"]; +if ((_this select 1) == 1) exitWith { + { + local _obj = objectFromNetId _x; + local _ID = _obj getVariable ["ObjectID", "0"]; -_player = objectfromNetID(_this select 0); -_option = _this select 1; -_objectsInfo = _this select 2; + if (_ID == "0") then { + local _UID = _obj getVariable ["ObjectUID", "0"]; -if (_option == 1) then { - { - _obj = objectfromNetID _x; - _ID = _obj getVariable ["ObjectID","0"]; - _UID = _obj getVariable ["ObjectUID","0"]; - - if (_ID == "0") then { - if (_UID != "0") then { - _obj setDamage 0; - _key = format["CHILD:397:%1:", _UID]; - _key call server_hiveWrite; - }; - } else { - _obj setDamage 0; - _key = format["CHILD:396:%1:", _ID]; - _key call server_hiveWrite; - }; - } count _objectsInfo; - _name = if (alive _player) then { name _player; } else { "Dead Player"; }; - diag_log format ["MAINTAIN AREA BY %1 - %2 Objects at %3, Grid: %4", _name, (count _objectsInfo), (getPosATL _player), mapGridPosition(getPosATL _player)]; -} else { - _obj = objectfromNetID(_objectsInfo select 0); - _ID = _obj getVariable ["ObjectID","0"]; - _UID = _obj getVariable ["ObjectUID","0"]; - - if (_ID == "0") then { - if (_UID != "0") then { - _obj setDamage 0; - _key = format["CHILD:397:%1:", _UID]; - _key call server_hiveWrite; - }; - } else { - _obj setDamage 0; - _key = format["CHILD:396:%1:", _ID]; - _key call server_hiveWrite; - }; -}; \ No newline at end of file + if (_UID != "0") then { + _obj setDamage 0; + (format ["CHILD:397:%1:", _UID]) call server_hiveWrite + } + } else { + _obj setDamage 0; + (format ["CHILD:396:%1:", _ID]) call server_hiveWrite + } + } count (_this select 2); + + local _player = objectFromNetId (_this select 0); + local _position = getPosATL _player; + + diag_log format [ + "MAINTAIN AREA BY %1 - %2 Objects at %3, Grid: %4." + ,if (alive _player) then {name _player} else {"Dead Player"} + ,count (_this select 2), _position, mapGridPosition _position + ] +}; + + +local _obj = objectFromNetId ((_this select 2) select 0); +local _ID = _obj getVariable ["ObjectID", "0"]; + +if (_ID == "0") exitWith { + local _UID = _obj getVariable ["ObjectUID", "0"]; + + if (_UID != "0") then { + _obj setDamage 0; + (format ["CHILD:397:%1:", _UID]) call server_hiveWrite + } +}; + + +_obj setDamage 0; +(format ["CHILD:396:%1:", _ID]) call server_hiveWrite