Advertisement
Guest User

Untitled

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