Consolidate maintain scripts

Thanks to @oiad for making this easy #1735
This commit is contained in:
ebaydayz
2016-08-15 16:33:00 -04:00
parent c738710b77
commit 15763f4f2a
8 changed files with 86 additions and 215 deletions

View File

@@ -42,7 +42,7 @@ class PlotManagement
x = 0.41 * safezoneW + safezoneX;
y = 0.22 * safezoneH + safezoneY;
w = 0.08 * safezoneW;
onButtonClick = "[""preview""] call MaintainPlot;";
onButtonClick = "'preview' call MaintainPlot;";
};
class RscShortcutButton_7011: ZSC_RscButtonMenuBlue
@@ -52,7 +52,7 @@ class PlotManagement
x = 0.51 * safezoneW + safezoneX;
y = 0.22 * safezoneH + safezoneY;
w = 0.08 * safezoneW;
onButtonClick = "[""maintain""] call MaintainPlot;";
onButtonClick = "'maintain' call MaintainPlot;";
};
class RscText_7012: ZSC_RscTextT
{

View File

@@ -1,89 +0,0 @@
//Code developed by Axe Cop - Massive improvments and performance tunes by Skaronator
private ["_objectID","_objectUID","_target","_objectClasses","_range","_objects","_requirements","_count","_option","_objects_filtered","_ctrl","_itemText"];
if (DZE_ActionInProgress) exitWith {localize "STR_EPOCH_ACTIONS_2" call dayz_rollingMessages;};
DZE_ActionInProgress = true;
player removeAction s_player_maintain_area;
s_player_maintain_area = 1;
player removeAction s_player_maintain_area_preview;
s_player_maintain_area_preview = 1;
_target = nearestObject [[player] call FNC_getPos,"Plastic_Pole_EP1_DZ"];
_objectClasses = DZE_maintainClasses;
_range = DZE_maintainRange; // set the max range for the maintain area
_objects = nearestObjects [_target, _objectClasses, _range];
//filter to only those that have 10% damage
_objects_filtered = [];
_count = 0;
{
if (damage _x >= DZE_DamageBeforeMaint) then {
_objectUID = _x getVariable ["ObjectUID","0"];
_objectID = _x getVariable ["ObjectID","0"];
_objects_filtered set [count _objects_filtered, [_x, _objectID, _objectUID]];
_count = _count + 1;
};
} count _objects;
_objects = _objects_filtered;
// TODO dynamic requirements based on used building parts?
if (_count == 0) exitWith {
format[localize "STR_EPOCH_ACTIONS_22",_count] call dayz_rollingMessages;
DZE_ActionInProgress = false;
s_player_maintain_area = -1;
s_player_maintain_area_preview = -1;
};
_requirements = [];
_option = _this select 0;
switch true do {
case (_count <= 10): {_requirements = [["ItemGoldBar10oz",1]]};
case (_count <= 20): {_requirements = [["ItemGoldBar10oz",2]]};
case (_count <= 35): {_requirements = [["ItemGoldBar10oz",3]]};
case (_count <= 50): {_requirements = [["ItemGoldBar10oz",4]]};
case (_count <= 75): {_requirements = [["ItemGoldBar10oz",6]]};
case (_count <= 100): {_requirements = [["ItemBriefcase100oz",1]]};
case (_count <= 175): {_requirements = [["ItemBriefcase100oz",2]]};
case (_count <= 250): {_requirements = [["ItemBriefcase100oz",3]]};
case (_count <= 325): {_requirements = [["ItemBriefcase100oz",4]]};
case (_count <= 400): {_requirements = [["ItemBriefcase100oz",5]]};
case (_count <= 475): {_requirements = [["ItemBriefcase100oz",6]]};
case (_count <= 550): {_requirements = [["ItemBriefcase100oz",7]]};
case (_count <= 625): {_requirements = [["ItemBriefcase100oz",8]]};
case (_count > 625): {_requirements = [["ItemBriefcase100oz",9]]};
};
_itemText = getText(configFile >> "CfgMagazines" >> (_requirements select 0) select 0 >> "displayName");
if ("ItemBriefcase100oz" == (_requirements select 0) select 0 && (_requirements select 0) select 1 > 1) then {
_itemText = _itemText + "s";
};
switch _option do {
case "maintain": {
if ([[[(_requirements select 0) select 0, (_requirements select 0) select 1]],0] call epoch_returnChange) then {
player playActionNow "Medic";
[player,_range,true,(getPosATL player)] spawn player_alertZombies;
PVDZE_maintainArea = [player,1,_objects];
publicVariableServer "PVDZE_maintainArea";
systemChat format[localize "STR_EPOCH_ACTIONS_4", _count];
format[localize "STR_EPOCH_PLOTMANAGEMENT_PRICE_MAINTAINED_SUCCESS", (_requirements select 0) select 1, _itemText] call dayz_rollingMessages;
format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_SUCCESS", _count] call dayz_rollingMessages;
} else {
format[localize "STR_EPOCH_PLOTMANAGEMENT_MONEY_NEEDED_FAILED", (_requirements select 0) select 1, _itemText] call dayz_rollingMessages;
format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_FAILED", _count] call dayz_rollingMessages;
};
};
case "preview": {
format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_PRICE", (_requirements select 0) select 1, _itemText] call dayz_rollingMessages;
format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_OBJECTS", _count] call dayz_rollingMessages;
};
};
DZE_ActionInProgress = false;
s_player_maintain_area = -1;
s_player_maintain_area_preview = -1;

View File

@@ -1,5 +1,5 @@
createdialog "PlotManagement";
call PlotNearbyHumans;
call PlotGetFriends;
["preview"] call MaintainPlot;
"preview" call MaintainPlot;
call PlotObjects;

View File

@@ -1,4 +1,4 @@
private ["_objectID","_objectUID","_target","_objectClasses","_range","_objects","_requirements","_count","_option","_objects_filtered","_ctrl","_itemText"];
private ["_objectID","_objectUID","_target","_objectClasses","_range","_objects","_requirements","_count","_objects_filtered","_ctrl","_itemText","_type","_amount","_success","_theCost","_wealth","_message1","_message2"];
disableSerialization;
if (DZE_ActionInProgress) exitWith {localize "STR_EPOCH_ACTIONS_2" call dayz_rollingMessages;};
@@ -29,66 +29,107 @@ _objects = _objects_filtered;
// TODO dynamic requirements based on used building parts?
if (_count == 0) exitWith {
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7012);
if (DZE_permanentPlot) then {
_ctrl = (uiNamespace getVariable "PlotManagement") displayCtrl 7012;
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_OBJECTS", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7013);
_ctrl = (uiNamespace getVariable "PlotManagement") displayCtrl 7013;
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_NO_MONEY_NEEDED", " "];
} else {
format[localize "STR_EPOCH_ACTIONS_22",_count] call dayz_rollingMessages;
};
DZE_ActionInProgress = false;
s_player_maintain_area = -1;
s_player_maintain_area_preview = -1;
};
_requirements = [];
_option = _this select 0;
_theCost = _count * 100;
switch true do {
case (_count <= 10): {_requirements = [["ItemGoldBar10oz",1]]};
case (_count <= 20): {_requirements = [["ItemGoldBar10oz",2]]};
case (_count <= 35): {_requirements = [["ItemGoldBar10oz",3]]};
case (_count <= 50): {_requirements = [["ItemGoldBar10oz",4]]};
case (_count <= 75): {_requirements = [["ItemGoldBar10oz",6]]};
case (_count <= 100): {_requirements = [["ItemBriefcase100oz",1]]};
case (_count <= 175): {_requirements = [["ItemBriefcase100oz",2]]};
case (_count <= 250): {_requirements = [["ItemBriefcase100oz",3]]};
case (_count <= 325): {_requirements = [["ItemBriefcase100oz",4]]};
case (_count <= 400): {_requirements = [["ItemBriefcase100oz",5]]};
case (_count <= 475): {_requirements = [["ItemBriefcase100oz",6]]};
case (_count <= 550): {_requirements = [["ItemBriefcase100oz",7]]};
case (_count <= 625): {_requirements = [["ItemBriefcase100oz",8]]};
case (_count > 625): {_requirements = [["ItemBriefcase100oz",9]]};
_requirements = switch true do {
case (_count <= 10): {[["ItemGoldBar10oz",1]]};
case (_count <= 20): {[["ItemGoldBar10oz",2]]};
case (_count <= 35): {[["ItemGoldBar10oz",3]]};
case (_count <= 50): {[["ItemGoldBar10oz",4]]};
case (_count <= 75): {[["ItemGoldBar10oz",6]]};
case (_count <= 100): {[["ItemBriefcase100oz",1]]};
case (_count <= 175): {[["ItemBriefcase100oz",2]]};
case (_count <= 250): {[["ItemBriefcase100oz",3]]};
case (_count <= 325): {[["ItemBriefcase100oz",4]]};
case (_count <= 400): {[["ItemBriefcase100oz",5]]};
case (_count <= 475): {[["ItemBriefcase100oz",6]]};
case (_count <= 550): {[["ItemBriefcase100oz",7]]};
case (_count <= 625): {[["ItemBriefcase100oz",8]]};
case (_count > 625): {[["ItemBriefcase100oz",9]]};
};
_itemText = getText(configFile >> "CfgMagazines" >> (_requirements select 0) select 0 >> "displayName");
if ("ItemBriefcase100oz" == (_requirements select 0) select 0 && (_requirements select 0) select 1 > 1) then {
_type = (_requirements select 0) select 0;
_amount = (_requirements select 0) select 1;
if (Z_SingleCurrency) then {
_amount = _theCost;
_itemText = CurrencyName;
_wealth = player getVariable[Z_MoneyVariable,0];
} else {
_itemText = getText(configFile >> "CfgMagazines" >> _type >> "displayName");
if ("ItemBriefcase100oz" == _type && _amount > 1) then {
_itemText = _itemText + "s";
};
};
switch _option do {
switch _this do {
case "maintain": {
if ([[[(_requirements select 0) select 0, (_requirements select 0) select 1]],0] call epoch_returnChange) then {
_success = if (Z_SingleCurrency) then {_theCost <= _wealth} else {[[[_type, _amount]],0] call epoch_returnChange};
if (_success) then {
player playActionNow "Medic";
[player,_range,true,(getPosATL player)] spawn player_alertZombies;
if (Z_SingleCurrency) then {
player setVariable[Z_MoneyVariable,(_wealth - _theCost),true];
call player_forceSave;
};
PVDZE_maintainArea = [player,1,_objects];
publicVariableServer "PVDZE_maintainArea";
systemChat format[localize "STR_EPOCH_ACTIONS_4", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7012);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_SUCCESS", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7013);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_PRICE_MAINTAINED_SUCCESS", (_requirements select 0) select 1, _itemText];
_message1 = format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_SUCCESS", _count];
_message2 = format[localize "STR_EPOCH_PLOTMANAGEMENT_PRICE_MAINTAINED_SUCCESS", _amount, _itemText];
if (DZE_permanentPlot) then {
_ctrl = (uiNamespace getVariable "PlotManagement") displayCtrl 7012;
_ctrl ctrlSetText _message1;
_ctrl = (uiNamespace getVariable "PlotManagement") displayCtrl 7013;
_ctrl ctrlSetText _message2;
} else {
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7012);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_FAILED", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7013);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_MONEY_NEEDED_FAILED", (_requirements select 0) select 1, _itemText];
_message2 call dayz_rollingMessages;
_message1 call dayz_rollingMessages;
};
} else {
_message1 = format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_FAILED", _count];
_message2 = format[localize "STR_EPOCH_PLOTMANAGEMENT_MONEY_NEEDED_FAILED", _amount, _itemText];
if (DZE_permanentPlot) then {
_ctrl = (uiNamespace getVariable "PlotManagement") displayCtrl 7012;
_ctrl ctrlSetText _message1;
_ctrl = (uiNamespace getVariable "PlotManagement") displayCtrl 7013;
_ctrl ctrlSetText _message2;
} else {
_message2 call dayz_rollingMessages;
_message1 call dayz_rollingMessages;
};
};
};
case "preview": {
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7012);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_OBJECTS", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7013);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_PRICE", (_requirements select 0) select 1, _itemText];
_message1 = format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_OBJECTS", _count];
_message2 = format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_PRICE", _amount, _itemText];
if (DZE_permanentPlot) then {
_ctrl = (uiNamespace getVariable "PlotManagement") displayCtrl 7012;
_ctrl ctrlSetText _message1;
_ctrl = (uiNamespace getVariable "PlotManagement") displayCtrl 7013;
_ctrl ctrlSetText _message2;
} else {
_message2 call dayz_rollingMessages;
_message1 call dayz_rollingMessages;
};
};
};

View File

@@ -1,81 +0,0 @@
private ["_newWealth","_target","_objectClasses","_range","_objects","_count","_option","_objects_filtered","_ctrl","_theCost","_wealth"];
disableSerialization;
if (DZE_ActionInProgress) exitWith {localize "STR_EPOCH_ACTIONS_2" call dayz_rollingMessages;};
DZE_ActionInProgress = true;
player removeAction s_player_maintain_area;
s_player_maintain_area = 1;
player removeAction s_player_maintain_area_preview;
s_player_maintain_area_preview = 1;
_target = nearestObject [[player] call FNC_getPos,"Plastic_Pole_EP1_DZ"];
_objectClasses = DZE_maintainClasses;
_range = DZE_maintainRange; // set the max range for the maintain area
_objects = nearestObjects [_target, _objectClasses, _range];
_objects_filtered = [];
_count = 0;
{
if (damage _x >= DZE_DamageBeforeMaint) then {
_objectUID = _x getVariable ["ObjectUID","0"];
_objectID = _x getVariable ["ObjectID","0"];
_objects_filtered set [count _objects_filtered, [_x, _objectID, _objectUID]];
_count = _count + 1;
};
} count _objects;
_objects = _objects_filtered;
// TODO dynamic requirements based on used building parts?
if (_count == 0) exitWith {
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7012);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_OBJECTS", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7013);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_NO_MONEY_NEEDED", " "];
DZE_ActionInProgress = false;
s_player_maintain_area = -1;
s_player_maintain_area_preview = -1;
};
_theCost = _count * 100;
_option = _this select 0;
switch _option do {
case "maintain": {
_wealth = player getVariable[Z_MoneyVariable,0];
systemChat format ["_wealth: %1 _theCost: %2",_wealth,_theCost];
if (_theCost <= _wealth) then {
_newWealth = (_wealth - _theCost);
player playActionNow "Medic";
[player,_range,true,(getPosATL player)] spawn player_alertZombies;
player setVariable[Z_MoneyVariable,_newWealth,true];
call player_forceSave;
PVDZE_maintainArea = [player,1,_objects];
publicVariableServer "PVDZE_maintainArea";
systemChat format[localize "STR_EPOCH_ACTIONS_4", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7012);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_SUCCESS", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7013);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_PRICE_MAINTAINED_SUCCESS",_theCost, CurrencyName];
} else {
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7012);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_OBJECTS_MAINTAINED_FAILED", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7013);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_MONEY_NEEDED_FAILED", _theCost, CurrencyName];
};
};
case "preview": {
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7012);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_OBJECTS", _count];
_ctrl = ((uiNamespace getVariable "PlotManagement") displayCtrl 7013);
_ctrl ctrlSetText format[localize "STR_EPOCH_PLOTMANAGEMENT_MAINTAIN_PRICE", _theCost, CurrencyName];
};
};
DZE_ActionInProgress = false;
s_player_maintain_area = -1;
s_player_maintain_area_preview = -1;

View File

@@ -55,7 +55,7 @@ if(_IsNearPlot == 0) then {
};
if(!_canBuild) exitWith { DZE_ActionInProgress = false; format[localize "STR_EPOCH_PLAYER_135",_needText,_distance] call dayz_rollingMessages; [_canBuild, _isPole];};
// Also count safes, lockboxes, vanilla buildables, tents and stashes against DZE_BuildingLimit
_buildables = DZE_maintainClasses + DZE_LockableStorage + ["DZ_buildables","DZ_storage_base"];
_center = if (isNull _nearestPole) then {_pos} else {_nearestPole};
if ((count (nearestObjects [_center,_buildables,_distance])) >= DZE_BuildingLimit) exitWith {DZE_ActionInProgress = false; format[localize "str_epoch_player_41",_distance] call dayz_rollingMessages; [false, _isPole];};

View File

@@ -646,8 +646,8 @@ if (!isNull _cursorTarget && !_inVehicle && !_isPZombie && (player distance _cur
};
} else {
if (s_player_maintain_area < 0) then {
s_player_maintain_area = player addAction [format["<t color='#ff0000'>%1</t>",localize "STR_EPOCH_ACTIONS_MAINTAREA"], "\z\addons\dayz_code\actions\maintain_area.sqf", ["maintain",_cursorTarget], 5, false];
s_player_maintain_area_preview = player addAction [format["<t color='#ff0000'>%1</t>",localize "STR_EPOCH_ACTIONS_MAINTPREV"], "\z\addons\dayz_code\actions\maintain_area.sqf", ["preview",_cursorTarget], 5, false];
s_player_maintain_area = player addAction [format["<t color='#ff0000'>%1</t>",localize "STR_EPOCH_ACTIONS_MAINTAREA"], "'maintain' call MaintainPlot", [], 5, false];
s_player_maintain_area_preview = player addAction [format["<t color='#ff0000'>%1</t>",localize "STR_EPOCH_ACTIONS_MAINTPREV"], "'preview' call MaintainPlot", [], 5, false];
};
};
_PlotsmarkersNear = count (_cursorTarget nearEntities ["Land_coneLight", DZE_PlotPole select 0]);

View File

@@ -195,7 +195,7 @@ if (!isDedicated) then {
PlotRemoveFriend = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\plotManagement\plotRemoveFriend.sqf";
PlotObjects = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\plotManagement\plotObjects.sqf";
PlotPreview = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\plotManagement\plotToggleMarkers.sqf";
MaintainPlot = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\plotManagement\maintain_area.sqf"; // use maintain_areaSC.sqf for single currency
MaintainPlot = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\plotManagement\maintain_area.sqf";
DoorGetFriends = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\doorManagement\doorGetFriends.sqf";
DoorNearbyHumans = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\doorManagement\doorNearbyHumans.sqf";
DoorAddFriend = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\doorManagement\doorAddFriend.sqf";