Advertisement
ElDubya

player_build.sqf

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