Advertisement
Guest User

Untitled

a guest
Dec 20th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.34 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","_objHupDiff","_needNear","_vehicle","_inVehicle","_previewCounter","_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 ((position 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. _distance = 3;
  50. _reason = "";
  51.  
  52. _needNear = getArray (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "neednearby");
  53.  
  54. {
  55. _need = _x select 0;
  56. _distance = _x select 1;
  57. switch(_need) do{
  58. case "fire":
  59. {
  60. _isNear = {inflamed _x} count (position player nearObjects _distance);
  61. if(_isNear == 0) then {
  62. _abort = true;
  63. _reason = "fire";
  64. };
  65. };
  66. case "workshop":
  67. {
  68. _isNear = count (nearestObjects [player, ["Wooden_shed_DZ","WoodShack_DZ","WorkBench_DZ"], _distance]);
  69. if(_isNear == 0) then {
  70. _abort = true;
  71. _reason = "workshop";
  72. };
  73. };
  74. case "fueltank":
  75. {
  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 = 0;
  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 = 30;
  121. _needText = localize "str_epoch_player_246";
  122.  
  123. if(_isPole) then {
  124. _distance = 60;
  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. _previewCounter = 60;
  216. _objHDiff = 0;
  217.  
  218. while {_isOk} do {
  219.  
  220. _zheightchanged = false;
  221. _zheightdirection = "";
  222. _rotate = false;
  223.  
  224. if (DZE_Q) then {
  225. DZE_Q = false;
  226. _zheightdirection = "up";
  227. _zheightchanged = true;
  228. };
  229. if (DZE_Z) then {
  230. DZE_Z = false;
  231. _zheightdirection = "down";
  232. _zheightchanged = true;
  233. };
  234. if (DZE_Q_alt) then {
  235. DZE_Q_alt = false;
  236. _zheightdirection = "up_alt";
  237. _zheightchanged = true;
  238. };
  239. if (DZE_Z_alt) then {
  240. DZE_Z_alt = false;
  241. _zheightdirection = "down_alt";
  242. _zheightchanged = true;
  243. };
  244. if (DZE_Q_ctrl) then {
  245. DZE_Q_ctrl = false;
  246. _zheightdirection = "up_ctrl";
  247. _zheightchanged = true;
  248. };
  249. if (DZE_Z_ctrl) then {
  250. DZE_Z_ctrl = false;
  251. _zheightdirection = "down_ctrl";
  252. _zheightchanged = true;
  253. };
  254. if (DZE_4) then {
  255. _rotate = true;
  256. DZE_4 = false;
  257. _dir = 180;
  258. };
  259. if (DZE_6) then {
  260. _rotate = true;
  261. DZE_6 = false;
  262. _dir = 0;
  263. };
  264.  
  265. if(_rotate) then {
  266. _object setDir _dir;
  267. _object setPosATL _position;
  268. //diag_log format["DEBUG Rotate BUILDING POS: %1", _position];
  269. };
  270.  
  271. if(_zheightchanged) then {
  272. detach _object;
  273.  
  274. _position = getPosATL _object;
  275.  
  276. if(_zheightdirection == "up") then {
  277. _position set [2,((_position select 2)+0.1)];
  278. _objHDiff = _objHDiff + 0.1;
  279. };
  280. if(_zheightdirection == "down") then {
  281. _position set [2,((_position select 2)-0.1)];
  282. _objHDiff = _objHDiff - 0.1;
  283. };
  284.  
  285. if(_zheightdirection == "up_alt") then {
  286. _position set [2,((_position select 2)+1)];
  287. _objHupDiff = _objHupDiff + 1;
  288. };
  289. if(_zheightdirection == "down_alt") then {
  290. _position set [2,((_position select 2)-1)];
  291. _objHDiff = _objHDiff - 1;
  292. };
  293.  
  294. if(_zheightdirection == "up_ctrl") then {
  295. _position set [2,((_position select 2)+0.01)];
  296. _objHupDiff = _objHupDiff + 0.01;
  297. };
  298. if(_zheightdirection == "down_ctrl") then {
  299. _position set [2,((_position select 2)-0.01)];
  300. _objHDiff = _objHDiff - 0.01;
  301. };
  302.  
  303. _object setDir (getDir _object);
  304.  
  305. if((_isAllowedUnderGround == 0) and ((_position select 2) < 0)) then {
  306. _position set [2,0];
  307. };
  308.  
  309. _object setPosATL _position;
  310.  
  311. //diag_log format["DEBUG Change BUILDING POS: %1", _position];
  312.  
  313. _object attachTo [player];
  314.  
  315. };
  316.  
  317. sleep 0.5;
  318.  
  319. _location2 = getPosATL player;
  320.  
  321. if(DZE_5) exitWith {
  322. _isOk = false;
  323. detach _object;
  324. _dir = getDir _object;
  325. _position = getPosATL _object;
  326. //diag_log format["DEBUG BUILDING POS: %1", _position];
  327. deleteVehicle _object;
  328. };
  329.  
  330. if(_location1 distance _location2 > 5) exitWith {
  331. _isOk = false;
  332. _cancel = true;
  333. _reason = "You've moved to far away from where you started building (within 5 meters)";
  334. detach _object;
  335. deleteVehicle _object;
  336. };
  337.  
  338. [format["<t size='0.6'>Time left to build: %1</t>",(ceil(_previewCounter))],0,0.8,0.5,0,0,8] spawn BIS_fnc_dynamicText;
  339.  
  340. if(_previewCounter <= 0) exitWith {
  341. _isOk = false;
  342. _cancel = true;
  343. _reason = "Ran out of time to find position";
  344. detach _object;
  345. deleteVehicle _object;
  346. };
  347.  
  348. _previewCounter = _previewCounter - 0.5;
  349.  
  350. if(abs(_objHDiff) > 5) exitWith {
  351. _isOk = false;
  352. _cancel = true;
  353. _reason = "Cannot move up or down more than 5 meters";
  354. detach _object;
  355. deleteVehicle _object;
  356. };
  357.  
  358. if (player getVariable["combattimeout", 0] >= time) exitWith {
  359. _isOk = false;
  360. _cancel = true;
  361. _reason = (localize "str_epoch_player_43");
  362. detach _object;
  363. deleteVehicle _object;
  364. };
  365.  
  366. if (DZE_cancelBuilding) exitWith {
  367. _isOk = false;
  368. _cancel = true;
  369. _reason = "Cancelled building.";
  370. detach _object;
  371. deleteVehicle _object;
  372. };
  373. };
  374.  
  375. // No building on roads
  376. if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  377.  
  378. // No building in trader zones
  379. if(!canbuild) then { _cancel = true; _reason = "Cannot build in a city."; };
  380. if(!placevault) then { _cancel = true; _reason = "Cannot build in a city."; };
  381.  
  382. if(!_cancel) then {
  383.  
  384. _classname = _classnametmp;
  385.  
  386. // Start Build
  387. _tmpbuilt = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  388. // ### [CPC] Indestructible Base Fix
  389. _tmpbuilt addEventHandler ["HandleDamage", {false}];
  390. _tmpbuilt enableSimulation false;
  391. // ### [CPC] Indestructible Base Fix
  392. _tmpbuilt setdir _dir;
  393.  
  394. // Get position based on object
  395. _location = _position;
  396.  
  397. if((_isAllowedUnderGround == 0) and ((_location select 2) < 0)) then {
  398. _location set [2,0];
  399. };
  400.  
  401. _tmpbuilt setPosATL _location;
  402.  
  403.  
  404. cutText [format[(localize "str_epoch_player_138"),_text], "PLAIN DOWN"];
  405.  
  406. _limit = 3;
  407.  
  408. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "constructioncount")) then {
  409. _limit = getNumber(configFile >> "CfgVehicles" >> _classname >> "constructioncount");
  410. };
  411.  
  412. _isOk = true;
  413. _proceed = false;
  414. _counter = 0;
  415.  
  416. while {_isOk} do {
  417.  
  418. [10,10] call dayz_HungerThirst;
  419. player playActionNow "Medic";
  420.  
  421. _dis=20;
  422. _sfx = "repair";
  423. [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
  424. [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
  425.  
  426. r_interrupt = false;
  427. _animState = animationState player;
  428. r_doLoop = true;
  429. _started = false;
  430. _finished = false;
  431.  
  432. while {r_doLoop} do {
  433. _animState = animationState player;
  434. _isMedic = ["medic",_animState] call fnc_inString;
  435. if (_isMedic) then {
  436. _started = true;
  437. };
  438. if (_started and !_isMedic) then {
  439. r_doLoop = false;
  440. _finished = true;
  441. };
  442. if (r_interrupt or (player getVariable["combattimeout", 0] >= time)) then {
  443. r_doLoop = false;
  444. };
  445. if (DZE_cancelBuilding) exitWith {
  446. r_doLoop = false;
  447. };
  448. sleep 0.1;
  449. };
  450. r_doLoop = false;
  451.  
  452.  
  453. if(!_finished) exitWith {
  454. _isOk = false;
  455. _proceed = false;
  456. };
  457.  
  458. if(_finished) then {
  459. _counter = _counter + 1;
  460. };
  461.  
  462. cutText [format[(localize "str_epoch_player_139"),_text, _counter,_limit], "PLAIN DOWN"];
  463.  
  464. if(_counter == _limit) exitWith {
  465. _isOk = false;
  466. _proceed = true;
  467. };
  468.  
  469. };
  470.  
  471. if (_proceed) then {
  472.  
  473. _num_removed = ([player,_item] call BIS_fnc_invRemove);
  474. if(_num_removed == 1) then {
  475.  
  476. cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  477.  
  478. _tmpbuilt setVariable ["OEMPos",_location,true];
  479.  
  480. if(_lockable > 1) then {
  481.  
  482. _combinationDisplay = "";
  483.  
  484. switch (_lockable) do {
  485.  
  486. case 2: { // 2 lockbox
  487. _combination_1 = (floor(random 3)) + 100; // 100=red,101=green,102=blue
  488. _combination_2 = floor(random 10);
  489. _combination_3 = floor(random 10);
  490. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  491.  
  492. if (_combination_1 == 100) then {
  493. _combination_1_Display = "Red";
  494. };
  495. if (_combination_1 == 101) then {
  496. _combination_1_Display = "Green";
  497. };
  498. if (_combination_1 == 102) then {
  499. _combination_1_Display = "Blue";
  500. };
  501. _combinationDisplay = format["%1%2%3",_combination_1_Display,_combination_2,_combination_3];
  502. };
  503.  
  504. case 3: { // 3 combolock
  505. _combination_1 = floor(random 10);
  506. _combination_2 = floor(random 10);
  507. _combination_3 = floor(random 10);
  508. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  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. _combinationDisplay = _combination;
  519. };
  520. };
  521.  
  522. _tmpbuilt setVariable ["CharacterID",_combination,true];
  523.  
  524.  
  525. PVDZE_obj_Publish = [_combination,_tmpbuilt,[_dir,_location],_classname];
  526. publicVariableServer "PVDZE_obj_Publish";
  527.  
  528. cutText [format[(localize "str_epoch_player_140"),_combinationDisplay,_text], "PLAIN DOWN", 5];
  529.  
  530.  
  531. } else {
  532. _tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
  533.  
  534. // fire?
  535. if(_tmpbuilt isKindOf "Land_Fire_DZ") then {
  536. _tmpbuilt spawn player_fireMonitor;
  537. } else {
  538. PVDZE_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location],_classname];
  539. publicVariableServer "PVDZE_obj_Publish";
  540. };
  541. };
  542.  
  543.  
  544. } else {
  545. deleteVehicle _tmpbuilt;
  546. cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  547. };
  548.  
  549. } else {
  550. r_interrupt = false;
  551. if (vehicle player == player) then {
  552. [objNull, player, rSwitchMove,""] call RE;
  553. player playActionNow "stop";
  554. };
  555.  
  556. deleteVehicle _tmpbuilt;
  557.  
  558. cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  559. };
  560.  
  561. } else {
  562. deleteVehicle _tmpbuilt;
  563. cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
  564. };
  565. };
  566.  
  567. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement