mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-13 19:52:38 +03:00
modular build code optimization + some extras
This commit is contained in:
@@ -55,31 +55,34 @@ _isLandFireDZ = _itemConfig select 10; //bool
|
|||||||
//Check for nearby plotpoles. Returns [_IsNearPlot,_nearestPole,_ownerID,_friendlies] [int,Obj,int,array]
|
//Check for nearby plotpoles. Returns [_IsNearPlot,_nearestPole,_ownerID,_friendlies] [int,Obj,int,array]
|
||||||
[_isPole, _requireplot, _isLandFireDZ] call player_build_plotCheck;
|
[_isPole, _requireplot, _isLandFireDZ] call player_build_plotCheck;
|
||||||
|
|
||||||
|
if (DZE_ActionInProgress) then { //needed otherwise _hasRequired gets RPT error
|
||||||
|
|
||||||
//Check for build requirements (missing tools and items). Returns [_hasrequireditem,_reason] [bool,string]
|
//Check for build requirements (missing tools and items). Returns [_hasrequireditem,_reason] [bool,string]
|
||||||
_hasRequired = [_require, _text, true, true] call player_build_buildReq;
|
_hasRequired = [_require, _text, true, true] call player_build_buildReq;
|
||||||
|
|
||||||
//define item collected from function
|
//define item collected from function
|
||||||
_hasrequireditem = _hasRequired select 0; //bool
|
_hasrequireditem = _hasRequired select 0; //bool
|
||||||
|
|
||||||
if (_hasrequireditem and DZE_ActionInProgress) then {
|
if (_hasrequireditem) then {
|
||||||
|
|
||||||
//Create object that is attached to a player (i.e Ghost preview if available)
|
//Create object that is attached to a player (i.e Ghost preview if available)
|
||||||
_buildObject = [_classname, _ghost, _offset, true] call player_build_create;
|
_buildObject = [_classname, _ghost, _offset, true] call player_build_create;
|
||||||
|
|
||||||
//define items collected from function
|
//define items collected from function
|
||||||
_location1 = _buildObject select 0; //array
|
_location1 = _buildObject select 0; //array
|
||||||
_object = _buildObject select 1; //Obj
|
_object = _buildObject select 1; //Obj
|
||||||
_position = _buildObject select 2; // array
|
_position = _buildObject select 2; // array
|
||||||
_objectHelper = _buildObject select 3; //Obj
|
_objectHelper = _buildObject select 3; //Obj
|
||||||
|
|
||||||
_controls = [_object, _isAllowedUnderGround, _location1, _position, _objectHelper] call player_build_controls;
|
_controls = [_object, _isAllowedUnderGround, _location1, _position, _objectHelper] call player_build_controls;
|
||||||
|
|
||||||
//define items collected from function
|
//define items collected from function
|
||||||
_cancel = _controls select 0; //bool
|
_cancel = _controls select 0; //bool
|
||||||
_reason = _controls select 1; //string
|
_reason = _controls select 1; //string
|
||||||
_position = _controls select 2; //array
|
_position = _controls select 2; //array
|
||||||
_dir = _controls select 3; //int
|
_dir = _controls select 3; //int
|
||||||
|
|
||||||
//Publish item to a database
|
//Publish item to a database
|
||||||
[_cancel, _position, _classnametmp,_isAllowedUnderGround, _text, _isPole, _lockable,_dir, _reason] call player_build_publish;
|
[_cancel, _position, _classnametmp,_isAllowedUnderGround, _text, _isPole, _lockable,_dir, _reason] call player_build_publish;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
if(!DZE_ActionInProgress) exitWith {};
|
||||||
//Check for build requirements like tools and if item is in magazines (check args to disable checks)
|
//Check for build requirements like tools and if item is in magazines (check args to disable checks)
|
||||||
private ["_passArray","_missing","_hasrequireditem","_require","_hastoolweapon","_hasbuilditem","_checkMag","_checkTools","_reason"];
|
private ["_passArray","_missing","_hasrequireditem","_require","_hastoolweapon","_hasbuilditem","_checkMag","_checkTools","_reason"];
|
||||||
|
|
||||||
@@ -20,11 +21,14 @@ _passArray = [];
|
|||||||
|
|
||||||
_hasbuilditem = DZE_buildItem in magazines player;
|
_hasbuilditem = DZE_buildItem in magazines player;
|
||||||
|
|
||||||
|
_passArray = [_hasrequireditem,_reason];
|
||||||
|
|
||||||
if (_checkMag) then { //passed argument
|
if (_checkMag) then { //passed argument
|
||||||
if (!_hasbuilditem) exitWith { //End script if magazine was not found
|
if (!_hasbuilditem) exitWith { //End script if magazine was not found
|
||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
cutText [format[(localize "str_player_31"),_text,"build"] , "PLAIN DOWN"];
|
cutText [format[(localize "str_player_31"),_text,"build"] , "PLAIN DOWN"];
|
||||||
_reason = "missing item";
|
_reason = "missing item";
|
||||||
|
_passArray
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,9 +37,8 @@ if (_checkTools) then { //passed argument
|
|||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
cutText [format[(localize "str_epoch_player_137"),_missing] , "PLAIN DOWN"];
|
cutText [format[(localize "str_epoch_player_137"),_missing] , "PLAIN DOWN"];
|
||||||
_reason = "missing tools";
|
_reason = "missing tools";
|
||||||
|
_passArray
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
_passArray = [_hasrequireditem,_reason];
|
|
||||||
_passArray //[bool,string]
|
_passArray //[bool,string]
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
private ["_canDo","_passArray","_objHDiff","_isOk","_zheightchanged","_zheightdirection","_rotate","_dir","_object","_position","_isAllowedUnderGround","_location2","_cancel","_reason","_lastDir","_objectHelper","_objectHelperDir","_objectHelperPos"];
|
private ["_canDo","_passArray","_objHDiff","_isOk","_zheightchanged","_zheightdirection","_rotate","_dir","_object","_position","_isAllowedUnderGround","_location1","_location2","_cancel","_reason","_lastDir","_objectHelper","_objectHelperDir","_objectHelperPos"];
|
||||||
|
|
||||||
_object = _this select 0;
|
_object = _this select 0;
|
||||||
_isAllowedUnderGround = _this select 1;
|
_isAllowedUnderGround = _this select 1;
|
||||||
@@ -142,8 +142,6 @@ while {_isOk} do {
|
|||||||
|
|
||||||
_objectHelper setPosATL _position;
|
_objectHelper setPosATL _position;
|
||||||
|
|
||||||
//diag_log format["DEBUG Change BUILDING POS: %1", _position];
|
|
||||||
|
|
||||||
if (!helperDetach) then {
|
if (!helperDetach) then {
|
||||||
_objectHelper attachTo [player];
|
_objectHelper attachTo [player];
|
||||||
};
|
};
|
||||||
@@ -153,13 +151,13 @@ while {_isOk} do {
|
|||||||
|
|
||||||
_location2 = getPosATL player;
|
_location2 = getPosATL player;
|
||||||
_objectHelperPos = getPosATL _objectHelper;
|
_objectHelperPos = getPosATL _objectHelper;
|
||||||
|
|
||||||
if(DZE_5) exitWith {
|
if(DZE_5) exitWith {
|
||||||
_isOk = false;
|
_isOk = false;
|
||||||
detach _object;
|
detach _object;
|
||||||
_dir = getDir _object;
|
|
||||||
_position = getPosATL _object;
|
_position = getPosATL _object;
|
||||||
//diag_log format["DEBUG BUILDING POS: %1", _position];
|
_dir = getDir _object;
|
||||||
|
|
||||||
deleteVehicle _object;
|
deleteVehicle _object;
|
||||||
detach _objectHelper;
|
detach _objectHelper;
|
||||||
deleteVehicle _objectHelper;
|
deleteVehicle _objectHelper;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// disallow building if too many objects are found within 30m
|
// disallow building if too many objects are found within 30m (by default)
|
||||||
private ["_cnt"];
|
private ["_cnt"];
|
||||||
|
|
||||||
_cnt = count ((getPosATL player) nearObjects ["All",30]);
|
_cnt = count ((getPosATL player) nearObjects ["All",DZE_checkNearbyRadius]);
|
||||||
if (_cnt >= DZE_BuildingLimit) exitWith { //end script if too many objects nearby
|
if (_cnt >= DZE_BuildingLimit) exitWith { //end script if too many objects nearby
|
||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
cutText [(localize "str_epoch_player_41"), "PLAIN DOWN"];
|
cutText [(localize "str_epoch_player_41"), "PLAIN DOWN"];
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
if(!DZE_ActionInProgress) exitWith {};
|
||||||
//Build an array of various variables gathered about build object from config files, only applies to legit buildable objects
|
//Build an array of various variables gathered about build object from config files, only applies to legit buildable objects
|
||||||
private ["_passArray","_classname","_classnametmp","_require","_text","_ghost","_lockable","_requireplot","_isAllowedUnderGround","_offset","_isPole","_isLandFireDZ"];
|
private ["_passArray","_classname","_classnametmp","_require","_text","_ghost","_lockable","_requireplot","_isAllowedUnderGround","_offset","_isPole","_isLandFireDZ"];
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
if(!DZE_ActionInProgress) exitWith {};
|
||||||
//disallow building if required items (defined in config) are not found nearby
|
//disallow building if required items (defined in config) are not found nearby
|
||||||
private ["_abort","_reason","_distance","_needNear","_isNear"];
|
private ["_abort","_reason","_distance","_needNear","_isNear"];
|
||||||
|
|
||||||
@@ -41,5 +42,3 @@ if (_abort) exitWith {
|
|||||||
cutText [format[(localize "str_epoch_player_135"),_reason,_distance], "PLAIN DOWN"];
|
cutText [format[(localize "str_epoch_player_135"),_reason,_distance], "PLAIN DOWN"];
|
||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
_reason //return string to a caller
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
if(!DZE_ActionInProgress) exitWith {};
|
||||||
//Check if nearby plotpoles exists
|
//Check if nearby plotpoles exists
|
||||||
private ["_passArray","_isPole","_needText","_distance","_findNearestPoles","_findNearestPole","_IsNearPlot","_requireplot","_isLandFireDZ","_canBuildOnPlot","_nearestPole","_ownerID","_friendlies"];
|
private ["_passArray","_isPole","_needText","_distance","_findNearestPoles","_findNearestPole","_IsNearPlot","_requireplot","_isLandFireDZ","_canBuildOnPlot","_nearestPole","_ownerID","_friendlies"];
|
||||||
|
|
||||||
@@ -11,7 +12,6 @@ _canBuildOnPlot = false;
|
|||||||
_nearestPole = objNull;
|
_nearestPole = objNull;
|
||||||
_ownerID = 0;
|
_ownerID = 0;
|
||||||
_friendlies = [];
|
_friendlies = [];
|
||||||
_passArray = [];
|
|
||||||
|
|
||||||
if(_isPole) then { //check if object is plotpole and adjust distance accordingly
|
if(_isPole) then { //check if object is plotpole and adjust distance accordingly
|
||||||
_distance = DZE_PlotPole select 1;
|
_distance = DZE_PlotPole select 1;
|
||||||
@@ -31,12 +31,6 @@ _findNearestPole = []; //must define an empty array to avoid problems
|
|||||||
|
|
||||||
_IsNearPlot = count (_findNearestPole); //count our new array of non-destroyed plotpoles. Empty array will return 0
|
_IsNearPlot = count (_findNearestPole); //count our new array of non-destroyed plotpoles. Empty array will return 0
|
||||||
|
|
||||||
// End script early if item is plot pole and another one exists within defined radius
|
|
||||||
if(_isPole && _IsNearPlot > 0) exitWith {
|
|
||||||
DZE_ActionInProgress = false;
|
|
||||||
cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"];
|
|
||||||
};
|
|
||||||
|
|
||||||
if(_IsNearPlot == 0) then { //No live plotpoles were found nearby
|
if(_IsNearPlot == 0) then { //No live plotpoles were found nearby
|
||||||
// Allow building of plot
|
// Allow building of plot
|
||||||
if(_requireplot == 0 || _isLandFireDZ) then {
|
if(_requireplot == 0 || _isLandFireDZ) then {
|
||||||
@@ -68,10 +62,18 @@ if(_IsNearPlot == 0) then { //No live plotpoles were found nearby
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_passArray = [_IsNearPlot,_nearestPole,_ownerID,_friendlies]; //create new array and pass it to caller
|
||||||
|
|
||||||
|
// End script if item is plot pole and another one exists within defined radius
|
||||||
|
if(_isPole && _IsNearPlot > 0) exitWith {
|
||||||
|
DZE_ActionInProgress = false;
|
||||||
|
cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"];
|
||||||
|
_passArray
|
||||||
|
};
|
||||||
|
|
||||||
if(!_canBuildOnPlot) exitWith { //end script if requirements were not met
|
if(!_canBuildOnPlot) exitWith { //end script if requirements were not met
|
||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
cutText [format[(localize "STR_EPOCH_PLAYER_135"),_needText,_distance] , "PLAIN DOWN"];
|
cutText [format[(localize "STR_EPOCH_PLAYER_135"),_needText,_distance] , "PLAIN DOWN"];
|
||||||
|
_passArray
|
||||||
};
|
};
|
||||||
|
|
||||||
_passArray = [_IsNearPlot,_nearestPole,_ownerID,_friendlies]; //create new array and pass it to caller
|
|
||||||
_passArray //[int,Obj,int,array]
|
_passArray //[int,Obj,int,array]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
if(!DZE_ActionInProgress) exitWith {};
|
||||||
//disallow building if these conditions are not met
|
//disallow building if these conditions are not met
|
||||||
private ["_isFine","_onLadder","_vehicle","_inVehicle"];
|
private ["_isFine","_onLadder","_vehicle","_inVehicle"];
|
||||||
|
|
||||||
@@ -10,24 +11,28 @@ if (dayz_isSwimming) exitWith { //end script if player is swimming
|
|||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
cutText [localize "str_player_26", "PLAIN DOWN"];
|
cutText [localize "str_player_26", "PLAIN DOWN"];
|
||||||
_isFine = "Swimming";
|
_isFine = "Swimming";
|
||||||
|
_isFine
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_inVehicle) exitWith { //end script if player is in vehicle
|
if (_inVehicle) exitWith { //end script if player is in vehicle
|
||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];
|
cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];
|
||||||
_isFine = "In vehicle";
|
_isFine = "In vehicle";
|
||||||
|
_isFine
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_onLadder) exitWith { //end script if player is climbing on ladder
|
if (_onLadder) exitWith { //end script if player is climbing on ladder
|
||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
cutText [localize "str_player_21", "PLAIN DOWN"];
|
cutText [localize "str_player_21", "PLAIN DOWN"];
|
||||||
_isFine = "On ladder";
|
_isFine = "On ladder";
|
||||||
|
_isFine
|
||||||
};
|
};
|
||||||
|
|
||||||
if (player getVariable["combattimeout", 0] >= time) exitWith { //end script if player is in combat
|
if (player getVariable["combattimeout", 0] >= time) exitWith { //end script if player is in combat
|
||||||
DZE_ActionInProgress = false;
|
DZE_ActionInProgress = false;
|
||||||
cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];
|
cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];
|
||||||
_isFine = "In combat";
|
_isFine = "In combat";
|
||||||
|
_isFine
|
||||||
};
|
};
|
||||||
|
|
||||||
_isFine //returns string to caller, default is "ok" if conditions were not met
|
_isFine //returns string to caller, default is "ok" if conditions were not met
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// July 10 2014 //
|
// July 10 2014 //
|
||||||
/*--------------------------------*/
|
/*--------------------------------*/
|
||||||
|
|
||||||
private ["_object","_objectSnapGizmo","_objColorActive","_objColorInactive","_classname","_whitelist","_points","_radius","_cfg","_cnt","_pos","_findWhitelisted","_nearbyObject","_posNearby","_selectedAction","_newPos","_pointsNearby","_onWater"];
|
private ["_object","_objectSnapGizmo","_objColorActive","_objColorInactive","_classname","_whitelist","_points","_radius","_cfg","_cnt","_pos","_findWhitelisted","_nearbyObject","_posNearby","_selectedAction","_newPos","_pointsNearby","_onWater","_waterBase"];
|
||||||
//Args
|
//Args
|
||||||
snapActionState = _this select 3 select 0;
|
snapActionState = _this select 3 select 0;
|
||||||
_object = _this select 3 select 1;
|
_object = _this select 3 select 1;
|
||||||
@@ -58,8 +58,10 @@ fnc_initSnapPoints = {
|
|||||||
|
|
||||||
fnc_initSnapPointsNearby = {
|
fnc_initSnapPointsNearby = {
|
||||||
_pos = getPosATL _object;
|
_pos = getPosATL _object;
|
||||||
_findWhitelisted = []; _pointsNearby = [];
|
_findWhitelisted = []; _pointsNearby = []; _waterBase = 0;
|
||||||
_findWhitelisted = nearestObjects [_pos,_whitelist,(_radius + DZE_snapExtraRange)]-[_object];
|
_onWater = surfaceIsWater position player;
|
||||||
|
if (_onWater) then { _waterBase = (getPosATL player select 2);};
|
||||||
|
_findWhitelisted = nearestObjects [_pos,_whitelist,(_radius + DZE_snapExtraRange + _waterBase)]-[_object];
|
||||||
snapGizmosNearby = [];
|
snapGizmosNearby = [];
|
||||||
{
|
{
|
||||||
_nearbyObject = _x;
|
_nearbyObject = _x;
|
||||||
|
|||||||
@@ -551,6 +551,9 @@ if (isNil "DZE_modularBuild") then {
|
|||||||
if (isNil "DZE_snapExtraRange") then {
|
if (isNil "DZE_snapExtraRange") then {
|
||||||
DZE_snapExtraRange = 0;
|
DZE_snapExtraRange = 0;
|
||||||
};
|
};
|
||||||
|
if (isNil "DZE_checkNearbyRadius") then {
|
||||||
|
DZE_checkNearbyRadius = 30;
|
||||||
|
};
|
||||||
|
|
||||||
// needed on server
|
// needed on server
|
||||||
if(isNil "DZE_PlotPole") then {
|
if(isNil "DZE_PlotPole") then {
|
||||||
|
|||||||
Reference in New Issue
Block a user