Advertisement
Guest User

player_build.sqf

a guest
May 14th, 2018
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.46 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","_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","_charID","_name","_objectID","_objectUID","_playerUID","_playerName","_combination","_playerID"];
  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. _crate = (_this select 3 select 0);
  46. _houselevel = (_this select 3 select 1);
  47. _classname = (_this select 3 select 2);
  48. _neededMaterials = (_this select 3 select 3);
  49. _name = (_this select 3 select 4);
  50. _charID = dayz_characterID;
  51. _playerUID = dayz_playerUID;
  52. _playerName = (name player);
  53. [1] call origins_removeActions;
  54.  
  55. _proceed = [_crate,_neededMaterials] call origins_checkNeededMaterial;
  56. if(!_proceed) exitWith{DZE_ActionInProgress = false;};
  57.  
  58. // Need Near Requirements
  59. _abort = false;
  60. _reason = "";
  61.  
  62. _classnametmp = _classname;
  63.  
  64. _requireplot = DZE_requireplot;
  65. _isAllowedUnderGround = 0;
  66. if(_classname in DZE_Origins_Stronghold) then {
  67. _offset = [0,30,0];
  68. } else {
  69. _offset = [0,10,0];
  70. };
  71. _isPole = (_classname == "Plastic_Pole_EP1_DZ");
  72. _isLandFireDZ = (_classname == "Land_Fire_DZ");
  73.  
  74. _distance = DZE_PlotPole select 0;
  75. _needText = localize "str_epoch_player_246";
  76.  
  77. if(_isPole) then {
  78. _distance = DZE_PlotPole select 1;
  79. };
  80.  
  81. // check for near plot
  82. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  83. _findNearestPole = [];
  84.  
  85. {
  86. if (alive _x) then {
  87. _findNearestPole set [(count _findNearestPole),_x];
  88. };
  89. } count _findNearestPoles;
  90.  
  91. _IsNearPlot = count (_findNearestPole);
  92.  
  93. // If item is plot pole && another one exists within 45m
  94. if(_isPole && _IsNearPlot > 0) exitWith { DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_44") , "PLAIN DOWN"]; };
  95.  
  96. if(_IsNearPlot == 0) then {
  97. // Allow building of plot
  98. if(_requireplot == 0 || _isLandFireDZ) then {
  99. _canBuildOnPlot = true;
  100. };
  101. } else {
  102. // check nearby plots ownership && then for friend status
  103. _nearestPole = _findNearestPole select 0;
  104.  
  105. // Find owner
  106. _hasAccess = false;
  107. _hasAccess = [player, _nearestPole] call FNC_check_access;
  108. _allowed = ((_hasAccess select 0) or (_hasAccess select 2) or (_hasAccess select 3) or (_hasAccess select 4));
  109. // 0= owner + 2= plot owner + 3= plot friends + 4=plot admins
  110. if(_allowed) then { //Keep ownership
  111. // owner can build anything within his plot except other plots
  112. _canBuildOnPlot = true; // 0= owner + 2= plot owner + 3= plot friends + 4=plot admins -> can build
  113. };
  114. // check if friendly to owner
  115. if(_playerID == _ownerID) then { //Keep ownership
  116. // owner can build anything within his plot except other plots
  117. if(!_isPole) then {
  118. _canBuildOnPlot = true;
  119. };
  120. } else {
  121. // disallow building plot
  122. if(!_isPole) then {
  123. _friendlies = player getVariable ["friendlyTo",[]];
  124. // check if friendly to owner
  125. if(_ownerID in _friendlies) then {
  126. _canBuildOnPlot = true;
  127. };
  128. };
  129. };
  130. };
  131.  
  132. // _message
  133. if(!_canBuildOnPlot) exitWith { DZE_ActionInProgress = false; cutText [format[(localize "STR_EPOCH_PLAYER_135"),_needText,_distance] , "PLAIN DOWN"]; };
  134.  
  135. _require = DZE_Origins_Build_Tools_Require;
  136. _missing = "";
  137. _hasrequireditem = true;
  138. {
  139. _hastoolweapon = _x in weapons player;
  140. if(!_hastoolweapon) exitWith { _hasrequireditem = false; _missing = getText (configFile >> "cfgWeapons" >> _x >> "displayName"); };
  141. } count _require;
  142.  
  143. if (!_hasrequireditem) exitWith {DZE_ActionInProgress = false; cutText [format[(localize "str_epoch_player_137"),_missing] , "PLAIN DOWN"]; };
  144. if (_hasrequireditem) then {
  145. _location = [0,0,0];
  146. _isOk = true;
  147.  
  148. // get inital players position
  149. _location1 = getPosATL player;
  150. _dir = getDir player;
  151.  
  152. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  153. _object attachTo [player,_offset];
  154. _position = getPosATL _object;
  155. cutText [(localize "str_epoch_player_45"), "PLAIN DOWN"];
  156. _objHDiff = 0;
  157.  
  158. while {_isOk} do {
  159.  
  160. _zheightchanged = false;
  161. _zheightdirection = "";
  162. _rotate = false;
  163.  
  164. if (DZE_Q) then {
  165. DZE_Q = false;
  166. _zheightdirection = "up";
  167. _zheightchanged = true;
  168. };
  169. if (DZE_Z) then {
  170. DZE_Z = false;
  171. _zheightdirection = "down";
  172. _zheightchanged = true;
  173. };
  174. if (DZE_Q_alt) then {
  175. DZE_Q_alt = false;
  176. _zheightdirection = "up_alt";
  177. _zheightchanged = true;
  178. };
  179. if (DZE_Z_alt) then {
  180. DZE_Z_alt = false;
  181. _zheightdirection = "down_alt";
  182. _zheightchanged = true;
  183. };
  184. if (DZE_Q_ctrl) then {
  185. DZE_Q_ctrl = false;
  186. _zheightdirection = "up_ctrl";
  187. _zheightchanged = true;
  188. };
  189. if (DZE_Z_ctrl) then {
  190. DZE_Z_ctrl = false;
  191. _zheightdirection = "down_ctrl";
  192. _zheightchanged = true;
  193. };
  194. if (DZE_4) then {
  195. _rotate = true;
  196. DZE_4 = false;
  197. _dir = 180;
  198. };
  199. if (DZE_6) then {
  200. _rotate = true;
  201. DZE_6 = false;
  202. _dir = 0;
  203. };
  204.  
  205. if(_rotate) then {
  206. _object setDir _dir;
  207. _object setPosATL _position;
  208. //diag_log format["DEBUG Rotate BUILDING POS: %1", _position];
  209. };
  210.  
  211. if(_zheightchanged) then {
  212. detach _object;
  213.  
  214. _position = getPosATL _object;
  215.  
  216. if(_zheightdirection == "up") then {
  217. _position set [2,((_position select 2)+0.1)];
  218. _objHDiff = _objHDiff + 0.1;
  219. };
  220. if(_zheightdirection == "down") then {
  221. _position set [2,((_position select 2)-0.1)];
  222. _objHDiff = _objHDiff - 0.1;
  223. };
  224.  
  225. if(_zheightdirection == "up_alt") then {
  226. _position set [2,((_position select 2)+1)];
  227. _objHDiff = _objHDiff + 1;
  228. };
  229. if(_zheightdirection == "down_alt") then {
  230. _position set [2,((_position select 2)-1)];
  231. _objHDiff = _objHDiff - 1;
  232. };
  233.  
  234. if(_zheightdirection == "up_ctrl") then {
  235. _position set [2,((_position select 2)+0.01)];
  236. _objHDiff = _objHDiff + 0.01;
  237. };
  238. if(_zheightdirection == "down_ctrl") then {
  239. _position set [2,((_position select 2)-0.01)];
  240. _objHDiff = _objHDiff - 0.01;
  241. };
  242.  
  243. _object setDir (getDir _object);
  244.  
  245. if((_isAllowedUnderGround == 0) && ((_position select 2) < 0)) then {
  246. _position set [2,0];
  247. };
  248.  
  249. _object setPosATL _position;
  250.  
  251. //diag_log format["DEBUG Change BUILDING POS: %1", _position];
  252.  
  253. _object attachTo [player];
  254.  
  255. };
  256.  
  257. sleep 0.5;
  258.  
  259. _location2 = getPosATL player;
  260.  
  261. if(DZE_5) exitWith {
  262. _isOk = false;
  263. detach _object;
  264. _dir = getDir _object;
  265. _position = getPosATL _object;
  266. //diag_log format["DEBUG BUILDING POS: %1", _position];
  267. deleteVehicle _object;
  268. };
  269.  
  270. if(_location1 distance _location2 > 5) exitWith {
  271. _isOk = false;
  272. _cancel = true;
  273. _reason = "You've moved to far away from where you started building (within 5 meters)";
  274. detach _object;
  275. deleteVehicle _object;
  276. };
  277.  
  278. if(abs(_objHDiff) > 5) exitWith {
  279. _isOk = false;
  280. _cancel = true;
  281. _reason = "Cannot move up || down more than 5 meters";
  282. detach _object;
  283. deleteVehicle _object;
  284. };
  285.  
  286. if (player getVariable["combattimeout", 0] >= time) exitWith {
  287. _isOk = false;
  288. _cancel = true;
  289. _reason = (localize "str_epoch_player_43");
  290. detach _object;
  291. deleteVehicle _object;
  292. };
  293.  
  294. if (DZE_cancelBuilding) exitWith {
  295. _isOk = false;
  296. _cancel = true;
  297. _reason = "Cancelled building.";
  298. detach _object;
  299. deleteVehicle _object;
  300. };
  301. };
  302.  
  303. //No building on roads unless toggled
  304. if (!DZE_BuildOnRoads) then {
  305. if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  306. };
  307.  
  308. // No building in trader zones
  309. if(!canbuild) then { _cancel = true; _reason = "Cannot build in a city."; };
  310.  
  311. if(!_cancel) then {
  312.  
  313. _classname = _classnametmp;
  314.  
  315. // Start Build
  316. _tmpbuilt = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  317.  
  318. _tmpbuilt setdir _dir;
  319.  
  320. // Get position based on object
  321. _location = _position;
  322.  
  323. if((_isAllowedUnderGround == 0) && ((_location select 2) < 0)) then {
  324. _location set [2,0];
  325. };
  326.  
  327. _tmpbuilt setPosATL _location;
  328. if((_location select 2) < 0.25) then {
  329. _tmpbuilt setVectorUp surfaceNormal position _tmpbuilt;
  330. };
  331. _location = getPosATL _tmpbuilt;
  332.  
  333. cutText [format[(localize "str_epoch_player_138"),_name], "PLAIN DOWN"];
  334.  
  335. _limit = 3;
  336.  
  337. if (DZE_StaticConstructionCount > 0) then {
  338. _limit = DZE_StaticConstructionCount;
  339. }
  340. else {
  341. if (isNumber (configFile >> "CfgVehicles" >> _classname >> "constructioncount")) then {
  342. _limit = getNumber(configFile >> "CfgVehicles" >> _classname >> "constructioncount");
  343. };
  344. };
  345.  
  346. _isOk = true;
  347. _proceed = false;
  348. _counter = 0;
  349.  
  350. while {_isOk} do {
  351.  
  352. [10,10] call dayz_HungerThirst;
  353. player playActionNow "Medic";
  354.  
  355. _dis=20;
  356. _sfx = "repair";
  357. [player,_sfx,0,false,_dis] call dayz_zombieSpeak;
  358. [player,_dis,true,(getPosATL player)] spawn player_alertZombies;
  359.  
  360. r_interrupt = false;
  361. r_doLoop = true;
  362. _started = false;
  363. _finished = false;
  364.  
  365. while {r_doLoop} do {
  366. _animState = animationState player;
  367. _isMedic = ["medic",_animState] call fnc_inString;
  368. if (_isMedic) then {
  369. _started = true;
  370. };
  371. if (_started && !_isMedic) then {
  372. r_doLoop = false;
  373. _finished = true;
  374. };
  375. if (r_interrupt || (player getVariable["combattimeout", 0] >= time)) then {
  376. r_doLoop = false;
  377. };
  378. if (DZE_cancelBuilding) exitWith {
  379. r_doLoop = false;
  380. };
  381. sleep 0.1;
  382. };
  383. r_doLoop = false;
  384.  
  385.  
  386. if(!_finished) exitWith {
  387. _isOk = false;
  388. _proceed = false;
  389. };
  390.  
  391. if(_finished) then {
  392. _counter = _counter + 1;
  393. };
  394.  
  395. cutText [format[(localize "str_epoch_player_139"),_name, _counter,_limit], "PLAIN DOWN"];
  396.  
  397. if(_counter == _limit) exitWith {
  398. _isOk = false;
  399. _proceed = true;
  400. };
  401.  
  402. };
  403.  
  404. if (_proceed) then {
  405. cutText [format[localize "str_build_01",_name], "PLAIN DOWN"];
  406.  
  407. if (_isPole) then {
  408. [] spawn player_plotPreview;
  409. };
  410.  
  411. if(_classname in DZE_Origins_Stronghold) then {
  412. private["_combination_1","_combination_2","_combination_3","_combination_4","_combination_5","_combination_6"];
  413. _combination = "";
  414. _combination_1 = ceil(random 9);
  415. while {_combination_1 == 0} do {
  416. _combination_1 = ceil (random 9);
  417. };
  418. _combination_2 = ceil(random 9);
  419. _combination_3 = ceil(random 9);
  420. _combination_4 = ceil(random 9);
  421. _combination_5 = ceil(random 9);
  422. _combination_6 = ceil(random 9);
  423. _combination = format["%1%2%3%4%5%6",_combination_1,_combination_2,_combination_3,_combination_4,_combination_5,_combination_6];
  424. dayz_combination = _combination;
  425.  
  426. };
  427. _tmpbuilt setVariable ["OEMPos",_location,true];
  428. _tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
  429. _tmpbuilt setVariable ["OwnerUID",_playerUID, true];
  430. _tmpbuilt setVariable ["OwnerName",_playerName, true];
  431. _activatingPlayer = player;
  432.  
  433. _proceed = [_crate,_neededMaterials] call origins_checkNeededMaterial;
  434. if(_proceed) then {
  435. switch (_houselevel) do {
  436. case 'B1' : {
  437. owner_B1 set [count owner_B1, _playerUID];
  438. publicVariable "owner_B1";
  439. player setVariable["DZE_Origins_Level1",true,true];
  440. };
  441. case 'B2' : {
  442. owner_B2 set [count owner_B2, _playerUID];
  443. publicVariable "owner_B2";
  444. player setVariable["DZE_Origins_Level2",true,true];
  445. };
  446. case 'B3' : {
  447. owner_B3 set [count owner_B3, _playerUID];
  448. publicVariable "owner_B3";
  449. player setVariable["DZE_Origins_Level3",true,true];
  450. };
  451. case 'H1' : {
  452. owner_H1 set [count owner_H1, _playerUID];
  453. publicVariable "owner_H1";
  454. player setVariable["DZE_Origins_Level1",true,true];
  455. };
  456. case 'H2' : {
  457. owner_H2 set [count owner_H2, _playerUID];
  458. publicVariable "owner_H2";
  459. player setVariable["DZE_Origins_Level2",true,true];
  460. };
  461. case 'H3' : {
  462. owner_H3 set [count owner_H3, _playerUID];
  463. publicVariable "owner_H3";
  464. player setVariable["DZE_Origins_Level3",true,true];
  465. };
  466. case 'SGH';
  467. case 'SGB' : {
  468. owner_SG set [count owner_SG, _playerUID];
  469. publicVariable "owner_SG";
  470. player setVariable["DZE_Origins_SG",true,true];
  471. };
  472. case 'LGH';
  473. case 'LGB' : {
  474. owner_LG set [count owner_LG, _playerUID];
  475. publicVariable "owner_LG";
  476. player setVariable["DZE_Origins_LG",true,true];
  477. };
  478. case 'KINGH';
  479. case 'KINGB' : {
  480. owner_KING set [count owner_KING, _playerUID];
  481. publicVariable "owner_KING";
  482. player setVariable["DZE_Origins_KING",true,true];
  483. };
  484. case 'SHH';
  485. case 'SHB' : {
  486. owner_SH set [count owner_SH, _playerUID];
  487. publicVariable "owner_SH";
  488. player setVariable["DZE_Origins_SH",true,true];
  489. };
  490. };
  491. if(_classname in DZE_Origins_Stronghold) then {
  492. //PVDZ_obj_Publish = [dayz_playerUID,_tmpbuilt,[_dir,_location,dayz_playerUID],[]];
  493. PVDZ_obj_Publish = [_combination,_tmpbuilt,[_dir,_location,dayz_playerUID],[],player,dayz_authKey];
  494. //PVDZ_obj_Publish = [_combination,_tmpbuilt,[_dir,_location,dayz_playerUID],[]];
  495. //PVDZ_obj_Publish = [_tmpbuilt,[_dir,_location,_playerUID],_classname,true,dayz_combination,_activatingPlayer];
  496. publicVariableServer "PVDZ_obj_Publish";
  497. cutText [format[(localize "str_epoch_player_140"),_combination,_name], "PLAIN DOWN", 5];
  498. } else {
  499. //PVDZ_obj_Publish = [dayz_playerUID,_tmpbuilt,[_dir,_location,dayz_playerUID],[]];
  500. PVDZ_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location,dayz_playerUID],[],player,dayz_authKey];
  501. publicVariableServer "PVDZ_obj_Publish";
  502. cutText [format["Nice one! You now have a %1", _name], "PLAIN DOWN",5];
  503. };
  504. clearWeaponCargoGlobal _crate;
  505. clearMagazineCargoGlobal _crate;
  506. clearBackpackCargoGlobal _crate;
  507.  
  508. _objectID = _crate getVariable["ObjectID","0"];
  509. _objectUID = _crate getVariable["ObjectUID","0"];
  510. PVDZ_obj_Destroy = [_objectID,_objectUID,_activatingPlayer];
  511. publicVariableServer "PVDZ_obj_Destroy";
  512. if (isServer) then {
  513. PVDZ_obj_Destroy call server_deleteObjDirect;
  514. };
  515. deleteVehicle _crate;
  516. } else {
  517. deleteVehicle _tmpbuilt;
  518. };
  519.  
  520. } else {
  521. r_interrupt = false;
  522. if (vehicle player == player) then {
  523. [objNull, player, rSwitchMove,""] call RE;
  524. player playActionNow "stop";
  525. };
  526.  
  527. deleteVehicle _tmpbuilt;
  528.  
  529. cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  530. };
  531.  
  532. } else {
  533. cutText [format[(localize "str_epoch_player_47"),_name,_reason], "PLAIN DOWN"];
  534. };
  535. };
  536.  
  537. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement