Advertisement
Guest User

custom_builds.sqf

a guest
Aug 19th, 2014
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.84 KB | None | 0 0
  1. /*
  2. DayZ Custom Buildables
  3. Made for DayZ Epoch please ask permission to use/edit/distrubute email vbawol@veteranbastards.com.
  4.  
  5. Edits by Mike of http://www.petuniaserver.com/ - Original file & all kudos to the EPOCH devs! http://www.dayzepoch.com
  6. Edits and re-writes by hogscraper:
  7. Added code to see if player has tools and materials required to build item
  8. Removed a lot of code referencing lockables, plot pole placement and construction multiplier since part of that code was already removed
  9. Cleaned up a lot of old code that wasn't needed any more for this custom crafting
  10. Removed irrelevant variables from private block
  11. This file is called with zero parameters
  12. */
  13. private ["_helperColor","_objectHelper","_objectHelperDir","_objectHelperPos","_canDo","_HT_temp","_HM_temp","_location","_dir","_classname","_cancel","_reason","_isMedic","_dis","_tmpbuilt","_onLadder","_isWater","_require","_text","_offset","_IsNearPlot","_isOk","_location1","_location2","_counter","_position","_object","_canBuildOnPlot","_friendlies","_nearestPole","_ownerID","_findNearestPoles","_findNearestPole","_distance","_zheightchanged","_rotate","_zheightdirection","_isNear","_objHupDiff","_vehicle","_inVehicle","_requireplot","_objHDiff","_ownerPUID", "_playerUID"];
  14.  
  15. _AdminCraft=false;
  16. _PUID = getPlayerUID player;
  17.  
  18.  
  19. if(_PUID in Admin_Crafting) then {
  20. _AdminCraft=true;
  21. };
  22.  
  23. _lbIndex = lbCurSel 3901;
  24. _classname = lbText [3901,_lbIndex];
  25.  
  26. if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_40") , "PLAIN DOWN"]; };
  27. DZE_ActionInProgress = true;
  28.  
  29. _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  30. _isWater = dayz_isSwimming;
  31. _cancel = false;
  32. _reason = "";
  33. _canBuildOnPlot = false;
  34.  
  35. //create arrays for checking whether or not the player
  36. //has the correct tools and materials to make the desired item
  37. _requiredtools = getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requiredtools");
  38. _requiredmaterials = getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requiredmaterials");
  39. _RT_temp=getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requiredtools");
  40. _RM_temp=getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requiredmaterials");
  41. _hastools = false;
  42. _hasmaterials = false;
  43. _weaps=[];
  44. _mags=[];
  45.  
  46. _weaps=weapons player;
  47. _mags=magazines player;
  48. _tmp_Pos=0;
  49. _counter=0;
  50.  
  51. {
  52. _tmp_Pos= _weaps find _x;
  53. if (_tmp_Pos > -1) then {
  54. _requiredtools set [_counter,objNull];
  55. _weaps set [_tmp_Pos,objNull];
  56. };
  57. _counter = _counter + 1;
  58. }
  59. forEach _RT_temp;
  60.  
  61. _requiredtools=_requiredtools-[objNull];
  62. _weaps=_weaps-[objNull];
  63.  
  64. _tmp_Pos=0;
  65. _counter=0;
  66. {
  67. _tmp_Pos= _mags find _x;
  68. if (_tmp_Pos > -1) then {
  69. _requiredmaterials set [_counter,objNull];
  70. _mags set [_tmp_Pos,objNull];
  71. };
  72. _counter = _counter + 1;
  73. }
  74. forEach _RM_temp;
  75. _requiredmaterials=_requiredmaterials-[objNull];
  76. _mags=_mags-[objNull];
  77.  
  78. if(((count _requiredmaterials) == 0) or (_AdminCraft)) then {
  79. _hasmaterials=true;
  80. };
  81. if(((count _requiredtools) == 0) or (_AdminCraft)) then {
  82. _hastools=true;
  83. };
  84.  
  85. //Create the message to display if player is missing any of the required tools
  86. if (!_hasTools) then{
  87. _HT_temp="You are missing the following tools:";
  88. {
  89. _HT_temp=_HT_temp+" " + getText (configFile >> "CfgWeapons" >> _x >> "displayName");
  90. }foreach _requiredtools;
  91. };
  92.  
  93. //Create the message to display if player is missing any of the required materials
  94. if (!_hasMaterials) then{
  95. _HM_temp="You are missing the following materials:";
  96. {
  97. if(getText (configFile >> "CfgMagazines" >> _x >> "displayName")=="Supply Crate") then{
  98. _HM_temp=_HM_temp+" " + getText (configFile >> "CfgMagazines" >> _x >> "descriptionShort");
  99. }else{
  100. _HM_temp=_HM_temp+" " + getText (configFile >> "CfgMagazines" >> _x >> "displayName");
  101. };
  102. }foreach _requiredmaterials;
  103. };
  104.  
  105. _vehicle = vehicle player;
  106. _inVehicle = (_vehicle != player);
  107. _playerUID = getPlayerUID player;
  108. helperDetach = false;
  109. _canDo = (!r_drag_sqf and !r_player_unconscious);
  110.  
  111. DZE_Q = false;
  112. DZE_Z = false;
  113.  
  114. DZE_Q_alt = false;
  115. DZE_Z_alt = false;
  116.  
  117. DZE_Q_ctrl = false;
  118. DZE_Z_ctrl = false;
  119.  
  120. DZE_5 = false;
  121. DZE_4 = false;
  122. DZE_6 = false;
  123. DZE_F = false;
  124.  
  125. DZE_cancelBuilding = false;
  126.  
  127. call gear_ui_init;
  128. closeDialog 1;
  129.  
  130. if (_isWater) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_26", "PLAIN DOWN"];};
  131. if (_inVehicle) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];};
  132. if (_onLadder) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_21", "PLAIN DOWN"];};
  133. if (player getVariable["combattimeout", 0] >= time) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];};
  134. if (!_hasTools) exitWith {DZE_ActionInProgress = false; cutText [format["%1",_HT_temp], "PLAIN DOWN"];};
  135. if (!_hasMaterials) exitWith {DZE_ActionInProgress = false; cutText [format["%1",_HM_temp], "PLAIN DOWN"];};
  136.  
  137. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  138.  
  139. _requireplot = DZE_requireplot;
  140. if(isNumber (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requireplot")) then {
  141. _requireplot = getNumber(missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requireplot");
  142. };
  143. if(_AdminCraft) then {
  144. _requireplot=0;
  145. };
  146.  
  147. _offset = getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "offset");
  148. if((count _offset) <= 0) then {
  149. _offset = [0,3,0];
  150. };
  151.  
  152. _distance = DZE_PlotPole select 0;
  153.  
  154. // check for near plot
  155. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  156. _findNearestPole = [];
  157.  
  158. {
  159. if (alive _x) then {
  160. _findNearestPole set [(count _findNearestPole),_x];
  161. };
  162. } foreach _findNearestPoles;
  163.  
  164. _IsNearPlot = count (_findNearestPole);
  165.  
  166. // check nearby plot's ownership and then for friend status
  167. //if plot does not belong to player
  168. _nearestPole = _findNearestPole select 0;
  169.  
  170. _ownerID = _nearestPole getVariable["ownerPUID","0"];
  171.  
  172. if(_playerUID == _ownerID) then { //Keep ownership
  173. _canBuildOnPlot = true;
  174. } else {
  175. _friendlies = player getVariable ["friendlyTo",[]];
  176. if(_ownerID in _friendlies) then {
  177. _canBuildOnPlot = true;
  178. };
  179. };
  180. //if plotpole is needed and none are within range or if what's in range does belong
  181. //to the player or a friendly we need to exit now
  182.  
  183. if((_requireplot>0) and ((_IsNearPlot==0)||(!_canBuildOnPlot))) exitWith {DZE_ActionInProgress = false; cutText ["Building of this item requires a plot pole within range!" , "PLAIN DOWN"]; };
  184.  
  185. _location = [0,0,0];
  186. _isOk = true;
  187.  
  188. // get inital players position
  189. _location1 = getPosATL player;
  190. _dir = getDir player;
  191.  
  192. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  193. //Build gizmo
  194. _objectHelper = "Sign_sphere10cm_EP1" createVehicle _location;
  195. _helperColor = "#(argb,8,8,3)color(0,0,0,0,ca)";
  196. _objectHelper setobjecttexture [0,_helperColor];
  197. _objectHelper attachTo [player,_offset];
  198. _object attachTo [_objectHelper,[0,0,0]];
  199. _position = getPosATL _objectHelper;
  200.  
  201. if(_AdminCraft) then{
  202. } else {
  203. {
  204. player removeMagazine _x;
  205. } foreach _RM_temp;
  206. };
  207.  
  208. _position = getPosATL _object;
  209. cutText [(localize "str_epoch_player_45"), "PLAIN DOWN"];
  210. _objHDiff = 0;
  211.  
  212. while {_isOk} do {
  213.  
  214. _zheightchanged = false;
  215. _zheightdirection = "";
  216. _rotate = false;
  217.  
  218. if (DZE_Q) then {
  219. DZE_Q = false;
  220. _zheightdirection = "up";
  221. _zheightchanged = true;
  222. };
  223. if (DZE_Z) then {
  224. DZE_Z = false;
  225. _zheightdirection = "down";
  226. _zheightchanged = true;
  227. };
  228. if (DZE_Q_alt) then {
  229. DZE_Q_alt = false;
  230. _zheightdirection = "up_alt";
  231. _zheightchanged = true;
  232. };
  233. if (DZE_Z_alt) then {
  234. DZE_Z_alt = false;
  235. _zheightdirection = "down_alt";
  236. _zheightchanged = true;
  237. };
  238. if (DZE_Q_ctrl) then {
  239. DZE_Q_ctrl = false;
  240. _zheightdirection = "up_ctrl";
  241. _zheightchanged = true;
  242. };
  243. if (DZE_Z_ctrl) then {
  244. DZE_Z_ctrl = false;
  245. _zheightdirection = "down_ctrl";
  246. _zheightchanged = true;
  247. };
  248. if (DZE_4) then {
  249. _rotate = true;
  250. DZE_4 = false;
  251. if (helperDetach) then {
  252. _dir = -45;
  253. } else {
  254. _dir = 180;
  255. };
  256. };
  257. if (DZE_6) then {
  258. _rotate = true;
  259. DZE_6 = false;
  260. if (helperDetach) then {
  261. _dir = 45;
  262. } else {
  263. _dir = 0;
  264. };
  265. };
  266. //Number keys above qwerty
  267. //1=turn clockwise 1/16th of a circle
  268. //2=detaches object from player - OBJECT MUST BE COMPLETELY ABOVE GROUND OR IT WILL DISAPPEAR!!
  269. //3=turn counter clockwise 1/16th of a circle
  270. if (AAC_1) then {
  271. _rotate = true;
  272. AAC_1 = false;
  273. if (helperDetach) then {
  274. _dir = -45;
  275. } else {
  276. _dir = _dir + 22.5;;
  277. };
  278. };
  279.  
  280. if (AAC_3) then {
  281. _rotate = true;
  282. AAC_3 = false;
  283. if (helperDetach) then {
  284. _dir = -45;
  285. } else {
  286. _dir = _dir - 22.5;
  287. };
  288. };
  289.  
  290. if (DZE_F and _canDo) then {
  291. if (helperDetach) then {
  292. _objectHelperDir = getDir _objectHelper;
  293. _objectHelper attachTo [player];
  294. _objectHelper setDir _objectHelperDir-(getDir player);
  295. helperDetach = false;
  296. } else {
  297. _objectHelperPos = getPosATL _objectHelper;
  298. detach _objectHelper;
  299. _objectHelper setPosATL _objectHelperPos;
  300. _objectHelperDir = getDir _objectHelper;
  301. _objectHelper setVelocity [0,0,0]; //fix sliding glitch
  302. helperDetach = true;
  303. };
  304. DZE_F = false;
  305. };
  306.  
  307. if(_rotate) then {
  308. if (helperDetach) then {
  309. _objectHelperDir = getDir _objectHelper;
  310. _objectHelperPos = getPosATL _objectHelper;
  311. _objectHelper setDir _objectHelperDir+_dir;
  312. _objectHelper setPosATL _objectHelperPos;
  313. } else {
  314. _objectHelper setDir _dir;
  315. _objectHelper setPosATL _position;
  316. //diag_log format["DEBUG Rotate BUILDING POS: %1", _position];
  317. };
  318.  
  319. };
  320.  
  321. if(_zheightchanged) then {
  322. if (!helperDetach) then {
  323. detach _objectHelper;
  324. };
  325.  
  326. _position = getPosATL _objectHelper;
  327.  
  328. if(_zheightdirection == "up") then {
  329. _position set [2,((_position select 2)+0.1)];
  330. _objHDiff = _objHDiff + 0.1;
  331. };
  332. if(_zheightdirection == "down") then {
  333. _position set [2,((_position select 2)-0.1)];
  334. _objHDiff = _objHDiff - 0.1;
  335. };
  336.  
  337. if(_zheightdirection == "up_alt") then {
  338. _position set [2,((_position select 2)+1)];
  339. _objHDiff = _objHDiff + 1;
  340. };
  341. if(_zheightdirection == "down_alt") then {
  342. _position set [2,((_position select 2)-1)];
  343. _objHDiff = _objHDiff - 1;
  344. };
  345.  
  346. if(_zheightdirection == "up_ctrl") then {
  347. _position set [2,((_position select 2)+0.01)];
  348. _objHDiff = _objHDiff + 0.01;
  349. };
  350. if(_zheightdirection == "down_ctrl") then {
  351. _position set [2,((_position select 2)-0.01)];
  352. _objHDiff = _objHDiff - 0.01;
  353. };
  354.  
  355. _objectHelper setDir (getDir _objectHelper);
  356.  
  357. if((_isAllowedUnderGround == 0) && ((_position select 2) < 0)) then {
  358. _position set [2,0];
  359. };
  360.  
  361. _objectHelper setPosATL _position;
  362.  
  363. //diag_log format["DEBUG Change BUILDING POS: %1", _position];
  364.  
  365. if (!helperDetach) then {
  366. _objectHelper attachTo [player];
  367. };
  368. };
  369.  
  370.  
  371. sleep 0.5;
  372.  
  373. _location2 = getPosATL player;
  374.  
  375. if(DZE_5) exitWith {
  376. _isOk = false;
  377. detach _object;
  378. _dir = getDir _object;
  379. _position = getPosATL _object;
  380. deleteVehicle _object;
  381. detach _objectHelper;
  382. deleteVehicle _objectHelper;
  383. };
  384.  
  385. if(_location1 distance _location2 > 10) exitWith {
  386. _isOk = false;
  387. _cancel = true;
  388. _reason = "You've moved to far away from where you started building (within 10 meters)";
  389. detach _object;
  390. deleteVehicle _object;
  391. detach _objectHelper;
  392. deleteVehicle _objectHelper;
  393. };
  394.  
  395. if(abs(_objHDiff) > 15) exitWith {
  396. _isOk = false;
  397. _cancel = true;
  398. _reason = "Cannot move up or down more than 15 meters";
  399. detach _object;
  400. deleteVehicle _object;
  401. detach _objectHelper;
  402. deleteVehicle _objectHelper;
  403. };
  404.  
  405. if (player getVariable["combattimeout", 0] >= time) exitWith {
  406. _isOk = false;
  407. _cancel = true;
  408. _reason = (localize "str_epoch_player_43");
  409. detach _object;
  410. deleteVehicle _object;
  411. detach _objectHelper;
  412. deleteVehicle _objectHelper;
  413. };
  414.  
  415. if (DZE_cancelBuilding) exitWith {
  416. _isOk = false;
  417. _cancel = true;
  418. _reason = "Cancelled building.";
  419. detach _object;
  420. deleteVehicle _object;
  421. detach _objectHelper;
  422. deleteVehicle _objectHelper;
  423. };
  424. };
  425.  
  426. //No building on roads unless toggled
  427. if (!DZE_BuildOnRoads) then {
  428. if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  429. };
  430.  
  431. // No building in trader zones
  432. if(!canbuild) then { _cancel = true; _reason = "Cannot build in a trader zone."; };
  433.  
  434. if(!_cancel) then {
  435.  
  436. // Start Build
  437. _tmpbuilt = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  438.  
  439. _tmpbuilt setdir _dir;
  440.  
  441. // Get position based on object
  442. _location = _position;
  443.  
  444. _tmpbuilt setPosATL _location;
  445.  
  446. cutText [format[(localize "str_epoch_player_138"),_text], "PLAIN DOWN"];
  447.  
  448. player playActionNow "Medic";
  449. [player,"repair",0,false,10] call dayz_zombieSpeak;
  450. [player,10,true,(getPosATL player)] spawn player_alertZombies;
  451.  
  452. cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  453.  
  454. _tmpbuilt setVariable ["OEMPos",_location,true];
  455. _tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
  456. _tmpbuilt setVariable ["ownerPUID",_playerUID,true];
  457. _charID = dayz_characterID;
  458. _activatingPlayer = player;
  459.  
  460. PVDZE_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location,_playerUID],_classname];
  461. publicVariableServer "PVDZE_obj_Publish";
  462.  
  463. cutText [format["Your build was successful!"], "PLAIN DOWN",3];
  464.  
  465. player reveal _tmpbuilt;
  466. DZE_ActionInProgress = false;
  467.  
  468. } else {
  469. cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
  470. DZE_ActionInProgress = false;
  471. if(_AdminCraft) then {
  472. } else {
  473. {
  474. //Since player had items removed we need to give them back
  475. player addMagazine _x;
  476. } foreach _RM_temp;
  477. };
  478. };
  479.  
  480. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement