Advertisement
haywardgb

Prevent Building in All Cities , towns and villages

Jun 30th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.26 KB | None | 0 0
  1. /*
  2.     DayZ Base Building
  3.     Made for DayZ Epoch please ask permission to use/edit/distrubute email vbawol@veteranbastards.com.
  4. */
  5. private ["_nearestCity","_location","_dir","_classname","_item","_hasrequireditem","_missing","_hastoolweapon","_cancel","_reason","_started","_finished","_animState","_isMedic","_dis","_sfx","_hasbuilditem","_tmpbuilt","_onLadder","_isWater","_require","_text","_offset","_IsNearPlot","_isOk","_location1","_location2","_counter","_limit","_proceed","_num_removed","_position","_object","_canBuildOnPlot","_friendlies","_nearestPole","_ownerID","_findNearestPoles","_findNearestPole","_distance","_classnametmp","_ghost","_isPole","_needText","_lockable","_zheightchanged","_rotate","_combination_1","_combination_2","_combination_3","_combination_4","_combination","_combination_1_Display","_combinationDisplay","_zheightdirection","_abort","_isNear","_need","_needNear","_vehicle","_inVehicle","_requireplot","_objHDiff","_isLandFireDZ","_isTankTrap"];
  6. // NO building in cities or towns (if you don't mind people building in Villages, remove "NameVillage" etc)
  7. _nearestCity = nearestLocations [getPos player, ["NameCityCapital","NameCity","NameVillage"],500];
  8.  
  9. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_40") , "PLAIN DOWN"]; };
  10. DZE_ActionInProgress = true;
  11.  
  12.  
  13.  
  14. // disallow building if too many objects are found within 30m
  15. if((count ((getPosATL player) nearObjects ["All",30])) >= DZE_BuildingLimit) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_41"), "PLAIN DOWN"];};
  16.  
  17. _onLadder =     (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  18. _isWater =      dayz_isSwimming;
  19. _cancel = false;
  20. _reason = "";
  21. _canBuildOnPlot = false;
  22.  
  23. _vehicle = vehicle player;
  24. _inVehicle = (_vehicle != player);
  25.  
  26. DZE_Q = false;
  27. DZE_Z = false;
  28.  
  29. DZE_Q_alt = false;
  30. DZE_Z_alt = false;
  31.  
  32. DZE_Q_ctrl = false;
  33. DZE_Z_ctrl = false;
  34.  
  35. DZE_5 = false;
  36. DZE_4 = false;
  37. DZE_6 = false;
  38.  
  39. DZE_cancelBuilding = false;
  40.  
  41. call gear_ui_init;
  42. closeDialog 1;
  43.  
  44. if (_isWater) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_26", "PLAIN DOWN"];};
  45. if (_inVehicle) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];};
  46. if (_onLadder) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_21", "PLAIN DOWN"];};
  47. if (player getVariable["combattimeout", 0] >= time) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];};
  48. // No building in Cities or Towns
  49. if (count _nearestCity > 0) exitWith { DZE_ActionInProgress = false; systemChat ("You cannot build here!");};
  50.  
  51. _item = _this;
  52.  
  53. // Need Near Requirements
  54. _abort = false;
  55. _reason = "";
  56.  
  57. _needNear =     getArray (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "neednearby");
  58.  
  59. {
  60.     switch(_x) do{
  61.         case "fire":
  62.         {
  63.             _distance = 3;
  64.             _isNear = {inflamed _x} count (getPosATL player nearObjects _distance);
  65.             if(_isNear == 0) then {
  66.                 _abort = true;
  67.                 _reason = "fire";
  68.             };
  69.         };
  70.         case "workshop":
  71.         {
  72.             _distance = 3;
  73.             _isNear = count (nearestObjects [player, ["Wooden_shed_DZ","WoodShack_DZ","WorkBench_DZ"], _distance]);
  74.             if(_isNear == 0) then {
  75.                 _abort = true;
  76.                 _reason = "workshop";
  77.             };
  78.         };
  79.         case "fueltank":
  80.         {
  81.             _distance = 30;
  82.             _isNear = count (nearestObjects [player, dayz_fuelsources, _distance]);
  83.             if(_isNear == 0) then {
  84.                 _abort = true;
  85.                 _reason = "fuel tank";
  86.             };
  87.         };
  88.     };
  89. } forEach _needNear;
  90.  
  91.  
  92. if(_abort) exitWith {
  93.     cutText [format[(localize "str_epoch_player_135"),_reason,_distance], "PLAIN DOWN"];
  94.     DZE_ActionInProgress = false;
  95. };
  96.  
  97. _classname =    getText (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "create");
  98. _classnametmp = _classname;
  99. _require =  getArray (configFile >> "cfgMagazines" >> _this >> "ItemActions" >> "Build" >> "require");
  100. _text =         getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  101. _ghost = getText (configFile >> "CfgVehicles" >> _classname >> "ghostpreview");
  102.  
  103. _lockable = 0;
  104. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "lockable")) then {
  105.     _lockable = getNumber(configFile >> "CfgVehicles" >> _classname >> "lockable");
  106. };
  107.  
  108. _requireplot = DZE_requireplot;
  109. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "requireplot")) then {
  110.     _requireplot = getNumber(configFile >> "CfgVehicles" >> _classname >> "requireplot");
  111. };
  112.  
  113. _isAllowedUnderGround = 1;
  114. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "nounderground")) then {
  115.     _isAllowedUnderGround = getNumber(configFile >> "CfgVehicles" >> _classname >> "nounderground");
  116. };
  117.  
  118. _offset =   getArray (configFile >> "CfgVehicles" >> _classname >> "offset");
  119. if((count _offset) <= 0) then {
  120.     _offset = [0,1.5,0];
  121. };
  122.  
  123. _isPole = (_classname == "Plastic_Pole_EP1_DZ");
  124. _isLandFireDZ = (_classname == "Land_Fire_DZ");
  125.  
  126. _distance = DZE_PlotPole select 0;
  127. _needText = localize "str_epoch_player_246";
  128.  
  129. if(_isPole) then {
  130.     _distance = DZE_PlotPole select 1;
  131. };
  132.  
  133. // check for near plot
  134. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  135. _findNearestPole = [];
  136.  
  137. {
  138.     if (alive _x) then {
  139.         _findNearestPole set [(count _findNearestPole),_x];
  140.     };
  141. } count _findNearestPoles;
  142.  
  143. _IsNearPlot = count (_findNearestPole);
  144.  
  145. // If item is plot pole && another one exists within 45m
  146. if(_isPole && _IsNearPlot > 0) exitWith {  DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"]; };
  147.  
  148. if(_IsNearPlot == 0) then {
  149.  
  150.     // Allow building of plot
  151.     if(_requireplot == 0 || _isLandFireDZ) then {
  152.         _canBuildOnPlot = true;
  153.     };
  154.  
  155. } else {
  156.     // Since there are plots nearby we check for ownership && then for friend status
  157.  
  158.     // check nearby plots ownership && then for friend status
  159.     _nearestPole = _findNearestPole select 0;
  160.  
  161.     // Find owner
  162.     _ownerID = _nearestPole getVariable ["CharacterID","0"];
  163.  
  164.     // diag_log format["DEBUG BUILDING: %1 = %2", dayz_characterID, _ownerID];
  165.  
  166.     // check if friendly to owner
  167.     if(dayz_characterID == _ownerID) then {  //Keep ownership
  168.         // owner can build anything within his plot except other plots
  169.         if(!_isPole) then {
  170.             _canBuildOnPlot = true;
  171.         };
  172.  
  173.     } else {
  174.         // disallow building plot
  175.         if(!_isPole) then {
  176.             _friendlies     = player getVariable ["friendlyTo",[]];
  177.             // check if friendly to owner
  178.             if(_ownerID in _friendlies) then {
  179.                 _canBuildOnPlot = true;
  180.             };
  181.         };
  182.     };
  183. };
  184.  
  185. // _message
  186. if(!_canBuildOnPlot) exitWith {  DZE_ActionInProgress = false; cutText [format[(localize "STR_EPOCH_PLAYER_135"),_needText,_distance] , "PLAIN DOWN"]; };
  187.  
  188. _missing = "";
  189. _hasrequireditem = true;
  190. {
  191.     _hastoolweapon = _x in weapons player;
  192.     if(!_hastoolweapon) exitWith { _hasrequireditem = false; _missing = getText (configFile >> "cfgWeapons" >> _x >> "displayName"); };
  193. } count _require;
  194.  
  195. _hasbuilditem = _this in magazines player;
  196. if (!_hasbuilditem) exitWith {DZE_ActionInProgress = false; cutText [format[(localize "str_player_31"),_text,"build"] , "PLAIN DOWN"]; };
  197.  
  198. if (!_hasrequireditem) exitWith {DZE_ActionInProgress = false; cutText [format[(localize "str_epoch_player_137"),_missing] , "PLAIN DOWN"]; };
  199. if (_hasrequireditem) then {
  200.  
  201.     _location = [0,0,0];
  202.     _isOk = true;
  203.  
  204.     // get inital players position
  205.     _location1 = getPosATL player;
  206.     _dir = getDir player;
  207.  
  208.     // if ghost preview available use that instead
  209.     if (_ghost != "") then {
  210.         _classname = _ghost;
  211.     };
  212.  
  213.     _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  214.  
  215.     _object attachTo [player,_offset];
  216.  
  217.     _position = getPosATL _object;
  218.  
  219.     cutText [(localize "str_epoch_player_45"), "PLAIN DOWN"];
  220.  
  221.     _objHDiff = 0;
  222.  
  223.     while {_isOk} do {
  224.  
  225.         _zheightchanged = false;
  226.         _zheightdirection = "";
  227.         _rotate = false;
  228.  
  229.         if (DZE_Q) then {
  230.             DZE_Q = false;
  231.             _zheightdirection = "up";
  232.             _zheightchanged = true;
  233.         };
  234.         if (DZE_Z) then {
  235.             DZE_Z = false;
  236.             _zheightdirection = "down";
  237.             _zheightchanged = true;
  238.         };
  239.         if (DZE_Q_alt) then {
  240.             DZE_Q_alt = false;
  241.             _zheightdirection = "up_alt";
  242.             _zheightchanged = true;
  243.         };
  244.         if (DZE_Z_alt) then {
  245.             DZE_Z_alt = false;
  246.             _zheightdirection = "down_alt";
  247.             _zheightchanged = true;
  248.         };
  249.         if (DZE_Q_ctrl) then {
  250.             DZE_Q_ctrl = false;
  251.             _zheightdirection = "up_ctrl";
  252.             _zheightchanged = true;
  253.         };
  254.         if (DZE_Z_ctrl) then {
  255.             DZE_Z_ctrl = false;
  256.             _zheightdirection = "down_ctrl";
  257.             _zheightchanged = true;
  258.         };
  259.         if (DZE_4) then {
  260.             _rotate = true;
  261.             DZE_4 = false;
  262.             _dir = 180;
  263.         };
  264.         if (DZE_6) then {
  265.             _rotate = true;
  266.             DZE_6 = false;
  267.             _dir = 0;
  268.         };
  269.  
  270.         if(_rotate) then {
  271.             _object setDir _dir;
  272.             _object setPosATL _position;
  273.             //diag_log format["DEBUG Rotate BUILDING POS: %1", _position];
  274.         };
  275.  
  276.         if(_zheightchanged) then {
  277.             detach _object;
  278.  
  279.             _position = getPosATL _object;
  280.  
  281.             if(_zheightdirection == "up") then {
  282.                 _position set [2,((_position select 2)+0.1)];
  283.                 _objHDiff = _objHDiff + 0.1;
  284.             };
  285.             if(_zheightdirection == "down") then {
  286.                 _position set [2,((_position select 2)-0.1)];
  287.                 _objHDiff = _objHDiff - 0.1;
  288.             };
  289.  
  290.             if(_zheightdirection == "up_alt") then {
  291.                 _position set [2,((_position select 2)+1)];
  292.                 _objHDiff = _objHDiff + 1;
  293.             };
  294.             if(_zheightdirection == "down_alt") then {
  295.                 _position set [2,((_position select 2)-1)];
  296.                 _objHDiff = _objHDiff - 1;
  297.             };
  298.  
  299.             if(_zheightdirection == "up_ctrl") then {
  300.                 _position set [2,((_position select 2)+0.01)];
  301.                 _objHDiff = _objHDiff + 0.01;
  302.             };
  303.             if(_zheightdirection == "down_ctrl") then {
  304.                 _position set [2,((_position select 2)-0.01)];
  305.                 _objHDiff = _objHDiff - 0.01;
  306.             };
  307.  
  308.             _object setDir (getDir _object);
  309.  
  310.             if((_isAllowedUnderGround == 0) && ((_position select 2) < 0)) then {
  311.                 _position set [2,0];
  312.             };
  313.  
  314.             _object setPosATL _position;
  315.  
  316.             //diag_log format["DEBUG Change BUILDING POS: %1", _position];
  317.  
  318.             _object attachTo [player];
  319.  
  320.         };
  321.  
  322.         sleep 0.5;
  323.  
  324.         _location2 = getPosATL player;
  325.  
  326.         if(DZE_5) exitWith {
  327.             _isOk = false;
  328.             detach _object;
  329.             _dir = getDir _object;
  330.             _position = getPosATL _object;
  331.             //diag_log format["DEBUG BUILDING POS: %1", _position];
  332.             deleteVehicle _object;
  333.         };
  334.  
  335.         if(_location1 distance _location2 > 5) exitWith {
  336.             _isOk = false;
  337.             _cancel = true;
  338.             _reason = "You've moved to far away from where you started building (within 5 meters)";
  339.             detach _object;
  340.             deleteVehicle _object;
  341.         };
  342.  
  343.         if(abs(_objHDiff) > 5) exitWith {
  344.             _isOk = false;
  345.             _cancel = true;
  346.             _reason = "Cannot move up || down more than 5 meters";
  347.             detach _object;
  348.             deleteVehicle _object;
  349.         };
  350.  
  351.         if (player getVariable["combattimeout", 0] >= time) exitWith {
  352.             _isOk = false;
  353.             _cancel = true;
  354.             _reason = (localize "str_epoch_player_43");
  355.             detach _object;
  356.             deleteVehicle _object;
  357.         };
  358.  
  359.         if (DZE_cancelBuilding) exitWith {
  360.             _isOk = false;
  361.             _cancel = true;
  362.             _reason = "Cancelled building.";
  363.             detach _object;
  364.             deleteVehicle _object;
  365.         };
  366.     };
  367.  
  368.     //No building on roads unless toggled
  369.     if (!DZE_BuildOnRoads) then {
  370.         if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  371.     };
  372.  
  373.     // No building in trader zones
  374.     if(!canbuild) then { _cancel = true; _reason = "Cannot build in a city."; };
  375.  
  376.     if(!_cancel) then {
  377.  
  378.         _classname = _classnametmp;
  379.  
  380.         // Start Build
  381.         _tmpbuilt = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  382.  
  383.         _tmpbuilt setdir _dir;
  384.  
  385.         // Get position based on object
  386.         _location = _position;
  387.  
  388.         if((_isAllowedUnderGround == 0) && ((_location select 2) < 0)) then {
  389.             _location set [2,0];
  390.         };
  391.  
  392.         _tmpbuilt setPosATL _location;
  393.  
  394.  
  395.         cutText [format[(localize "str_epoch_player_138"),_text], "PLAIN DOWN"];
  396.  
  397.         _limit = 3;
  398.  
  399.         if (DZE_StaticConstructionCount > 0) then {
  400.             _limit = DZE_StaticConstructionCount;
  401.         }
  402.         else {
  403.             if (isNumber (configFile >> "CfgVehicles" >> _classname >> "constructioncount")) then {
  404.                 _limit = getNumber(configFile >> "CfgVehicles" >> _classname >> "constructioncount");
  405.             };
  406.         };
  407.  
  408.         _isOk = true;
  409.         _proceed = false;
  410.         _counter = 0;
  411.  
  412.         while {_isOk} do {
  413.  
  414.             [10,10] call dayz_HungerThirst;
  415.             player playActionNow "Medic";
  416.  
  417.             _dis=20;
  418.             _sfx = "repair";
  419.             [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
  420.             [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
  421.  
  422.             r_interrupt = false;
  423.             r_doLoop = true;
  424.             _started = false;
  425.             _finished = false;
  426.  
  427.             while {r_doLoop} do {
  428.                 _animState = animationState player;
  429.                 _isMedic = ["medic",_animState] call fnc_inString;
  430.                 if (_isMedic) then {
  431.                     _started = true;
  432.                 };
  433.                 if (_started && !_isMedic) then {
  434.                     r_doLoop = false;
  435.                     _finished = true;
  436.                 };
  437.                 if (r_interrupt || (player getVariable["combattimeout", 0] >= time)) then {
  438.                     r_doLoop = false;
  439.                 };
  440.                 if (DZE_cancelBuilding) exitWith {
  441.                     r_doLoop = false;
  442.                 };
  443.                 sleep 0.1;
  444.             };
  445.             r_doLoop = false;
  446.  
  447.  
  448.             if(!_finished) exitWith {
  449.                 _isOk = false;
  450.                 _proceed = false;
  451.             };
  452.  
  453.             if(_finished) then {
  454.                 _counter = _counter + 1;
  455.             };
  456.  
  457.             cutText [format[(localize "str_epoch_player_139"),_text, _counter,_limit], "PLAIN DOWN"];
  458.  
  459.             if(_counter == _limit) exitWith {
  460.                 _isOk = false;
  461.                 _proceed = true;
  462.             };
  463.  
  464.         };
  465.  
  466.         if (_proceed) then {
  467.  
  468.             _num_removed = ([player,_item] call BIS_fnc_invRemove);
  469.             if(_num_removed == 1) then {
  470.  
  471.                 cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  472.  
  473.                 if (_isPole) then {
  474.                     [] spawn player_plotPreview;
  475.                 };
  476.  
  477.                 _tmpbuilt setVariable ["OEMPos",_location,true];
  478.  
  479.                 if(_lockable > 1) then {
  480.  
  481.                     _combinationDisplay = "";
  482.  
  483.                     switch (_lockable) do {
  484.  
  485.                         case 2: { // 2 lockbox
  486.                             _combination_1 = (floor(random 3)) + 100; // 100=red,101=green,102=blue
  487.                             _combination_2 = floor(random 10);
  488.                             _combination_3 = floor(random 10);
  489.                             _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  490.                             dayz_combination = _combination;
  491.                             if (_combination_1 == 100) then {
  492.                                 _combination_1_Display = "Red";
  493.                             };
  494.                             if (_combination_1 == 101) then {
  495.                                 _combination_1_Display = "Green";
  496.                             };
  497.                             if (_combination_1 == 102) then {
  498.                                 _combination_1_Display = "Blue";
  499.                             };
  500.                             _combinationDisplay = format["%1%2%3",_combination_1_Display,_combination_2,_combination_3];
  501.                         };
  502.  
  503.                         case 3: { // 3 combolock
  504.                             _combination_1 = floor(random 10);
  505.                             _combination_2 = floor(random 10);
  506.                             _combination_3 = floor(random 10);
  507.                             _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  508.                             dayz_combination = _combination;
  509.                             _combinationDisplay = _combination;
  510.                         };
  511.  
  512.                         case 4: { // 4 safe
  513.                             _combination_1 = floor(random 10);
  514.                             _combination_2 = floor(random 10);
  515.                             _combination_3 = floor(random 10);
  516.                             _combination_4 = floor(random 10);
  517.                             _combination = format["%1%2%3%4",_combination_1,_combination_2,_combination_3,_combination_4];
  518.                             dayz_combination = _combination;
  519.                             _combinationDisplay = _combination;
  520.                         };
  521.                     };
  522.  
  523.                     _tmpbuilt setVariable ["CharacterID",_combination,true];
  524.  
  525.  
  526.                     PVDZE_obj_Publish = [_combination,_tmpbuilt,[_dir,_location],_classname];
  527.                     publicVariableServer "PVDZE_obj_Publish";
  528.  
  529.                     cutText [format[(localize "str_epoch_player_140"),_combinationDisplay,_text], "PLAIN DOWN", 5];
  530.  
  531.  
  532.                 } else {
  533.                     _tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
  534.  
  535.                     // fire?
  536.                     if(_tmpbuilt isKindOf "Land_Fire_DZ") then {
  537.                         _tmpbuilt spawn player_fireMonitor;
  538.                     } else {
  539.                         PVDZE_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location],_classname];
  540.                         publicVariableServer "PVDZE_obj_Publish";
  541.                     };
  542.                 };
  543.             } else {
  544.                 deleteVehicle _tmpbuilt;
  545.                 cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  546.             };
  547.  
  548.         } else {
  549.             r_interrupt = false;
  550.             if (vehicle player == player) then {
  551.                 [objNull, player, rSwitchMove,""] call RE;
  552.                 player playActionNow "stop";
  553.             };
  554.  
  555.             deleteVehicle _tmpbuilt;
  556.  
  557.             cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  558.         };
  559.  
  560.     } else {
  561.         cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
  562.     };
  563. };
  564.  
  565. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement