Add Big Egg's Restrict Building function

Thx @BigEgg17 and @Victor-the-Cleaner
This commit is contained in:
A Man
2021-12-23 17:03:07 +01:00
parent adc17d4ec6
commit db4a417f30

View File

@@ -3,7 +3,7 @@
// Updated by: Victor the Cleaner
// Date: August 2021
//
// Performs 10 different build checks
// Performs 12 different build checks
//
// 1) You are not allowed to build here a "Trader" is nearby.
// 2) You cannot build a plot pole within "_distance" of an existing plot.
@@ -11,10 +11,13 @@
// 4) This item needs a "Plot Pole" within "_distance" meters
// 5) You do not have access to build on this plot.
// 6) Building is restricted above "DZE_BuildHeightLimit" meter(s).
// 7) You cannot build. There are too many objects within "DZE_maintainRange" m.
// 8) You can't build a "displayName" within "_distance" meters of a safe zone.
// 9) You can't build a "displayName" within "DZE_NoBuildNearDistance" meters of a "class".
// 10) Tool Check (silent)
// 7) You are not allowed to build over sea water.
// 8) You cannot build within %1m of a restricted zone.
// 9) You cannot build within %1m of a blacklisted building.
// 10) You cannot build. There are too many objects within "DZE_maintainRange" m.
// 11) You can't build a "displayName" within "_distance" meters of a safe zone.
// 12) You can't build a "displayName" within "DZE_NoBuildNearDistance" meters of a "class".
// 13) Tool Check (silent)
//
// Input values = [position, classname, toolcheck];
// Return values = [_canBuild, _isPole, _nearestPole]; // added _nearestPole
@@ -30,13 +33,13 @@ local _toolCheck = _this select 2;
local _classname = getText (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "create");
local _isPole = (_classname == "Plastic_Pole_EP1_DZ");
local _isLandFireDZ = (_classname == "Land_Fire_DZ");
local _isAdmin = dayz_playerUID in DZE_PlotManagementAdmins;
local _canBuild = false;
local _plotPoles = 0;
local _radius = DZE_PlotPole select 0;
local _minDistance = DZE_PlotPole select 1;
local _requireplot = DZE_requireplot;
local _message = ""; // for blacklisted zones and buildings
if (isNumber (configFile >> "CfgVehicles" >> _classname >> "requireplot")) then {
_requireplot = getNumber(configFile >> "CfgVehicles" >> _classname >> "requireplot");
@@ -46,6 +49,12 @@ local _distance = _plotcheck select 0;
local _isNearPlot = _plotcheck select 1;
local _nearestPole = _plotcheck select 2; // object or objNull
local _isOnWater = surfaceIsWater _pos;
local _heightASL = _pos select 2;
if (!_isOnWater) then {
_heightASL = (ATLToASL _pos) select 2;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -56,6 +65,7 @@ if (!canbuild) exitWith {
dayz_actionInProgress = false;
format[localize "STR_EPOCH_PLAYER_136", localize "STR_EPOCH_TRADER"] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
@@ -69,6 +79,7 @@ if (_isPole && _isNearPlot > 0) exitWith {
dayz_actionInProgress = false;
format[localize "str_epoch_player_44", _distance] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
@@ -85,10 +96,11 @@ if (_isPole && !_isAdmin && DZE_limitPlots > 0) then {
};
} count (entities "Plastic_Pole_EP1_DZ"); // all plot poles on the map owned by player
};
if ((DZE_limitPlots > 0) && (_plotPoles >= DZE_LimitPlots)) exitWith {
if ((DZE_limitPlots > 0) && (_plotPoles >= DZE_LimitPlots)) exitWith {
dayz_actionInProgress = false;
format[localize "STR_EPOCH_PLAYER_133", DZE_limitPlots] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
@@ -99,14 +111,15 @@ if ((DZE_limitPlots > 0) && (_plotPoles >= DZE_LimitPlots)) exitWith {
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (_isNearPlot == 0) then {
if (_requireplot == 0 || _isLandFireDZ) then {
if (_requireplot == 0) then {
_canBuild = true;
};
};
if (_isNearPlot == 0 && !_canBuild) exitWith {
if (_isNearPlot == 0 && !_canBuild) exitWith {
dayz_actionInProgress = false;
format[localize "STR_EPOCH_PLAYER_135", localize "str_epoch_player_246", _distance] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
@@ -129,10 +142,11 @@ if (_isNearPlot > 0) then {
};
};
};
if (_isNearPlot > 0 && !_canBuild) exitWith {
if (_isNearPlot > 0 && !_canBuild) exitWith {
dayz_actionInProgress = false;
localize "STR_EPOCH_PLAYER_134" call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
@@ -146,37 +160,99 @@ if (DZE_BuildHeightLimit > 0 && ((_pos select 2) > DZE_BuildHeightLimit)) exitWi
dayz_actionInProgress = false;
format[localize "STR_EPOCH_PLAYER_168", DZE_BuildHeightLimit] call dayz_rollingMessages;
[false, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 7) You cannot build. There are too many objects within "DZE_maintainRange" m.
// 7) You are not allowed to build over sea water.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (!DZE_buildOnWater && (_isOnWater || {_heightASL < DZE_maxSeaLevel})) exitWith {
dayz_actionInProgress = false;
localize "STR_EPOCH_BUILD_FAIL_WATER" call dayz_rollingMessages;
[false, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 8) You cannot build within %1m of a restricted zone.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
{
local _dis = (_x select 2); // minimum distance
local _chk = player distance (_x select 1); // current distance
if (_chk <= _dis) exitWith { // player is within blacklisted zone
_message = format[localize "STR_EPOCH_PLAYER_RES_ZONE", _dis, (_x select 0), floor _chk];
};
} count DZE_RestrictedBuildingZones;
if (_message != "") exitWith {
dayz_actionInProgress = false;
_message call dayz_rollingMessages;
[false, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 9) You cannot build within %1m of a blacklisted building.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
{
local _dis = (_x select 2); // minimum distance
local _chk = count (nearestObjects [player, [(_x select 1)], _dis]); // blacklisted buildings
if (_chk > 0) exitWith { // player is too close
_message = format[localize "STR_EPOCH_PLAYER_RES_BUILDING", _dis, (_x select 0)];
};
} count DZE_BlacklistedBuildings;
if (_message != "") exitWith {
dayz_actionInProgress = false;
_message call dayz_rollingMessages;
[false, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 10) You cannot build. There are too many objects within "DZE_maintainRange" m.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// Also count safes, lockboxes, vanilla buildables, tents and stashes against DZE_BuildingLimit
local _buildables = DZE_maintainClasses + DZE_LockableStorage + ["DZ_storage_base"];
local _center = if (isNull _nearestPole) then {
_pos; // player's position
} else {
_nearestPole;
};
if ((count (nearestObjects [_center, _buildables, DZE_maintainRange])) >= DZE_BuildingLimit) exitWith {
if ((count (nearestObjects [_center, _buildables, DZE_maintainRange])) >= DZE_BuildingLimit) exitWith {
dayz_actionInProgress = false;
format[localize "str_epoch_player_41", floor DZE_maintainRange] call dayz_rollingMessages;
[false, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 8) You can't build a "displayName" within "_distance" meters of a safe zone.
// 11) You can't build a "displayName" within "_distance" meters of a safe zone.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
local _text = getText (configFile >> "CfgMagazines" >> _item >> "displayName");
local _checkOK = false;
_distance = DZE_SafeZoneNoBuildDistance;
{
if (typeName _x == "ARRAY") then {
@@ -195,17 +271,18 @@ _distance = DZE_SafeZoneNoBuildDistance;
if (_checkOK && !_isAdmin) then {
_canBuild = !([player, _distance] call DZE_SafeZonePosCheck);
};
if (!_canBuild) exitWith {
if (!_canBuild) exitWith {
dayz_actionInProgress = false;
format [localize "STR_EPOCH_PLAYER_166", _text, _distance] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 9) You can't build a "displayName" within "DZE_NoBuildNearDistance" meters of a "class".
// 12) You can't build a "displayName" within "DZE_NoBuildNearDistance" meters of a "class".
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (count DZE_NoBuildNear > 0 && !_isAdmin) then {
@@ -215,17 +292,18 @@ if (count DZE_NoBuildNear > 0 && !_isAdmin) then {
_canBuild = false;
};
};
if (!_canBuild) exitWith {
if (!_canBuild) exitWith {
dayz_actionInProgress = false;
format [localize "STR_EPOCH_PLAYER_167", _text, DZE_NoBuildNearDistance, typeOf (_near select 0)] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 10) Tool Check (silent)
// 13) Tool Check (silent)
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (_toolCheck) then {
@@ -233,6 +311,6 @@ if (_toolCheck) then {
_classname = getText (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "create");
_canBuild = [_item, _require, _classname] call dze_requiredItemsCheck;
};
// When calling this function in another script use a silent exitWith, unless you have something special to say. i.e. if !(_canBuild select 0) exitWith {};
// When calling this function in another script use a silent exitWith, unless you have something special to say. i.e. if !(_canBuild select 0) exitWith{};
[_canBuild, _isPole, _nearestPole];