MGT

Epoch 1.0.4.2 player_build.sqf building height restriction

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