Advertisement
jhondominic

player_build.sqf

May 26th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.89 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 ["_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.  
  7. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_40") , "PLAIN DOWN"]; };
  8. DZE_ActionInProgress = true;
  9.  
  10. // disallow building if too many objects are found within 30m
  11. if((count ((getPosATL player) nearObjects ["All",30])) >= DZE_BuildingLimit) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_41"), "PLAIN DOWN"];};
  12.  
  13. _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  14. _isWater = dayz_isSwimming;
  15. _cancel = false;
  16. _reason = "";
  17. _canBuildOnPlot = false;
  18.  
  19. _vehicle = vehicle player;
  20. _inVehicle = (_vehicle != player);
  21.  
  22. DZE_Q = false;
  23. DZE_Z = false;
  24.  
  25. DZE_Q_alt = false;
  26. DZE_Z_alt = false;
  27.  
  28. DZE_Q_ctrl = false;
  29. DZE_Z_ctrl = false;
  30.  
  31. DZE_5 = false;
  32. DZE_4 = false;
  33. DZE_6 = false;
  34.  
  35. DZE_cancelBuilding = false;
  36.  
  37. call gear_ui_init;
  38. closeDialog 1;
  39.  
  40. if (_isWater) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_26", "PLAIN DOWN"];};
  41. if (_inVehicle) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];};
  42. if (_onLadder) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_21", "PLAIN DOWN"];};
  43. if (player getVariable["combattimeout", 0] >= time) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];};
  44.  
  45. _item = _this;
  46.  
  47. // Need Near Requirements
  48. _abort = false;
  49. _reason = "";
  50.  
  51. _needNear = getArray (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "neednearby");
  52.  
  53. {
  54. switch(_x) do{
  55. case "fire":
  56. {
  57. _distance = 3;
  58. _isNear = {inflamed _x} count (getPosATL player nearObjects _distance);
  59. if(_isNear == 0) then {
  60. _abort = true;
  61. _reason = "fire";
  62. };
  63. };
  64. case "workshop":
  65. {
  66. _distance = 3;
  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. _distance = 30;
  76. _isNear = count (nearestObjects [player, dayz_fuelsources, _distance]);
  77. if(_isNear == 0) then {
  78. _abort = true;
  79. _reason = "fuel tank";
  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. } count _findNearestPoles;
  136.  
  137. _IsNearPlot = count (_findNearestPole);
  138.  
  139. // If item is plot pole && another one exists within 45m
  140. if(_isPole && _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 || _isLandFireDZ) then {
  146. _canBuildOnPlot = true;
  147. };
  148.  
  149. } else {
  150. // Since there are plots nearby we check for ownership && then for friend status
  151.  
  152. // check nearby plots ownership && 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. } count _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) && ((_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 || 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) && ((_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. r_doLoop = true;
  418. _started = false;
  419. _finished = false;
  420.  
  421. while {r_doLoop} do {
  422. _animState = animationState player;
  423. _isMedic = ["medic",_animState] call fnc_inString;
  424. if (_isMedic) then {
  425. _started = true;
  426. };
  427. if (_started && !_isMedic) then {
  428. r_doLoop = false;
  429. _finished = true;
  430. };
  431. if (r_interrupt || (player getVariable["combattimeout", 0] >= time)) then {
  432. r_doLoop = false;
  433. };
  434. if (DZE_cancelBuilding) exitWith {
  435. r_doLoop = false;
  436. };
  437. sleep 0.1;
  438. };
  439. r_doLoop = false;
  440.  
  441.  
  442. if(!_finished) exitWith {
  443. _isOk = false;
  444. _proceed = false;
  445. };
  446.  
  447. if(_finished) then {
  448. _counter = _counter + 1;
  449. };
  450.  
  451. cutText [format[(localize "str_epoch_player_139"),_text, _counter,_limit], "PLAIN DOWN"];
  452.  
  453. if(_counter == _limit) exitWith {
  454. _isOk = false;
  455. _proceed = true;
  456. };
  457.  
  458. };
  459.  
  460. if (_proceed) then {
  461.  
  462. _num_removed = ([player,_item] call BIS_fnc_invRemove);
  463. if(_num_removed == 1) then {
  464.  
  465. cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  466.  
  467. if (_isPole) then {
  468. [] spawn player_plotPreview;
  469. };
  470.  
  471. _tmpbuilt setVariable ["OEMPos",_location,true];
  472.  
  473. if(_lockable > 1) then {
  474.  
  475. _combinationDisplay = "";
  476.  
  477. switch (_lockable) do {
  478.  
  479. case 2: { // 2 lockbox
  480. _combination_1 = (floor(random 3)) + 100; // 100=red,101=green,102=blue
  481. _combination_2 = floor(random 10);
  482. _combination_3 = floor(random 10);
  483. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  484. dayz_combination = _combination;
  485. if (_combination_1 == 100) then {
  486. _combination_1_Display = "Red";
  487. };
  488. if (_combination_1 == 101) then {
  489. _combination_1_Display = "Green";
  490. };
  491. if (_combination_1 == 102) then {
  492. _combination_1_Display = "Blue";
  493. };
  494. _combinationDisplay = format["%1%2%3",_combination_1_Display,_combination_2,_combination_3];
  495. };
  496.  
  497. case 3: { // 3 combolock
  498. _combination_1 = floor(random 10);
  499. _combination_2 = floor(random 10);
  500. _combination_3 = floor(random 10);
  501. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  502. dayz_combination = _combination;
  503. _combinationDisplay = _combination;
  504. };
  505.  
  506. case 4: { // 4 safe
  507. _combination_1 = floor(random 10);
  508. _combination_2 = floor(random 10);
  509. _combination_3 = floor(random 10);
  510. _combination_4 = floor(random 10);
  511. _combination = format["%1%2%3%4",_combination_1,_combination_2,_combination_3,_combination_4];
  512. dayz_combination = _combination;
  513. _combinationDisplay = _combination;
  514. };
  515. };
  516.  
  517. _tmpbuilt setVariable ["CharacterID",_combination,true];
  518.  
  519.  
  520. PVDZE_obj_Publish = [_combination,_tmpbuilt,[_dir,_location],_classname];
  521. publicVariableServer "PVDZE_obj_Publish";
  522.  
  523. cutText [format[(localize "str_epoch_player_140"),_combinationDisplay,_text], "PLAIN DOWN", 5];
  524.  
  525.  
  526. } else {
  527. _tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
  528.  
  529. // fire?
  530. if(_tmpbuilt isKindOf "Land_Fire_DZ") then {
  531. _tmpbuilt spawn player_fireMonitor;
  532. } else {
  533. PVDZE_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location],_classname];
  534. publicVariableServer "PVDZE_obj_Publish";
  535. };
  536. };
  537. } else {
  538. deleteVehicle _tmpbuilt;
  539. cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  540. };
  541.  
  542. } else {
  543. r_interrupt = false;
  544. if (vehicle player == player) then {
  545. [objNull, player, rSwitchMove,""] call RE;
  546. player playActionNow "stop";
  547. };
  548.  
  549. deleteVehicle _tmpbuilt;
  550.  
  551. cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  552. };
  553.  
  554. } else {
  555. cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
  556. };
  557. };
  558.  
  559. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement