Advertisement
Guest User

Untitled

a guest
Nov 28th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.99 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. */
  6. 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","_objHdwnDiff","_needNear"];
  7.  
  8. if(TradeInprogress) exitWith { cutText ["\n\nBuilding already in progress." , "PLAIN DOWN"]; };
  9. TradeInprogress = true;
  10.  
  11. // disallow building if too many objects are found within 30m
  12. if((count ((position player) nearObjects ["All",60])) >= DZE_BuildingLimit) exitWith {TradeInprogress = false; cutText ["\n\nCannot build, too many objects witin 60m.", "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. DZE_Q = false;
  21. DZE_Z = false;
  22.  
  23. DZE_Q_alt = false;
  24. DZE_Z_alt = false;
  25.  
  26. DZE_Q_ctrl = false;
  27. DZE_Z_ctrl = false;
  28.  
  29. DZE_5 = false;
  30. DZE_4 = false;
  31. DZE_6 = false;
  32.  
  33. DZE_cancelBuilding = false;
  34.  
  35. call gear_ui_init;
  36. closeDialog 1;
  37.  
  38. if(_isWater) exitWith {TradeInprogress = false; cutText [localize "str_player_26", "PLAIN DOWN"];};
  39. if(_onLadder) exitWith {TradeInprogress = false; cutText [localize "str_player_21", "PLAIN DOWN"];};
  40. if(player getVariable["combattimeout", 0] >= time) exitWith {TradeInprogress = false; cutText ["Cannot build while in combat.", "PLAIN DOWN"];};
  41.  
  42. _item = _this;
  43.  
  44. // Need Near Requirements
  45. _abort = false;
  46. _distance = 3;
  47. _reason = "";
  48.  
  49. _needNear = getArray (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "neednearby");
  50.  
  51. {
  52. _need = _x select 0;
  53. _distance = _x select 1;
  54.  
  55. if("fire" in _need) then {
  56. _isNear = {inflamed _x} count (position player nearObjects _distance);
  57. if(_isNear == 0) then {
  58. _abort = true;
  59. _reason = "fire";
  60. };
  61. };
  62. if("workshop" in _need) then {
  63. _isNear = count (nearestObjects [player, ["Wooden_shed_DZ","WoodShack_DZ","WorkBench_DZ"], _distance]);
  64. if(_isNear == 0) then {
  65. _abort = true;
  66. _reason = "workshop";
  67. };
  68. };
  69. if("fueltank" in _need) then {
  70. _isNear = count (nearestObjects [player, dayz_fuelsources, _distance]);
  71. if(_isNear == 0) then {
  72. _abort = true;
  73. _reason = "fuel tank";
  74. };
  75. };
  76. } forEach _needNear;
  77.  
  78.  
  79. if(_abort) exitWith {
  80. cutText [format["\n\nThis building needs a %1 within %2 meters",_reason,_distance], "PLAIN DOWN"];
  81. TradeInprogress = false;
  82. };
  83.  
  84.  
  85.  
  86.  
  87. _classname = getText (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "create");
  88. _classnametmp = _classname;
  89. _require = getArray (configFile >> "cfgMagazines" >> _this >> "ItemActions" >> "Build" >> "require");
  90. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  91. _ghost = getText (configFile >> "CfgVehicles" >> _classname >> "ghostpreview");
  92.  
  93. _lockable = 0;
  94. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "lockable")) then {
  95. _lockable = getNumber(configFile >> "CfgVehicles" >> _classname >> "lockable");
  96. };
  97.  
  98. _offset = getArray (configFile >> "CfgVehicles" >> _classname >> "offset");
  99.  
  100. if((count _offset) <= 0) then {
  101. _offset = [0,1.5,0];
  102. };
  103.  
  104. _isPole = (_classname == "Plastic_Pole_EP1_DZ");
  105. _isWorkBench = (_classname == "WorkBench_DZ");
  106. _isTent = (_classname == "TentStorage");
  107. _isTentStorageDomed = (_classname == "TentStorageDomed");
  108. _isTentStorageDomed2 = (_classname == "TentStorageDomed2");
  109. _isLockboxStorageLocked = (_classname == "LockboxStorageLocked");
  110. _isGeneratorDZ = (_classname == "Generator_DZ");
  111. _isLandFireDZ = (_classname == "Land_Fire_DZ");
  112.  
  113. _distance = 60;
  114. _needText = "Plot Pole";
  115.  
  116. if(_isPole) then {
  117. _distance = 300;
  118. };
  119.  
  120. // check for near plot
  121. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  122. _findNearestPole = [];
  123.  
  124. {
  125. if (alive _x) then {
  126. _findNearestPole set [(count _findNearestPole),_x];
  127. };
  128. } foreach _findNearestPoles;
  129.  
  130. _IsNearPlot = count (_findNearestPole);
  131.  
  132. // If item is plot pole and another one exists within 300m
  133. if(_isPole and _IsNearPlot > 0) exitWith { TradeInprogress = false; cutText ["Cannot build plot pole within 300m of an existing plot." , "PLAIN DOWN"]; };
  134. //diag_log format["DEBUG BUILDING _IsNearPlot: %1", _IsNearPlot];
  135. if(_IsNearPlot == 0) then {
  136. if(_isPole or _isWorkBench or _isTent or _isTentStorageDomed or _isTentStorageDomed2 or _isGeneratorDZ or _isLockboxStorageLocked or _isLandFireDZ) then {
  137. _canBuildOnPlot = true;
  138. };
  139. } else {
  140. _nearestPole = _findNearestPole select 0;
  141. _ownerID = _nearestPole getVariable["CharacterID","0"];
  142.  
  143. if (dayz_playerUID == _ownerID) then {
  144. _canBuildOnPlot = true;
  145. } else {
  146. {
  147. if((_ownerID == getPlayerUID _x) && (isPlayer _x)) then {_ownerID = _x getVariable "CharacterID"};
  148. } forEach playableunits;
  149. _friendlies = player getVariable ["friendlyTo",[]];
  150. //diag_log format["DEBUG BUILD:(%1 IN %2)", _ownerID, _friendlies];
  151. //"DEBUG BUILD:(136186054 IN ["709"])"
  152. if(_ownerID in _friendlies) then {
  153. _canBuildOnPlot = true;
  154. };
  155. };
  156. };
  157.  
  158. // _message
  159. if(!_canBuildOnPlot) exitWith { TradeInprogress = false; cutText [format["You need a %1 nearby!",_needText] , "PLAIN DOWN"]; };
  160.  
  161. _missing = "";
  162. _hasrequireditem = true;
  163. {
  164. _hastoolweapon = _x in weapons player;
  165. if(!_hastoolweapon) exitWith { _hasrequireditem = false; _missing = _x; }
  166. } forEach _require;
  167.  
  168. _hasbuilditem = _this in magazines player;
  169. if (!_hasbuilditem) exitWith {TradeInprogress = false; cutText [format[(localize "str_player_31"),_text,"build"] , "PLAIN DOWN"]; };
  170.  
  171. if (!_hasrequireditem) exitWith {TradeInprogress = false; cutText [format["Missing tool %1",_missing] , "PLAIN DOWN"]; };
  172. if (_hasrequireditem) then {
  173.  
  174. _location = [0,0,0];
  175. _isOk = true;
  176.  
  177. // get inital players position
  178. _location1 = getPosATL player;
  179. _dir = getDir player;
  180.  
  181. // if ghost preview available use that instead
  182. if (_ghost == "") then {
  183. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  184. } else {
  185. _classname = _ghost;
  186. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  187. };
  188.  
  189. _object attachTo [player,_offset];
  190.  
  191. _position = getPosATL _object;
  192.  
  193. cutText ["Planning construction: PgUp = raise, PgDn = lower, Q or E = flip 180, and Space-Bar to build.", "PLAIN DOWN"];
  194. _previewCounter = 60;
  195. _objHupDiff = 0;
  196. _objHdwnDiff = 0;
  197.  
  198. while {_isOk} do {
  199.  
  200. _zheightchanged = false;
  201. _zheightdirection = "";
  202. _rotate = false;
  203.  
  204. if (DZE_Q) then {
  205. DZE_Q = false;
  206. _zheightdirection = "up";
  207. _zheightchanged = true;
  208. };
  209. if (DZE_Z) then {
  210. DZE_Z = false;
  211. _zheightdirection = "down";
  212. _zheightchanged = true;
  213. };
  214.  
  215.  
  216. if (DZE_Q_alt) then {
  217. DZE_Q_alt = false;
  218. _zheightdirection = "up_alt";
  219. _zheightchanged = true;
  220. };
  221. if (DZE_Z_alt) then {
  222. DZE_Z_alt = false;
  223. _zheightdirection = "down_alt";
  224. _zheightchanged = true;
  225. };
  226.  
  227.  
  228. if (DZE_Q_ctrl) then {
  229. DZE_Q_ctrl = false;
  230. _zheightdirection = "up_ctrl";
  231. _zheightchanged = true;
  232. };
  233. if (DZE_Z_ctrl) then {
  234. DZE_Z_ctrl = false;
  235. _zheightdirection = "down_ctrl";
  236. _zheightchanged = true;
  237. };
  238.  
  239. if (DZE_4) then {
  240. _rotate = true;
  241. DZE_4 = false;
  242. _dir = 180;
  243. };
  244. if (DZE_6) then {
  245. _rotate = true;
  246. DZE_6 = false;
  247. _dir = 0;
  248. };
  249.  
  250. if(_rotate) then {
  251. _object setDir _dir;
  252. _object setPosATL _position;
  253. diag_log format["DEBUG Rotate BUILDING POS: %1", _position];
  254. };
  255.  
  256. if(_zheightchanged) then {
  257. detach _object;
  258.  
  259. _position = getPosATL _object;
  260.  
  261. if(_zheightdirection == "up") then {
  262. _position set [2,((_position select 2)+0.1)];
  263. _objHupDiff = _objHupDiff + 0.1;
  264. _objHdwnDiff = _objHdwnDiff - 0.1;
  265. };
  266. if(_zheightdirection == "down") then {
  267. _position set [2,((_position select 2)-0.1)];
  268. _objHdwnDiff = _objHdwnDiff + 0.1;
  269. _objHupDiff = _objHupDiff - 0.1;
  270. };
  271.  
  272. if(_zheightdirection == "up_alt") then {
  273. _position set [2,((_position select 2)+1)];
  274. _objHupDiff = _objHupDiff + 1;
  275. _objHdwnDiff = _objHdwnDiff - 1;
  276. };
  277. if(_zheightdirection == "down_alt") then {
  278. _position set [2,((_position select 2)-1)];
  279. _objHdwnDiff = _objHdwnDiff + 1;
  280. _objHupDiff = _objHupDiff - 1;
  281. };
  282.  
  283. if(_zheightdirection == "up_ctrl") then {
  284. _position set [2,((_position select 2)+0.01)];
  285. _objHupDiff = _objHupDiff + 0.01;
  286. _objHdwnDiff = _objHdwnDiff - 0.01;
  287. };
  288. if(_zheightdirection == "down_ctrl") then {
  289. _position set [2,((_position select 2)-0.01)];
  290. _objHdwnDiff = _objHdwnDiff + 0.01;
  291. _objHupDiff = _objHupDiff - 0.01;
  292. };
  293.  
  294. _object setDir (getDir _object);
  295.  
  296. _object setPosATL _position;
  297.  
  298. diag_log format["DEBUG Change BUILDING POS: %1", _position];
  299.  
  300. _object attachTo [player];
  301.  
  302. };
  303.  
  304. sleep 1;
  305.  
  306. _location2 = getPosATL player;
  307.  
  308. if(DZE_5) exitWith {
  309. _isOk = false;
  310. detach _object;
  311. _dir = getDir _object;
  312. _position = getPosATL _object;
  313. diag_log format["DEBUG BUILDING POS: %1", _position];
  314. deleteVehicle _object;
  315. };
  316.  
  317. if(_location1 distance _location2 > 5) exitWith {
  318. _isOk = false;
  319. _cancel = true;
  320. _reason = "Moving too fast.";
  321. detach _object;
  322. deleteVehicle _object;
  323. };
  324.  
  325. cutText [format["%1",_previewCounter], "PLAIN DOWN"];
  326.  
  327. if(_previewCounter <= 0) exitWith {
  328. _isOk = false;
  329. _cancel = true;
  330. _reason = "Ran out of time to find position.";
  331. detach _object;
  332. deleteVehicle _object;
  333. };
  334.  
  335. _previewCounter = _previewCounter - 1;
  336.  
  337. if((_objHdwnDiff > 5) or (_objHupDiff > 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 = "Cannot build while in combat.";
  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
  363. if (isOnRoad _location) then { _cancel = true; _reason = "Cannot build on a road."; };
  364.  
  365. // No building in trader zones
  366. if(!canbuild) then { _cancel = true; _reason = "Cannot build in a city."; };
  367. if(!placevault) then { _cancel = true; _reason = "Cannot build in a city."; };
  368.  
  369. if(!_cancel) then {
  370.  
  371. _classname = _classnametmp;
  372.  
  373. // Start Build
  374. _tmpbuilt = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  375. // ### [CPC] Indestructible Base Fix
  376. _tmpbuilt addEventHandler ["HandleDamage", {false}];
  377. _tmpbuilt enableSimulation false;
  378. // ### [CPC] Indestructible Base Fix
  379.  
  380. _tmpbuilt setdir _dir;
  381.  
  382. // Get position based on object
  383. _location = _position;
  384.  
  385. _tmpbuilt setPosATL _location;
  386.  
  387.  
  388. cutText [format["Placing %1, move to cancel.",_text], "PLAIN DOWN"];
  389.  
  390. _limit = 3;
  391.  
  392. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "constructioncount")) then {
  393. _limit = getNumber(configFile >> "CfgVehicles" >> _classname >> "constructioncount");
  394. };
  395.  
  396. _isOk = true;
  397. _proceed = false;
  398. _counter = 0;
  399.  
  400. while {_isOk} do {
  401.  
  402. player playActionNow "Medic";
  403.  
  404. _dis=20;
  405. _sfx = "repair";
  406. [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
  407. [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
  408.  
  409. r_interrupt = false;
  410. _animState = animationState player;
  411. r_doLoop = true;
  412. _started = false;
  413. _finished = false;
  414.  
  415. while {r_doLoop} do {
  416. _animState = animationState player;
  417. _isMedic = ["medic",_animState] call fnc_inString;
  418. if (_isMedic) then {
  419. _started = true;
  420. };
  421. if (_started and !_isMedic) then {
  422. r_doLoop = false;
  423. _finished = true;
  424. };
  425. if (r_interrupt) then {
  426. r_doLoop = false;
  427. };
  428. if (DZE_cancelBuilding) exitWith {
  429. r_doLoop = false;
  430. };
  431. sleep 0.1;
  432. };
  433. r_doLoop = false;
  434.  
  435.  
  436. if(!_finished) exitWith {
  437. _isOk = false;
  438. _proceed = false;
  439. };
  440.  
  441. if(_finished) then {
  442. _counter = _counter + 1;
  443. };
  444.  
  445. cutText [format["Constructing %1 stage %2 of %3, move to cancel.",_text, _counter,_limit], "PLAIN DOWN"];
  446.  
  447. if(_counter == _limit) exitWith {
  448. _isOk = false;
  449. _proceed = true;
  450. };
  451.  
  452. };
  453.  
  454. if (_proceed) then {
  455.  
  456. _num_removed = ([player,_item] call BIS_fnc_invRemove);
  457. _tmpbuilt allowDamage false;
  458. diag_log format["Add while Building a Godmode for Obj: %1", _tmpbuilt];
  459. if(_num_removed == 1) then {
  460.  
  461. cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  462.  
  463. _tmpbuilt setVariable ["OEMPos",_location,true];
  464.  
  465. if(_lockable > 1) then {
  466.  
  467. _combinationDisplay = "";
  468.  
  469. switch (_lockable) do {
  470.  
  471. case 2: { // 2 lockbox
  472. _combination_1 = (floor(random 3)) + 100; // 100=red,101=green,102=blue
  473. _combination_2 = floor(random 10);
  474. _combination_3 = floor(random 10);
  475. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  476.  
  477. if (_combination_1 == 100) then {
  478. _combination_1_Display = "Red";
  479. };
  480. if (_combination_1 == 101) then {
  481. _combination_1_Display = "Green";
  482. };
  483. if (_combination_1 == 102) then {
  484. _combination_1_Display = "Blue";
  485. };
  486. _combinationDisplay = format["%1%2%3",_combination_1_Display,_combination_2,_combination_3];
  487. };
  488.  
  489. case 3: { // 3 combolock
  490. _combination_1 = floor(random 10);
  491. _combination_2 = floor(random 10);
  492. _combination_3 = floor(random 10);
  493. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  494. _combinationDisplay = _combination;
  495. };
  496.  
  497. case 4: { // 4 safe
  498. _combination_1 = floor(random 10);
  499. _combination_2 = floor(random 10);
  500. _combination_3 = floor(random 10);
  501. _combination_4 = floor(random 10);
  502. _combination = format["%1%2%3%4",_combination_1,_combination_2,_combination_3,_combination_4];
  503. _combinationDisplay = _combination;
  504. };
  505. };
  506.  
  507. _tmpbuilt setVariable ["CharacterID",_combination,true];
  508.  
  509.  
  510. PVDZE_obj_Publish = [_combination,_tmpbuilt,[_dir,_location],_classname];
  511. publicVariableServer "PVDZE_obj_Publish";
  512.  
  513. cutText [format["You have setup your %2. Combination is %1",_combinationDisplay,_text], "PLAIN DOWN", 5];
  514.  
  515.  
  516. } else {
  517. _tmpbuilt setVariable ["CharacterID",dayz_playerUID,true];
  518.  
  519. // fire?
  520. if(_tmpbuilt isKindOf "Land_Fire") then {
  521. _tmpbuilt spawn player_fireMonitor;
  522. } else {
  523. PVDZE_obj_Publish = [dayz_playerUID,_tmpbuilt,[_dir,_location],_classname];
  524. publicVariableServer "PVDZE_obj_Publish";
  525. };
  526. };
  527.  
  528.  
  529. } else {
  530. deleteVehicle _tmpbuilt;
  531. cutText ["Canceled building." , "PLAIN DOWN"];
  532. };
  533.  
  534. } else {
  535. r_interrupt = false;
  536. if (vehicle player == player) then {
  537. [objNull, player, rSwitchMove,""] call RE;
  538. player playActionNow "stop";
  539. };
  540.  
  541. deleteVehicle _tmpbuilt;
  542.  
  543. cutText ["Canceled building." , "PLAIN DOWN"];
  544. };
  545.  
  546. } else {
  547. deleteVehicle _tmpbuilt;
  548. cutText [format["Canceled construction of %1 %2.",_text,_reason], "PLAIN DOWN"];
  549. };
  550. };
  551.  
  552. TradeInprogress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement