Advertisement
Guest User

Untitled

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