Advertisement
Guest User

Untitled

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