Advertisement
ElDubya

player_build.sqf

Feb 23rd, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 29.09 KB | None | 0 0
  1. /*
  2.     DayZ Base Building
  3.     Made for DayZ Epoch please ask permission to use/edit/distrubute email [email protected].
  4. */
  5. private ["_index","_typeIsString","_helperColor","_objectHelper","_objectHelperDir","_objectHelperPos","_canDo", "_pos", "_cnt",
  6. "_location","_dir","_classname","_item","_hasrequireditem","_missing","_hastoolweapon","_cancel","_reason",
  7. "_started","_finished","_animState","_isMedic","_dis","_sfx","_hasbuilditem","_tmpbuilt","_onLadder","_isWater",
  8. "_require","_text","_offset","_IsNearPlot","_isOk","_location1","_location2","_counter","_limit","_proceed",
  9. "_num_removed","_position","_object","_canBuildOnPlot","_friendlies","_nearestPole","_ownerID","_findNearestPoles",
  10. "_findNearestPole","_distance","_classnametmp","_ghost","_isPole","_needText","_lockable","_zheightchanged",
  11. "_rotate","_combination_1","_combination_2","_combination_3","_combination_4","_combination","_combination_1_Display",
  12. "_combinationDisplay","_zheightdirection","_abort","_isNear","_need","_needNear","_vehicle","_inVehicle","_requireplot",
  13. "_objHDiff","_isLandFireDZ","_isTankTrap","_vector","_buildOffset","_vUp","_posrad","_cntrad","_cntrad2"];
  14.  
  15. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_40") , "PLAIN DOWN"]; };
  16. DZE_ActionInProgress = true;
  17.  
  18. //snap vars -- temporary fix for errors so variables.sqf can be skipped
  19. if (isNil "snapProVariables") then {
  20.     if (isNil "DZE_snapExtraRange") then {
  21.         DZE_snapExtraRange = 0;
  22.     };
  23.     if (isNil "DZE_checkNearbyRadius") then {
  24.         DZE_checkNearbyRadius = 30;
  25.     };
  26.     s_player_toggleSnap = -1;
  27.     s_player_toggleSnapSelect = -1;
  28.     s_player_toggleSnapSelectPoint=[];
  29.     snapActions = -1;
  30.     snapGizmos = [];
  31.     snapGizmosNearby = [];
  32.     snapProVariables = true; // will skip this statement from now on.
  33. };
  34. if(isNil "vectorBuildVariables") then{
  35.     s_player_toggleDegree = -1;
  36.     s_player_toggleDegrees=[];
  37.     degreeActions = -1;
  38.     s_player_toggleVector = -1;
  39.     s_player_toggleVectors=[];
  40.     vectorActions = -1;
  41.     vectorBuildVariables = true;
  42. };
  43. // snap vars
  44.  
  45. // disallow building if too many objects are found within (30m by default) add DZE_checkNearbyRadius = 30; to your init.sqf to change
  46. _pos = [player] call FNC_GetPos;
  47. _cnt = count (_pos nearObjects ["All",DZE_checkNearbyRadius]);
  48.  if (_cnt >= DZE_BuildingLimit) exitWith { //end script if too many objects nearby
  49.     DZE_ActionInProgress = false;
  50.     cutText [(localize "str_epoch_player_41"), "PLAIN DOWN"];
  51.  };
  52.  
  53. _onLadder =     (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  54. _isWater =      dayz_isSwimming;
  55. _cancel = false;
  56. _reason = "";
  57. _canBuildOnPlot = false;
  58.  
  59. _vehicle = vehicle player;
  60. _inVehicle = (_vehicle != player);
  61.  
  62. helperDetach = false;
  63. _canDo = (!r_drag_sqf and !r_player_unconscious);
  64.  
  65. DZE_Q = false;
  66. DZE_Z = false;
  67.  
  68. DZE_Q_alt = false;
  69. DZE_Z_alt = false;
  70.  
  71. DZE_Q_ctrl = false;
  72. DZE_Z_ctrl = false;
  73.  
  74. DZE_5 = false;
  75. DZE_4 = false;
  76. DZE_6 = false;
  77. DZE_F = false;
  78.  
  79. DZE_cancelBuilding = false;
  80.  
  81. DZE_updateVec = false;
  82. DZE_memDir = 0;
  83. DZE_memForBack = 0;
  84. DZE_memLeftRight = 0;
  85.  
  86. call gear_ui_init;
  87. closeDialog 1;
  88.  
  89. if (_isWater) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_26", "PLAIN DOWN"];};
  90. if (_inVehicle) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];};
  91. if (_onLadder) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_21", "PLAIN DOWN"];};
  92. if (player getVariable["combattimeout", 0] >= time) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];};
  93.  
  94. _typeIsString = ((typeName _this) == "STRING");
  95.  
  96. _item = _this;
  97.  
  98.  
  99. // Need Near Requirements
  100. _abort = false;
  101. _reason = "";
  102.  
  103. if (_typeIsString) then {
  104. _needNear =     getArray (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "neednearby");
  105. } else {
  106.     private["_index"];
  107.     _index = _this call getDeployableIndex;
  108.     _needNear = _index call getDeployableNeedNearBy;
  109. };
  110. systemchat format["_index: %1",_index];
  111. {
  112.     switch(_x) do{
  113.         case "fire":
  114.         {
  115.             _distance = 3;
  116.             _isNear = {inflamed _x} count (_pos nearObjects _distance);
  117.             if(_isNear == 0) then {
  118.                 _abort = true;
  119.                 _reason = "fire";
  120.             };
  121.         };
  122.         case "workshop":
  123.         {
  124.             _distance = 3;
  125.             _isNear = count (nearestObjects [_pos, ["Wooden_shed_DZ","WoodShack_DZ","WorkBench_DZ"], _distance]);
  126.             if(_isNear == 0) then {
  127.                 _abort = true;
  128.                 _reason = "workshop";
  129.             };
  130.         };
  131.         case "fueltank":
  132.         {
  133.             _distance = 30;
  134.             _isNear = count (nearestObjects [_pos, dayz_fuelsources, _distance]);
  135.             if(_isNear == 0) then {
  136.                 _abort = true;
  137.                 _reason = "fuel tank";
  138.             };
  139.         };
  140.     };
  141. } forEach _needNear;
  142.  
  143.  
  144. if(_abort) exitWith {
  145.     cutText [format[(localize "str_epoch_player_135"),_reason,_distance], "PLAIN DOWN"];
  146.     DZE_ActionInProgress = false;
  147. };
  148.  
  149. if (_typeIsString) then {
  150. _classname =    getText (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "create");
  151. _classnametmp = _classname;
  152. _require =  getArray (configFile >> "cfgMagazines" >> _this >> "ItemActions" >> "Build" >> "require");
  153. _text =         getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  154. _ghost = getText (configFile >> "CfgVehicles" >> _classname >> "ghostpreview");
  155.  
  156. } else {
  157. _classname      = _index call getDeployableClass;
  158. _classnametmp   = _classname;
  159. _require        = [];
  160. _text           = _index call getDeployableDisplay;
  161. _ghost          = "";
  162. };
  163.  
  164. _lockable = 0;
  165. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "lockable")) then {
  166.     _lockable = getNumber(configFile >> "CfgVehicles" >> _classname >> "lockable");
  167. };
  168.  
  169.  
  170.  
  171.  
  172. if (_typeIsString) then {
  173.         _requireplot = DZE_requireplot;
  174.         if(isNumber (configFile >> "CfgVehicles" >> _classname >> "requireplot")) then {
  175.             _requireplot = getNumber(configFile >> "CfgVehicles" >> _classname >> "requireplot");
  176.         };
  177. } else {
  178.         if(_index call getDeployableRequirePlot) then {_requireplot = 1;} else {_requireplot = 0;};
  179. };
  180.  
  181. if (_classname in schwedes_requirePlot) then {
  182. _requireplot = 1;
  183. };
  184.  
  185. _isAllowedUnderGround = 1;
  186. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "nounderground")) then {
  187.     _isAllowedUnderGround = getNumber(configFile >> "CfgVehicles" >> _classname >> "nounderground");
  188. };
  189.  
  190. if (_typeIsString) then {
  191.     _offset =   getArray (configFile >> "CfgVehicles" >> _classname >> "offset");
  192.     if((count _offset) <= 0) then {
  193.         _offset = [0,1.5,0];
  194.     };
  195.     } else {
  196.         _offset = _index call getDeployableDistanceOffset;
  197. };
  198. _isPole = (_classname == "Plastic_Pole_EP1_DZ");
  199. _isLandFireDZ = (_classname == "Land_Fire_DZ");
  200.  
  201. _distance = DZE_PlotPole select 0;
  202. _needText = localize "str_epoch_player_246";
  203.  
  204. if(_isPole) then {
  205.     _distance = DZE_PlotPole select 1;
  206. };
  207.  
  208. // check for near plot
  209. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  210. _findNearestPole = [];
  211.  
  212. {
  213.     if (alive _x) then {
  214.         _findNearestPole set [(count _findNearestPole),_x];
  215.     };
  216. } count _findNearestPoles;
  217.  
  218. _IsNearPlot = count (_findNearestPole);
  219.  
  220. // If item is plot pole && another one exists within 45m
  221. if(_isPole && _IsNearPlot > 0) exitWith { DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"]; };
  222.  
  223. if(_IsNearPlot == 0) then {
  224.  
  225.     // Allow building of plot
  226.     if(_requireplot == 0 || _isLandFireDZ) then {
  227.         _canBuildOnPlot = true;
  228.     };
  229.  
  230. } else {
  231.     // Since there are plots nearby we check for ownership && then for friend status
  232.  
  233.     // check nearby plots ownership && then for friend status
  234.     _nearestPole = _findNearestPole select 0;
  235.  
  236.     // Find owner
  237.     _ownerID = _nearestPole getVariable ["CharacterID","0"];
  238.  
  239.     // diag_log format["DEBUG BUILDING: %1 = %2", dayz_characterID, _ownerID];
  240.  
  241.     // check if friendly to owner
  242.     if(dayz_characterID == _ownerID) then {  //Keep ownership
  243.         // owner can build anything within his plot except other plots
  244.         if(!_isPole) then {
  245.             _canBuildOnPlot = true;
  246.         };
  247.  
  248.     } else {
  249.         // disallow building plot
  250.         if(!_isPole) then {
  251.             _friendlies = _nearestPole getVariable ["plotfriends",[]];
  252.             _fuid  = [];
  253.     {
  254.             _friendUID = _x select 0;
  255.             _fuid  =  _fuid  + [_friendUID];
  256.     } forEach _friendlies;
  257.             _builder  = getPlayerUID player;
  258.             // check if friendly to owner
  259.             if(_builder in _fuid) then {
  260.             _canBuildOnPlot = true;
  261.             };
  262.         };
  263.     };
  264. };
  265.  
  266. // _message
  267. if(!_canBuildOnPlot) exitWith { DZE_ActionInProgress = false; cutText [format[(localize "STR_EPOCH_PLAYER_135"),_needText,_distance] , "PLAIN DOWN"]; };
  268.  
  269. _missing = "";
  270. _hasrequireditem = true;
  271. {
  272. _hastoolweapon = _x in weapons player;
  273. if(!_hastoolweapon) exitWith { _hasrequireditem = false; _missing = getText (configFile >> "cfgWeapons" >> _x >> "displayName"); };
  274. } count _require;
  275.  
  276. if !(_typeIsString) then {
  277. _hastoolweapon = (_index call getDeployableKitClass) in ((weapons player) + (magazines player));
  278. if(!_hastoolweapon) then { _hasrequireditem = false; _missing = (_index call getDeployableKitDisplay); };
  279. };
  280.  
  281.  
  282. if (_typeIsString) then {
  283.         _hasbuilditem = _this in magazines player;
  284.         if (!_hasbuilditem) exitWith {DZE_ActionInProgress = false; cutText [format[(localize "str_player_31"),_text,"build"] , "PLAIN DOWN"]; };
  285.  
  286. } else {
  287.         _hasbuilditem = [player,_index] call getHasDeployableParts;
  288.         if (!_hasbuilditem) exitWith {DZE_ActionInProgress = false; cutText [format[(localize "str_player_31"),str (_index call getDeployableParts),"build"] , "PLAIN DOWN"]; };
  289.  
  290. };
  291.  
  292. if (!_hasrequireditem) exitWith {DZE_ActionInProgress = false; cutText [format[(localize "str_epoch_player_137"),_missing] , "PLAIN DOWN"]; };
  293. if (_hasrequireditem) then {
  294.  
  295.     _location = [0,0,0];
  296.     _isOk = true;
  297.  
  298.     // get inital players position
  299.     _location1 = [player] call FNC_GetPos;
  300.     _dir = getDir player;
  301.  
  302.     // if ghost preview available use that instead
  303.     if (_ghost != "") then {
  304.         _classname = _ghost;
  305.     };
  306.  
  307.     _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  308.     //Build gizmo
  309.     if (_typeIsString) then {
  310.             _objectHelper = "Sign_sphere10cm_EP1" createVehicle _location;
  311.             _helperColor = "#(argb,8,8,3)color(0,0,0,0,ca)";
  312.             _objectHelper setobjecttexture [0,_helperColor];
  313.             _objectHelper attachTo [player,_offset];
  314.             _object attachTo [_objectHelper,[0,0,0]];
  315.             _position = [_objectHelper] call FNC_GetPos;
  316.     } else {
  317.         _object setVariable["ObjectUID","1",true];
  318.  
  319.         _object attachTo [player,_offset];
  320.        
  321.         _object setDir _dir;
  322.         _position = getPosATL _object;
  323.  
  324.         cutText [(localize "str_epoch_player_45"), "PLAIN DOWN"];
  325.     };
  326.  
  327.    
  328.     _objHDiff = 0;
  329.  
  330.     if (isClass (missionConfigFile >> "SnapBuilding" >> _classname)) then {
  331.         ["","","",["Init",_object,_classname,_objectHelper]] spawn snap_build;
  332.     };
  333.    
  334.     if !(_item in DZE_noRotate) then{
  335.         ["","","",["Init","Init",0]] spawn build_vectors;
  336.     };
  337.     while {_isOk} do {
  338.  
  339.         _zheightchanged = false;
  340.         _zheightdirection = "";
  341.         _rotate = false;
  342.  
  343.         if (DZE_Q) then {
  344.             DZE_Q = false;
  345.             _zheightdirection = "up";
  346.             _zheightchanged = true;
  347.         };
  348.         if (DZE_Z) then {
  349.             DZE_Z = false;
  350.             _zheightdirection = "down";
  351.             _zheightchanged = true;
  352.         };
  353.         if (DZE_Q_alt) then {
  354.             DZE_Q_alt = false;
  355.             _zheightdirection = "up_alt";
  356.             _zheightchanged = true;
  357.         };
  358.         if (DZE_Z_alt) then {
  359.             DZE_Z_alt = false;
  360.             _zheightdirection = "down_alt";
  361.             _zheightchanged = true;
  362.         };
  363.         if (DZE_Q_ctrl) then {
  364.             DZE_Q_ctrl = false;
  365.             _zheightdirection = "up_ctrl";
  366.             _zheightchanged = true;
  367.         };
  368.         if (DZE_Z_ctrl) then {
  369.             DZE_Z_ctrl = false;
  370.             _zheightdirection = "down_ctrl";
  371.             _zheightchanged = true;
  372.         };
  373.         if (DZE_4) then {
  374.             _rotate = true;
  375.             DZE_4 = false;
  376.             if (_typeIsString) then {
  377.                 if(DZE_dirWithDegrees) then{
  378.                     DZE_memDir = DZE_memDir - DZE_curDegree;
  379.                 }else{
  380.                     DZE_memDir = DZE_memDir - 45;
  381.                 };
  382.             } else {
  383.                     _dir = _dir + 30;
  384.             };
  385.  
  386.  
  387.         };
  388.         if (DZE_6) then {
  389.             _rotate = true;
  390.             DZE_6 = false;
  391.                 if (_typeIsString) then {
  392.                         if(DZE_dirWithDegrees) then{
  393.                             DZE_memDir = DZE_memDir + DZE_curDegree;
  394.                         }else{
  395.                             DZE_memDir = DZE_memDir + 45;
  396.                         };
  397.                 } else {
  398.                        _dir = _dir - 30;
  399.                 };
  400.         };
  401.        
  402.         if(DZE_updateVec) then{
  403.             [_objectHelper,[DZE_memForBack,DZE_memLeftRight,DZE_memDir]] call fnc_SetPitchBankYaw;
  404.             DZE_updateVec = false;
  405.         };
  406.        
  407.         if (DZE_F and _canDo) then {
  408.             if (helperDetach) then {
  409.                 _objectHelper attachTo [player];
  410.                 DZE_memDir = DZE_memDir-(getDir player);
  411.                 helperDetach = false;
  412.                 [_objectHelper,[DZE_memForBack,DZE_memLeftRight,DZE_memDir]] call fnc_SetPitchBankYaw;
  413.             } else {       
  414.                 _objectHelperPos = getPosATL _objectHelper;
  415.                 detach _objectHelper;          
  416.                 DZE_memDir = getDir _objectHelper;
  417.                 [_objectHelper,[DZE_memForBack,DZE_memLeftRight,DZE_memDir]] call fnc_SetPitchBankYaw;
  418.                 _objectHelper setPosATL _objectHelperPos;
  419.                 _objectHelper setVelocity [0,0,0]; //fix sliding glitch
  420.                 helperDetach = true;
  421.             };
  422.             DZE_F = false;
  423.         };
  424.  
  425.         if(_rotate) then {
  426.             [_objectHelper,[DZE_memForBack,DZE_memLeftRight,DZE_memDir]] call fnc_SetPitchBankYaw;
  427.         };
  428.  
  429.         if(_zheightchanged) then {
  430.             if (!helperDetach) then {
  431.                 detach _objectHelper;
  432.                 _objectHelperDir = getDir _objectHelper;
  433.             };
  434.  
  435.             _position = [_objectHelper] call FNC_GetPos;
  436.  
  437.             if(_zheightdirection == "up") then {
  438.                 _position set [2,((_position select 2)+0.1)];
  439.                 _objHDiff = _objHDiff + 0.1;
  440.             };
  441.             if(_zheightdirection == "down") then {
  442.                 _position set [2,((_position select 2)-0.1)];
  443.                 _objHDiff = _objHDiff - 0.1;
  444.             };
  445.  
  446.             if(_zheightdirection == "up_alt") then {
  447.                 _position set [2,((_position select 2)+1)];
  448.                 _objHDiff = _objHDiff + 1;
  449.             };
  450.             if(_zheightdirection == "down_alt") then {
  451.                 _position set [2,((_position select 2)-1)];
  452.                 _objHDiff = _objHDiff - 1;
  453.             };
  454.  
  455.             if(_zheightdirection == "up_ctrl") then {
  456.                 _position set [2,((_position select 2)+0.01)];
  457.                 _objHDiff = _objHDiff + 0.01;
  458.             };
  459.             if(_zheightdirection == "down_ctrl") then {
  460.                 _position set [2,((_position select 2)-0.01)];
  461.                 _objHDiff = _objHDiff - 0.01;
  462.             };
  463.  
  464.             if((_isAllowedUnderGround == 0) && ((_position select 2) < 0)) then {
  465.                 _position set [2,0];
  466.             };
  467.  
  468.             if (surfaceIsWater _position) then {
  469.                 _objectHelper setPosASL _position;
  470.             } else {
  471.                 _objectHelper setPosATL _position;
  472.             };
  473.  
  474.             if (_typeIsString) then {
  475.                         if (!helperDetach) then {
  476.                             _objectHelper attachTo [player];
  477.                         };
  478.                        
  479.                         [_objectHelper,[DZE_memForBack,DZE_memLeftRight,DZE_memDir]] call fnc_SetPitchBankYaw;
  480.             } else {
  481.                         _object setPosATL _position;
  482.  
  483.                         _object attachTo [player];
  484.  
  485.                         _object setDir _dir;
  486.             };
  487.  
  488.            
  489.         };
  490.  
  491.         sleep 0.5;
  492.        
  493.         if (_typeIsString) then {
  494.             _location2 = [player] call FNC_GetPos;
  495.             _objectHelperPos = [_objectHelper] call FNC_GetPos;
  496.         } else {
  497.             _location2 = getPosATL player;
  498.             _objectHelperPos = getPosATL _object;
  499.         };
  500.         if (_typeIsString) then {
  501.             if(DZE_5) exitWith {
  502.                 _isOk = false;
  503.                 _position = [_object] call FNC_GetPos;
  504.                 detach _object;
  505.                 _dir = getDir _object;
  506.                 _vector = [(vectorDir _object),(vectorUp _object)];
  507.                 deleteVehicle _object;
  508.                 detach _objectHelper;
  509.                 deleteVehicle _objectHelper;
  510.             };
  511.         } else {
  512.                 if(DZE_5) exitWith {
  513.                     _isOk = false;
  514.                     detach _object;
  515.                     _dir = getDir _object;
  516.                     _position = getPosATL _object;
  517.                     //diag_log format["DEBUG BUILDING POS: %1", _position];
  518.                     _object setPos[0,0,0];
  519.                     hideObject _object;
  520.                     deleteVehicle _object;
  521.                 };
  522.         };
  523.  
  524.         if(_location1 distance _location2 > 10) exitWith {
  525.             _isOk = false;
  526.             _cancel = true;
  527.             _reason = "You've moved to far away from where you started building (within 10 meters)";
  528.             detach _object;
  529.             deleteVehicle _object;
  530.             detach _objectHelper;
  531.             deleteVehicle _objectHelper;
  532.         };
  533.        
  534.         if(_location1 distance _objectHelperPos > 10) exitWith {
  535.             _isOk = false;
  536.             _cancel = true;
  537.             _reason = "Object is placed to far away from where you started building (within 10 meters)";
  538.             detach _object;
  539.             deleteVehicle _object;
  540.             detach _objectHelper;
  541.             deleteVehicle _objectHelper;
  542.         };
  543.  
  544.         if(abs(_objHDiff) > 10) exitWith {
  545.             _isOk = false;
  546.             _cancel = true;
  547.             _reason = "Cannot move up or down more than 10 meters";
  548.             detach _object;
  549.             deleteVehicle _object;
  550.             detach _objectHelper;
  551.             deleteVehicle _objectHelper;
  552.         };
  553.  
  554.         if (player getVariable["combattimeout", 0] >= time) exitWith {
  555.             _isOk = false;
  556.             _cancel = true;
  557.             _reason = (localize "str_epoch_player_43");
  558.             detach _object;
  559.             deleteVehicle _object;
  560.             detach _objectHelper;
  561.             deleteVehicle _objectHelper;
  562.         };
  563.  
  564.         if (DZE_cancelBuilding) exitWith {
  565.             _isOk = false;
  566.             _cancel = true;
  567.             _reason = "Cancelled building.";
  568.             detach _object;
  569.             deleteVehicle _object;
  570.             detach _objectHelper;
  571.             deleteVehicle _objectHelper;
  572.         };
  573.     };
  574.  
  575.     //No building on roads unless toggled
  576.     if (_typeIsString) then {
  577.             if (!DZE_BuildOnRoads) then {
  578.                 if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  579.             };
  580.     } else {
  581.         if (!(_index call getDeployableBuildOnRoad)) then {
  582.             if (isOnRoad [_position select 0, _position select 1, 0]) then { _cancel = true; _reason = "Cannot build on a road."; };
  583.         };
  584.     };
  585.     if (!DZE_BuildOnRoads) then {
  586.         if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  587.     };
  588.  
  589.     // No building in trader zones
  590.     if(!canbuild) then { _cancel = true; _reason = "Cannot build in a city."; };
  591.    
  592.     _posrad = [player] call FNC_GetPos;
  593.     _cntrad = count (nearestObjects [_posrad, ServerNoBuildList, ServerIllegalRadius]);
  594.     _cntrad2 = count (nearestObjects [_posrad, ServerNoBuildList2, ServerIllegalRadius2]);
  595.  
  596.      
  597.     if (_cntrad > 0) then {
  598.     _cancel = true;
  599.     _reason = format["- Building is restricted %1m near military areas!", ServerIllegalRadius];
  600.     };
  601.     if (_cntrad2 > 0) then {
  602.     _cancel = true;
  603.     _reason = format["- Building is restricted %1m near trader areas!", ServerIllegalRadius2];
  604.     };
  605.  
  606.     if(!_cancel) then {
  607.  
  608.         _classname = _classnametmp;
  609.  
  610.         // Start Build
  611.         _tmpbuilt = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  612.  
  613.         _tmpbuilt setdir _dir;
  614.         _tmpbuilt setVariable["memDir",_dir,true];
  615.        
  616.         if !(_typeIsString) then {        
  617.             if (!(_index call getDeployableSimulation)) then {
  618.                 _tmpbuilt enableSimulation false;
  619.             };
  620.             _tmpbuilt setVariable ["ObjectUID", "1", true];
  621.         };
  622.        
  623.         // Get position based on object
  624.         _location = _position;
  625.  
  626.         if((_isAllowedUnderGround == 0) && ((_location select 2) < 0)) then {
  627.             _location set [2,0];
  628.         };
  629.  
  630.         _tmpbuilt setVectorDirAndUp _vector;
  631.    
  632.         _buildOffset = [0,0,0];
  633.         _vUp = _vector select 1;
  634.         switch (_classname) do {
  635.             case "MetalFloor_DZ": { _buildOffset = [(_vUp select 0) * .148, (_vUp select 1) * .148,0]; };
  636.         };
  637.        
  638.         _location = [
  639.             (_location select 0) - (_buildOffset select 0),
  640.             (_location select 1) - (_buildOffset select 1),
  641.             (_location select 2) - (_buildOffset select 2)
  642.         ];
  643.        
  644.         if (surfaceIsWater _location) then {
  645.             _tmpbuilt setPosASL _location;
  646.             _location = ASLtoATL _location; //Database uses ATL
  647.         } else {
  648.             _tmpbuilt setPosATL _location;
  649.         };
  650.  
  651.         cutText [format[(localize "str_epoch_player_138"),_text], "PLAIN DOWN"];
  652.  
  653.         _limit = 3;
  654.  
  655.         if (DZE_StaticConstructionCount > 0) then {
  656.             _limit = DZE_StaticConstructionCount;
  657.         }
  658.         else {
  659.             if (isNumber (configFile >> "CfgVehicles" >> _classname >> "constructioncount")) then {
  660.                 _limit = getNumber(configFile >> "CfgVehicles" >> _classname >> "constructioncount");
  661.             };
  662.         };
  663.  
  664.         _isOk = true;
  665.         _proceed = false;
  666.         _counter = 0;
  667.  
  668.         while {_isOk} do {
  669.  
  670.             [10,10] call dayz_HungerThirst;
  671.             player playActionNow "Medic";
  672.  
  673.             _dis=20;
  674.             _sfx = "repair";
  675.             [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
  676.             [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
  677.  
  678.             r_interrupt = false;
  679.             r_doLoop = true;
  680.             _started = false;
  681.             _finished = false;
  682.  
  683.             while {r_doLoop} do {
  684.                 _animState = animationState player;
  685.                 _isMedic = ["medic",_animState] call fnc_inString;
  686.                 if (_isMedic) then {
  687.                     _started = true;
  688.                 };
  689.                 if (_started && !_isMedic) then {
  690.                     r_doLoop = false;
  691.                     _finished = true;
  692.                 };
  693.                 if (r_interrupt || (player getVariable["combattimeout", 0] >= time)) then {
  694.                     r_doLoop = false;
  695.                 };
  696.                 if (DZE_cancelBuilding) exitWith {
  697.                     r_doLoop = false;
  698.                 };
  699.                 sleep 0.1;
  700.             };
  701.             r_doLoop = false;
  702.  
  703.  
  704.             if(!_finished) exitWith {
  705.                 _isOk = false;
  706.                 _proceed = false;
  707.             };
  708.  
  709.             if(_finished) then {
  710.                 _counter = _counter + 1;
  711.             };
  712.  
  713.             cutText [format[(localize "str_epoch_player_139"),_text, _counter,_limit], "PLAIN DOWN"];
  714.  
  715.             if(_counter == _limit) exitWith {
  716.                 _isOk = false;
  717.                 _proceed = true;
  718.             };
  719.  
  720.         };
  721.  
  722.         if (_proceed) then {
  723.  
  724.         if (_typeIsString) then {
  725.         _num_removed = ([player,_item] call BIS_fnc_invRemove);
  726.             if(_num_removed == 1) then {
  727.  
  728.                 cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  729.  
  730.                 if (_isPole) then {
  731.                     [] spawn player_plotPreview;
  732.                 };
  733.  
  734.                 _tmpbuilt setVariable ["OEMPos",_location,true];
  735.  
  736.                 if(_lockable > 1) then {
  737.  
  738.                     _combinationDisplay = "";
  739.  
  740.                     switch (_lockable) do {
  741.  
  742.                         case 2: { // 2 lockbox
  743.                             _combination_1 = (floor(random 3)) + 100; // 100=red,101=green,102=blue
  744.                             _combination_2 = floor(random 10);
  745.                             _combination_3 = floor(random 10);
  746.                             _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  747.                             dayz_combination = _combination;
  748.                             if (_combination_1 == 100) then {
  749.                                 _combination_1_Display = "Red";
  750.                             };
  751.                             if (_combination_1 == 101) then {
  752.                                 _combination_1_Display = "Green";
  753.                             };
  754.                             if (_combination_1 == 102) then {
  755.                                 _combination_1_Display = "Blue";
  756.                             };
  757.                             _combinationDisplay = format["%1%2%3",_combination_1_Display,_combination_2,_combination_3];
  758.                         };
  759.  
  760.                         case 3: { // 3 combolock
  761.                             _combination_1 = floor(random 10);
  762.                             _combination_2 = floor(random 10);
  763.                             _combination_3 = floor(random 10);
  764.                             _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  765.                             dayz_combination = _combination;
  766.                             _combinationDisplay = _combination;
  767.                         };
  768.  
  769.                         case 4: { // 4 safe
  770.                             _combination_1 = floor(random 10);
  771.                             _combination_2 = floor(random 10);
  772.                             _combination_3 = floor(random 10);
  773.                             _combination_4 = floor(random 10);
  774.                             _combination = format["%1%2%3%4",_combination_1,_combination_2,_combination_3,_combination_4];
  775.                             dayz_combination = _combination;
  776.                             _combinationDisplay = _combination;
  777.                         };
  778.                     };
  779.  
  780.                     _tmpbuilt setVariable ["CharacterID",_combination,true];
  781.  
  782.  
  783.                     PVDZE_obj_Publish = [_combination,_tmpbuilt,[_dir,_location,_vector],_classname];
  784.                     publicVariableServer "PVDZE_obj_Publish";
  785.  
  786.                     cutText [format[(localize "str_epoch_player_140"),_combinationDisplay,_text], "PLAIN DOWN", 5];
  787.  
  788.  
  789.                 } else {
  790.                     _tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
  791.  
  792.                     // fire?
  793.                     if(_tmpbuilt isKindOf "Land_Fire_DZ") then {
  794.                         _tmpbuilt spawn player_fireMonitor;
  795.                     } else {
  796.                         PVDZE_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location,_vector],_classname];
  797.                         publicVariableServer "PVDZE_obj_Publish";
  798.                     };
  799.                     if(_tmpbuilt isKindOf "Plastic_Pole_EP1_DZ") then {
  800.                         _tmpbuilt setVariable ["plotfriends",[[(getPlayerUID player),(name player)]],true];
  801.                         PVDZE_veh_Update = [_tmpbuilt,"gear"];
  802.                         publicVariableServer "PVDZE_veh_Update";
  803.                     };
  804.                 };
  805.             } else {
  806.                 deleteVehicle _tmpbuilt;
  807.                 cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  808.             };
  809.         } else {
  810.                 if([player,_index] call getHasDeployableParts) then {
  811.                 [player,_index] call removeDeployableParts;
  812.             //###BEGIN MODIFIED CODE
  813.  
  814.                 cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  815.  
  816.                 if (_isPole) then {
  817.                     [] spawn player_plotPreview;
  818.                 };
  819.  
  820.                 _tmpbuilt setVariable ["OEMPos",_location,true];
  821.  
  822.                 if(_lockable > 1) then {
  823.  
  824.                     _combinationDisplay = "";
  825.  
  826.                     switch (_lockable) do {
  827.  
  828.                         case 2: { // 2 lockbox
  829.                             _combination_1 = (floor(random 3)) + 100; // 100=red,101=green,102=blue
  830.                             _combination_2 = floor(random 10);
  831.                             _combination_3 = floor(random 10);
  832.                             _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  833.                             dayz_combination = _combination;
  834.                             if (_combination_1 == 100) then {
  835.                                 _combination_1_Display = "Red";
  836.                             };
  837.                             if (_combination_1 == 101) then {
  838.                                 _combination_1_Display = "Green";
  839.                             };
  840.                             if (_combination_1 == 102) then {
  841.                                 _combination_1_Display = "Blue";
  842.                             };
  843.                             _combinationDisplay = format["%1%2%3",_combination_1_Display,_combination_2,_combination_3];
  844.                         };
  845.  
  846.                         case 3: { // 3 combolock
  847.                             _combination_1 = floor(random 10);
  848.                             _combination_2 = floor(random 10);
  849.                             _combination_3 = floor(random 10);
  850.                             _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  851.                             dayz_combination = _combination;
  852.                             _combinationDisplay = _combination;
  853.                         };
  854.  
  855.                         case 4: { // 4 safe
  856.                             _combination_1 = floor(random 10);
  857.                             _combination_2 = floor(random 10);
  858.                             _combination_3 = floor(random 10);
  859.                             _combination_4 = floor(random 10);
  860.                             _combination = format["%1%2%3%4",_combination_1,_combination_2,_combination_3,_combination_4];
  861.                             dayz_combination = _combination;
  862.                             _combinationDisplay = _combination;
  863.                         };
  864.                     };
  865.  
  866.                     _tmpbuilt setVariable ["CharacterID",_combination,true];
  867.  
  868.  
  869.                     PVDZE_obj_Publish = [_combination,_tmpbuilt,[_dir,_location],_classname];
  870.                     publicVariableServer "PVDZE_obj_Publish";
  871.  
  872.                     cutText [format[(localize "str_epoch_player_140"),_combinationDisplay,_text], "PLAIN DOWN", 5];
  873.  
  874.  
  875.                 } else {
  876.                     //_tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
  877.                     //### BEGIN MODIFIED CODE: player deploy
  878.                     // fire?
  879.                     //if(_tmpbuilt isKindOf "Land_Fire_DZ") then {
  880.                     //    _tmpbuilt spawn player_fireMonitor;
  881.                     //} else {
  882.                     //    PVDZE_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location],_classname];
  883.                     //    publicVariableServer "PVDZE_obj_Publish";
  884.                     //};
  885.                     if (_index call getPermanent) then {
  886.                         _tmpbuilt call fnc_set_temp_deployable_id;
  887.                         if(_index call getDeployableSimulation) then {
  888.                             PVDZE_veh_Publish = [_tmpbuilt,[_dir,_position],(_index call getDeployableClass),true,call fnc_perm_deployable_id];
  889.                             publicVariableServer "PVDZE_veh_Publish";
  890.                         } else {
  891.                             PVDZE_obj_Publish = [call fnc_perm_deployable_id,_tmpbuilt,[_dir,_position],(_index call getDeployableClass)];
  892.                             publicVariableServer "PVDZE_obj_Publish";
  893.                         };
  894.                     } else {
  895.                         _tmpbuilt call fnc_set_temp_deployable_id;
  896.                     };
  897.                     if(_index call getClearCargo) then {
  898.                         clearWeaponCargoGlobal _tmpbuilt;
  899.                         clearMagazineCargoGlobal _tmpbuilt;
  900.                     };
  901.                     if(_index call getDeployableClearAmmo) then {
  902.                         _tmpbuilt setVehicleAmmo 0;
  903.                     };
  904.                     player reveal _tmpbuilt;
  905.                     DZE_DEPLOYING_SUCCESSFUL = true;
  906.                     //### END MODIFIED CODE: player deploy
  907.                 };
  908.             } else {
  909.                 _tmpbuilt setPos[0,0,0];
  910.                 hideObject _tmpbuilt;
  911.                 deleteVehicle _tmpbuilt;
  912.                 cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  913.             };
  914.         };
  915.            
  916.  
  917.         } else {
  918.             r_interrupt = false;
  919.             if (vehicle player == player) then {
  920.                 [objNull, player, rSwitchMove,""] call RE;
  921.                 player playActionNow "stop";
  922.             };
  923.  
  924.             deleteVehicle _tmpbuilt;
  925.  
  926.             cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  927.         };
  928.  
  929.     } else {
  930.         cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
  931.     };
  932. };
  933.  
  934. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement