Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.69 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 ["_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. _playerUID = getPlayerUID player;
  35.  
  36.  //create arrays for checking whether or not the player
  37.  //has the correct tools and materials to make the desired item
  38. _requiredtools = getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requiredtools");
  39. _requiredmaterials = getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requiredmaterials");
  40. _RT_temp=getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requiredtools");
  41. _RM_temp=getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requiredmaterials");
  42. _hastools = false;
  43. _hasmaterials = false;
  44. _weaps=[];
  45. _mags=[];
  46.  
  47. _weaps=weapons player;
  48. _mags=magazines player;
  49. _tmp_Pos=0;
  50. _counter=0;
  51.  
  52. {
  53. _tmp_Pos= _weaps find _x;
  54. if (_tmp_Pos > -1) then {
  55. _requiredtools set [_counter,objNull];
  56. _weaps set [_tmp_Pos,objNull];
  57. };
  58. _counter = _counter + 1;
  59. }
  60. forEach _RT_temp;
  61.  
  62. _requiredtools=_requiredtools-[objNull];
  63. _weaps=_weaps-[objNull];
  64.  
  65. _tmp_Pos=0;
  66. _counter=0;
  67. {
  68. _tmp_Pos= _mags find _x;
  69. if (_tmp_Pos > -1) then {
  70. _requiredmaterials set [_counter,objNull];
  71. _mags set [_tmp_Pos,objNull];
  72. };
  73. _counter = _counter + 1;
  74. }
  75. forEach _RM_temp;
  76. _requiredmaterials=_requiredmaterials-[objNull];
  77. _mags=_mags-[objNull];
  78.  
  79. if(((count _requiredmaterials) == 0) or (_AdminCraft)) then {
  80. _hasmaterials=true;
  81. };
  82. if(((count _requiredtools) == 0) or (_AdminCraft)) then {
  83. _hastools=true;
  84. };
  85.  
  86. //Create the message to display if player is missing any of the required tools
  87. if (!_hasTools) then{
  88. _HT_temp="You are missing the following tools:";
  89. {  
  90. _HT_temp=_HT_temp+" " + getText (configFile >> "CfgWeapons" >> _x >> "displayName");
  91. }foreach _requiredtools;
  92. };
  93.  
  94. //Create the message to display if player is missing any of the required materials
  95. if (!_hasMaterials) then{
  96. _HM_temp="You are missing the following materials:";
  97. {  
  98. if(getText (configFile >> "CfgMagazines" >> _x >> "displayName")=="Supply Crate") then{
  99. _HM_temp=_HM_temp+" " + getText (configFile >> "CfgMagazines" >> _x >> "descriptionShort");
  100. }else{
  101. _HM_temp=_HM_temp+" " + getText (configFile >> "CfgMagazines" >> _x >> "displayName");
  102. };
  103. }foreach _requiredmaterials;
  104. };
  105.  
  106. _vehicle = vehicle player;
  107. _inVehicle = (_vehicle != player);
  108.  
  109. DZE_Q = false;
  110. DZE_Z = false;
  111.  
  112. DZE_Q_alt = false;
  113. DZE_Z_alt = false;
  114.  
  115. DZE_Q_ctrl = false;
  116. DZE_Z_ctrl = false;
  117.  
  118. DZE_5 = false;
  119. DZE_4 = false;
  120. DZE_6 = false;
  121.  
  122. DZE_cancelBuilding = false;
  123.  
  124. call gear_ui_init;
  125. closeDialog 1;
  126.  
  127. if (_isWater) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_26", "PLAIN DOWN"];};
  128. if (_inVehicle) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_42"), "PLAIN DOWN"];};
  129. if (_onLadder) exitWith {DZE_ActionInProgress = false; cutText [localize "str_player_21", "PLAIN DOWN"];};
  130. if (player getVariable["combattimeout", 0] >= time) exitWith {DZE_ActionInProgress = false; cutText [(localize "str_epoch_player_43"), "PLAIN DOWN"];};
  131. if (!_hasTools) exitWith {DZE_ActionInProgress = false; cutText [format["%1",_HT_temp], "PLAIN DOWN"];};
  132. if (!_hasMaterials) exitWith {DZE_ActionInProgress = false; cutText [format["%1",_HM_temp], "PLAIN DOWN"];};
  133.  
  134. _text =  getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  135.  
  136. _requireplot = DZE_requireplot;
  137. if(isNumber (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requireplot")) then {
  138. _requireplot = getNumber(missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "requireplot");
  139. };
  140. if(_AdminCraft) then {
  141. _requireplot=0;
  142. };
  143.  
  144. _offset =  getArray (missionConfigFile >> "Custom_Buildables" >> "Buildables" >> ComboBoxResult >> _classname >> "offset");
  145. if((count _offset) <= 0) then {
  146. _offset = [0,3,0];
  147. };
  148.  
  149. _distance = DZE_PlotPole select 0;
  150.  
  151. // check for near plot
  152. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  153. _findNearestPole = [];
  154.  
  155. {
  156. if (alive _x) then {
  157. _findNearestPole set [(count _findNearestPole),_x];
  158. };
  159. } foreach _findNearestPoles;
  160.  
  161. _IsNearPlot = count (_findNearestPole);
  162.  
  163. // check nearby plot's ownership and then for friend status
  164. //if plot does not belong to player
  165. _nearestPole = _findNearestPole select 0;
  166.  
  167. _ownerID = _nearestPole getVariable["ownerPUID","0"];
  168.  
  169. if(_playerUID == _ownerID) then {  //Keep ownership
  170.     _canBuildOnPlot = true;
  171. } else {
  172. _friendlies = player getVariable ["friendlyTo",[]];
  173. if(_ownerID in _friendlies) then {
  174.     _canBuildOnPlot = true;
  175.     };
  176. };
  177. //if plotpole is needed and none are within range or if what's in range does belong
  178. //to the player or a friendly we need to exit now
  179.  
  180. if((_requireplot>0) and ((_IsNearPlot==0)||(!_canBuildOnPlot))) exitWith {DZE_ActionInProgress = false; cutText ["Building of this item requires a plot pole within range!" , "PLAIN DOWN"]; };
  181.  
  182. _location = [0,0,0];
  183. _isOk = true;
  184.  
  185. // get inital players position
  186. _location1 = getPosATL player;
  187. _dir = getDir player;
  188.  
  189. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  190. _object attachTo [player,_offset];
  191.  
  192. if(_AdminCraft) then{
  193. } else {
  194. {
  195. player removeMagazine _x;
  196. } foreach _RM_temp;
  197. };
  198.  
  199. _position = getPosATL _object;
  200.  cutText [(localize "str_epoch_player_45"), "PLAIN DOWN"];
  201. _objHDiff = 0;
  202.  
  203. while {_isOk} do {
  204.  
  205. _zheightchanged = false;
  206. _zheightdirection = "";
  207. _rotate = false;
  208.  
  209. if (DZE_Q) then {
  210. DZE_Q = false;
  211. _zheightdirection = "up";
  212. _zheightchanged = true;
  213. };
  214. if (DZE_Z) then {
  215. DZE_Z = false;
  216. _zheightdirection = "down";
  217. _zheightchanged = true;
  218. };
  219. if (DZE_Q_alt) then {
  220. DZE_Q_alt = false;
  221. _zheightdirection = "up_alt";
  222. _zheightchanged = true;
  223. };
  224. if (DZE_Z_alt) then {
  225. DZE_Z_alt = false;
  226. _zheightdirection = "down_alt";
  227. _zheightchanged = true;
  228. };
  229. if (DZE_Q_ctrl) then {
  230. DZE_Q_ctrl = false;
  231. _zheightdirection = "up_ctrl";
  232. _zheightchanged = true;
  233. };
  234. if (DZE_Z_ctrl) then {
  235. DZE_Z_ctrl = false;
  236. _zheightdirection = "down_ctrl";
  237. _zheightchanged = true;
  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. //Number keys above qwerty
  250. //1=turn clockwise 1/16th of a circle
  251. //2=detaches object from player - OBJECT MUST BE COMPLETELY ABOVE GROUND OR IT WILL DISAPPEAR!!
  252. //3=turn counter clockwise 1/16th of a circle
  253. if (AAC_1) then {
  254. _rotate = true;
  255. AAC_1 = false;
  256. _dir = _dir + 22.5;;
  257. };
  258.  
  259. if (AAC_3) then {
  260. _rotate = true;
  261. AAC_3 = false;
  262. _dir = _dir - 22.5;
  263. };
  264.  
  265. if(_rotate) then {
  266. _object setDir _dir;
  267. _object setPosATL _position;
  268. };
  269.  
  270. if(_zheightchanged) then {
  271. detach _object;
  272.  
  273. _position = getPosATL _object;
  274.  
  275. if(_zheightdirection == "up") then {
  276. _position set [2,((_position select 2)+0.1)];
  277. _objHDiff = _objHDiff + 0.1;
  278. };
  279. if(_zheightdirection == "down") then {
  280. _position set [2,((_position select 2)-0.1)];
  281. _objHDiff = _objHDiff - 0.1;
  282. };
  283.  
  284. if(_zheightdirection == "up_alt") then {
  285. _position set [2,((_position select 2)+1)];
  286. _objHupDiff = _objHupDiff + 1;
  287. };
  288. if(_zheightdirection == "down_alt") then {
  289. _position set [2,((_position select 2)-1)];
  290. _objHDiff = _objHDiff - 1;
  291. };
  292.  
  293. if(_zheightdirection == "up_ctrl") then {
  294. _position set [2,((_position select 2)+0.01)];
  295. _objHupDiff = _objHupDiff + 0.01;
  296. };
  297. if(_zheightdirection == "down_ctrl") then {
  298. _position set [2,((_position select 2)-0.01)];
  299. _objHDiff = _objHDiff - 0.01;
  300. };
  301.  
  302. _object setDir (getDir _object);
  303. _object setPosATL _position;
  304. _object attachTo [player];
  305. };
  306.  
  307. sleep 0.5;
  308.  
  309. _location2 = getPosATL player;
  310.  
  311. if(DZE_5) exitWith {
  312. _isOk = false;
  313. detach _object;
  314. _dir = getDir _object;
  315. _position = getPosATL _object;
  316. deleteVehicle _object;
  317. };
  318.  
  319. if(_location1 distance _location2 > 5) exitWith {
  320. _isOk = false;
  321. _cancel = true;
  322. _reason = "You've moved to far away from where you started building (within 5 meters)";
  323. detach _object;
  324. deleteVehicle _object;
  325. };
  326.  
  327. if(abs(_objHDiff) > 5) exitWith {
  328. _isOk = false;
  329. _cancel = true;
  330. _reason = "Cannot move up or down more than 5 meters";
  331. detach _object;
  332. deleteVehicle _object;
  333. };
  334.  
  335. if (player getVariable["combattimeout", 0] >= time) exitWith {
  336. _isOk = false;
  337. _cancel = true;
  338. _reason = (localize "str_epoch_player_43");
  339. detach _object;
  340. deleteVehicle _object;
  341. };
  342.  
  343. if (DZE_cancelBuilding) exitWith {
  344. _isOk = false;
  345. _cancel = true;
  346. _reason = "Cancelled building.";
  347. detach _object;
  348. deleteVehicle _object;
  349. };
  350. };
  351.  
  352. //No building on roads unless toggled
  353. if (!DZE_BuildOnRoads) then {
  354. if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  355. };
  356.  
  357. // No building in trader zones
  358. if(!canbuild) then { _cancel = true; _reason = "Cannot build in a trader zone."; };
  359.  
  360. if(!_cancel) then {
  361.  
  362. // Start Build
  363. _tmpbuilt = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  364.  
  365. _tmpbuilt setdir _dir;
  366.  
  367. // Get position based on object
  368. _location = _position;
  369.  
  370. _tmpbuilt setPosATL _location;
  371.  
  372. cutText [format[(localize "str_epoch_player_138"),_text], "PLAIN DOWN"];
  373.  
  374. player playActionNow "Medic";
  375. [player,"repair",0,false,10] call dayz_zombieSpeak;
  376. [player,10,true,(getPosATL player)] spawn player_alertZombies;
  377.  
  378.  cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  379.  
  380. _tmpbuilt setVariable ["OEMPos",_location,true];
  381. _tmpbuilt setVariable ["CharacterID",dayz_characterID,true];
  382. _tmpbuilt setVariable ["ownerPUID",_playerUID,true];
  383.  
  384. _charID = dayz_characterID;
  385. _activatingPlayer = player;
  386.  
  387. PVDZE_obj_Publish = [dayz_characterID,_tmpbuilt,[_dir,_location,_playerUID],_classname];
  388. publicVariableServer "PVDZE_obj_Publish";
  389.  
  390. cutText [format["Your build was successful!"], "PLAIN DOWN",3];
  391.  
  392. player reveal _tmpbuilt;
  393. DZE_ActionInProgress = false;
  394.  
  395. } else {
  396. cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
  397. DZE_ActionInProgress = false;
  398. if(_AdminCraft) then {
  399. } else {
  400. {
  401. //Since player had items removed we need to give them back
  402. player addMagazine _x;
  403. } foreach _RM_temp;
  404. };
  405. };
  406.  
  407. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement