Modulr build changes

- Players may no longer build objects outside the plot radius.
- This is calculated using the object's pivot point, not its geometry nor its bounding box.
- Players may move an object any distance or height within the plot boundary/sphere.
- Therefore, DZE_buildMaxMoveDistance and DZE_buildMaxHeightDistance are now obsolete.
- Players may move a small distance outside the plot radius, provided the object remains inside.	Enabled with DZE_PlotOzone.	Default: 10 meters.
- A line of helpers now appears through the plot's vertical axis to aid line-of-sight to the pole.	Enabled with DZE_AxialHelper.
- This may be useful for nearby plots that are grouped together, or where their radii overlap.
- Players may now cancel the build by fast movement, i.e. running, or fast walking on steep terrain.
- This only applies when the player is holding the object. They may press F to release it, then run without cancelling.
- Crouch-walking or slow-walking will not cancel the build.
- The player will auto-crouch when clicking "build" to prevent accidental cancelling.

Changes made by  @Victor-the-Cleaner
This commit is contained in:
A Man
2021-09-19 18:41:52 +02:00
parent 2a3b895647
commit bb968698e6
5 changed files with 1053 additions and 593 deletions

View File

@@ -1,132 +1,245 @@
//Checks if item is near a plot, if the player is plot owner or friendly, if there are too many items, and if the player has required tools
private ["_isAdmin","_requireplot","_distance","_canBuild","_friendlies","_nearestPole","_ownerID","_pos","_item","_classname","_isPole","_isLandFireDZ","_IsNearPlot","_buildables","_center","_toolCheck","_plotcheck","_buildcheck","_isfriendly","_isowner","_require","_text","_near","_plotPoles"];
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Updated by: Victor the Cleaner
// Date: August 2021
//
// Performs 10 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.
// 3) You can only own "DZE_limitPlots" plot pole(s)
// 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)
//
// Input values = [position, classname, toolcheck];
// Return values = [_canBuild, _isPole, _nearestPole]; // added _nearestPole
//
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Initialize
//
///////////////////////////////////////////////////////////////////////////////////////////////////
local _pos = _this select 0;
local _item = _this select 1;
local _toolCheck = _this select 2;
_pos = _this select 0;
_item = _this select 1;
_toolCheck = _this select 2;
_classname = getText (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "create");
_requireplot = DZE_requireplot;
_isAdmin = dayz_playerUID in DZE_PlotManagementAdmins;
// "Unable to build trader nearby."
if (!canbuild) exitWith {dayz_actionInProgress = false; format[localize "STR_EPOCH_PLAYER_136",localize "STR_EPOCH_TRADER"] call dayz_rollingMessages; [false, false];};
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;
if (isNumber (configFile >> "CfgVehicles" >> _classname >> "requireplot")) then {
_requireplot = getNumber(configFile >> "CfgVehicles" >> _classname >> "requireplot");
};
local _plotcheck = [player, _isPole] call FNC_find_plots;
local _distance = _plotcheck select 0;
local _isNearPlot = _plotcheck select 1;
local _nearestPole = _plotcheck select 2; // object or objNull
_checkClass = {
private ["_checkOK","_distance"];
_checkOK = false;
_distance = DZE_SafeZoneNoBuildDistance;
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 1) You are not allowed to build here a "Trader" is nearby.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (!canbuild) exitWith {
dayz_actionInProgress = false;
format[localize "STR_EPOCH_PLAYER_136", localize "STR_EPOCH_TRADER"] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 2) You cannot build a plot pole within "_distance" of an existing plot.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (_isPole && _isNearPlot > 0) exitWith {
dayz_actionInProgress = false;
format[localize "str_epoch_player_44", _distance] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 3) You can only own "DZE_limitPlots" plot pole(s)
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (_isPole && !_isAdmin && DZE_limitPlots > 0) then {
{
if (typeName _x == "ARRAY") then {
if (_x select 0 == _classname) then {_checkOK = true; _distance = _x select 1;};
} else {
if (_x == _className) then {_checkOK = true};
if (_x getVariable["ownerPUID","0"] == dayz_playerUID || (_x getVariable["CharacterID","0"] == dayz_characterID)) then {
_plotPoles = _plotPoles + 1;
};
if (_checkOK) exitWith {};
} count DZE_SafeZoneNoBuildItems;
} count (entities "Plastic_Pole_EP1_DZ"); // all plot poles on the map owned by player
};
if ((DZE_limitPlots > 0) && (_plotPoles >= DZE_LimitPlots)) exitWith {
[_checkOK,_distance]
dayz_actionInProgress = false;
format[localize "STR_EPOCH_PLAYER_133", DZE_limitPlots] call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
_isPole = (_classname == "Plastic_Pole_EP1_DZ");
_isLandFireDZ = (_classname == "Land_Fire_DZ");
_canBuild = false;
_plotPoles = 0;
_nearestPole = objNull;
_ownerID = 0;
_friendlies = [];
if (_isPole) then {
_plotcheck = [player, true] call FNC_find_plots;
_distance = DZE_PlotPole select 1;
if (DZE_limitPlots > 0 && !_isAdmin) then {
{
if (_x getVariable["ownerPUID","0"] == dayz_playerUID || (_x getVariable["CharacterID","0"] == dayz_characterID)) then {
_plotPoles = _plotPoles +1;
};
} count (entities "Plastic_Pole_EP1_DZ");
};
} else {
_plotcheck = [player, false] call FNC_find_plots;
_distance = DZE_PlotPole select 0;
};
_IsNearPlot = _plotcheck select 1;
_nearestPole = _plotcheck select 2;
if (_isPole && {_IsNearPlot > 0}) exitWith {dayz_actionInProgress = false; format[localize "str_epoch_player_44",_distance] call dayz_rollingMessages; [_canBuild, _isPole];};
if (DZE_limitPlots > 0 && {_plotPoles >= DZE_LimitPlots}) exitWith {dayz_actionInProgress = false; format[localize "STR_EPOCH_PLAYER_133",DZE_limitPlots] call dayz_rollingMessages; [_canBuild, _isPole];};
if (_IsNearPlot == 0) then {
if (_requireplot == 0 || {_isLandFireDZ}) then {
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 4) This item needs a "Plot Pole" within "_distance" meters
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (_isNearPlot == 0) then {
if (_requireplot == 0 || _isLandFireDZ) then {
_canBuild = true;
};
} else {
_ownerID = _nearestPole getVariable["CharacterID","0"];
};
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];
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 5) You do not have access to build on this plot.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (_isNearPlot > 0) then {
local _ownerID = _nearestPole getVariable["CharacterID","0"];
if (dayz_characterID == _ownerID) then {
_canBuild = true;
} else {
if (DZE_permanentPlot) then {
_buildcheck = [player, _nearestPole] call FNC_check_access;
_isowner = _buildcheck select 0;
_isfriendly = ((_buildcheck select 1) or (_buildcheck select 3));
local _accessCheck = [player, _nearestPole] call FNC_check_access;
local _isowner = _accessCheck select 0;
local _isfriendly = ((_accessCheck select 1) || (_accessCheck select 3));
if (_isowner || _isfriendly) then {
_canBuild = true;
};
} else {
_friendlies = player getVariable ["friendlyTo",[]];
local _friendlies = player getVariable ["friendlyTo",[]];
if (_ownerID in _friendlies) then {
_canBuild = true;
};
};
};
};
if (_isNearPlot > 0 && !_canBuild) exitWith {
if (!_canBuild) exitWith {
dayz_actionInProgress = false;
if (_isNearPlot == 0) then {
format[localize "STR_EPOCH_PLAYER_135",localize "str_epoch_player_246",_distance] call dayz_rollingMessages;
} else {
localize "STR_EPOCH_PLAYER_134" call dayz_rollingMessages;
};
[_canBuild, _isPole];
localize "STR_EPOCH_PLAYER_134" call dayz_rollingMessages;
[_canBuild, _isPole, _nearestPole];
};
if (DZE_BuildHeightLimit > 0 && {([player] call fnc_getPos) select 2 > DZE_BuildHeightLimit}) exitWith {dayz_actionInProgress = false; format[localize "STR_EPOCH_PLAYER_168",DZE_BuildHeightLimit] call dayz_rollingMessages; [false, _isPole];};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 6) Building is restricted above "DZE_BuildHeightLimit" meter(s).
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (DZE_BuildHeightLimit > 0 && ((_pos select 2) > DZE_BuildHeightLimit)) exitWith {
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.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// Also count safes, lockboxes, vanilla buildables, tents and stashes against DZE_BuildingLimit
_buildables = DZE_maintainClasses + DZE_LockableStorage + ["DZ_storage_base"];
_center = if (isNull _nearestPole) then {_pos} else {_nearestPole};
if ((count (nearestObjects [_center,_buildables,_distance])) >= DZE_BuildingLimit) exitWith {dayz_actionInProgress = false; format[localize "str_epoch_player_41",_distance] call dayz_rollingMessages; [false, _isPole];};
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 {
_text = getText (configFile >> 'CfgMagazines' >> _item >> 'displayName');
_buildCheck = call _checkClass;
if (_buildCheck select 0 && !_isAdmin) then {
_canBuild = !([player,_buildCheck select 1] call DZE_SafeZonePosCheck);
dayz_actionInProgress = false;
format[localize "str_epoch_player_41", floor DZE_maintainRange] call dayz_rollingMessages;
[false, _isPole, _nearestPole];
};
if !(_canBuild) exitWith {dayz_actionInProgress = false; format [localize "STR_EPOCH_PLAYER_166",_text,_buildCheck select 1] call dayz_rollingMessages; [false, _isPole];};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 8) 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 {
if (_x select 0 == _classname) then {
_checkOK = true;
_distance = _x select 1;
};
} else {
if (_x == _classname) then {
_checkOK = true;
};
};
if (_checkOK) exitWith {};
} count DZE_SafeZoneNoBuildItems;
if (_checkOK && !_isAdmin) then {
_canBuild = !([player, _distance] call DZE_SafeZonePosCheck);
};
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".
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (count DZE_NoBuildNear > 0 && !_isAdmin) then {
_near = (nearestObjects [_pos,DZE_NoBuildNear,DZE_NoBuildNearDistance]);
if ((count _near) > 0) then { _canBuild = false; };
local _near = (nearestObjects [_pos, DZE_NoBuildNear, DZE_NoBuildNearDistance]);
if ((count _near) > 0) then {
_canBuild = false;
};
};
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];
};
if !(_canBuild) exitWith {dayz_actionInProgress = false; format [localize "STR_EPOCH_PLAYER_167",_text,DZE_NoBuildNearDistance,typeOf (_near select 0)] call dayz_rollingMessages; [false, _isPole];};
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// 10) Tool Check (silent)
//
///////////////////////////////////////////////////////////////////////////////////////////////////
if (_toolCheck) then {
_require = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> "Build" >> "require");
local _require = getArray (configFile >> "cfgMagazines" >> _item >> "ItemActions" >> "Build" >> "require");
_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{};
[_canBuild, _isPole];
// 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];

View File

@@ -1,26 +1,28 @@
// Find Plots by RimBlock (http://epochmod.com/forum/index.php?/user/12612-rimblock/)
///////////////////////////////////////////////////////////////////////////////////////////////////
//
// Find Plots by RimBlock (http://epochmod.com/forum/index.php?/user/12612-rimblock/)
// Updated by: Victor the Cleaner
// Date: August 2021
//
///////////////////////////////////////////////////////////////////////////////////////////////////
private ["_player","_isPole","_IsNearPlot","_nearestPole","_distance","_findNearestPoles","_findNearestPole","_friendly","_return","_pos"];
local _player = _this select 0; // object
local _isPole = _this select 1; // bool
local _pos = [vehicle _player] call FNC_getPos;
local _radius = DZE_PlotPole select 0; // plot radius
local _minDistance = DZE_PlotPole select 1; // minimum distance between plot poles
local _nearestPole = objNull; // default
local _distance = _radius; // default
_player = _this select 0;
_isPole = _this select 1;
_IsNearPlot = 0;
_nearestPole = "";
_findNearestPole = [];
if(_isPole) then {
_distance = DZE_PlotPole select 1;
}else{
_distance = DZE_PlotPole select 0;
if (_isPole) then {
_distance = _minDistance;
};
_pos = [vehicle _player] call FNC_getPos;
// check for near plot
_findNearestPole = _pos nearEntities ["Plastic_Pole_EP1_DZ", _distance];
local _findNearestPole = _pos nearEntities ["Plastic_Pole_EP1_DZ", _distance];
_IsNearPlot = count (_findNearestPole);
if (_IsNearPlot > 0) then{_nearestPole = _findNearestPole select 0;}else{_nearestPole = objNull;};
local _isNearPlot = count _findNearestPole;
_return = [_distance, _IsNearPlot, _nearestPole];
_return
if (_isNearPlot > 0) then { // found one or more
_nearestPole = _findNearestPole select 0; // get first entry
};
[_distance, _isNearPlot, _nearestPole];