Advertisement
ElDubya

Untitled

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