Advertisement
Guest User

Untitled

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