Advertisement
Guest User

Untitled

a guest
Feb 13th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.38 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.5
  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","_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. _distance = 30;
  89. };
  90. };
  91. };
  92. } forEach _needNear;
  93.  
  94.  
  95. if(_abort) exitWith {
  96. cutText [format[(localize "str_epoch_player_135"),_reason,_distance], "PLAIN DOWN"];
  97. DZE_ActionInProgress = false;
  98. };
  99.  
  100. _classname = getText (configFile >> "CfgMagazines" >> _item >> "ItemActions" >> "Build" >> "create");
  101. _classnametmp = _classname;
  102. _require = getArray (configFile >> "cfgMagazines" >> _this >> "ItemActions" >> "Build" >> "require");
  103. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  104. _ghost = getText (configFile >> "CfgVehicles" >> _classname >> "ghostpreview");
  105.  
  106. _lockable = 0;
  107. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "lockable")) then {
  108. _lockable = getNumber(configFile >> "CfgVehicles" >> _classname >> "lockable");
  109. };
  110.  
  111. _requireplot = DZE_requireplot;
  112. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "requireplot")) then {
  113. _requireplot = getNumber(configFile >> "CfgVehicles" >> _classname >> "requireplot");
  114. };
  115.  
  116. _isAllowedUnderGround = 1;
  117. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "nounderground")) then {
  118. _isAllowedUnderGround = getNumber(configFile >> "CfgVehicles" >> _classname >> "nounderground");
  119. };
  120.  
  121. _offset = getArray (configFile >> "CfgVehicles" >> _classname >> "offset");
  122. if((count _offset) <= 0) then {
  123. _offset = [0,1.5,0];
  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 ["Cannot build plot pole within 60m of an existing plot.", "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. /* Commented out cause GHOST preview does not work with snapping!
  212. // if ghost preview available use that instead
  213. if (_ghost != "") then {
  214. _classname = _ghost;
  215. };
  216. */
  217.  
  218. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  219. _object setDir _dir;
  220. _object attachTo [player,_offset];
  221.  
  222. _position = getPosATL _object;
  223.  
  224. cutText [(localize "str_epoch_player_45"), "PLAIN DOWN"];
  225.  
  226.  
  227. player allowDamage false;
  228. SnappingOffset = _offset;
  229. SnappingDir = 0;
  230. SnappingSpotMarkers = [];
  231. SnappingEnabled = false;
  232. SnappedOffsetZ = 0;
  233. SnappingResetPos = false;
  234.  
  235. if (isClass (missionConfigFile >> "SnapPoints" >> _classname)) then {
  236. s_building_snapping = player addAction ["<t color=""#0000ff"">Toggle Snapping</t>", "scripts\snapping\player_toggleSnapping.sqf",_classname, 3, true, false, "",""];
  237. };
  238.  
  239. _snapper = [_object, _classname] spawn snap_object;
  240. _key_monitor = [] spawn player_buildControls ;
  241.  
  242. while {_isOk} do {
  243. sleep 1;
  244. _location2 = getPosATL player;
  245.  
  246. if(DZE_5) exitWith {
  247. _isOk = false;
  248. detach _object;
  249. _dir = getDir _object;
  250. _position = getPosATL _object;
  251. };
  252.  
  253. if(_location1 distance _location2 > 5) exitWith {
  254. _isOk = false;
  255. _cancel = true;
  256. _reason = "You've moved to far away from where you started building (within 5 meters)";
  257. detach _object;
  258. };
  259.  
  260. if(((SnappingOffset select 2) > 5) or ((SnappingOffset select 2) < -5)) exitWith {
  261. _isOk = false;
  262. _cancel = true;
  263. _reason = "Cannot move up or down more than 5 meters";
  264. detach _object;
  265. };
  266.  
  267. if (player getVariable["combattimeout", 0] >= time) exitWith {
  268. _isOk = false;
  269. _cancel = true;
  270. _reason = (localize "str_epoch_player_43");
  271. detach _object;
  272. };
  273.  
  274. if (DZE_cancelBuilding) exitWith {
  275. _isOk = false;
  276. _cancel = true;
  277. _reason = "Cancelled building.";
  278. detach _object;
  279. };
  280. };
  281.  
  282. terminate _snapper;
  283. terminate _key_monitor;
  284. player removeAction s_building_snapping;
  285. player allowDamage true;
  286.  
  287. //No building on roads unless toggled
  288. if (!DZE_BuildOnRoads) then {
  289. if (isOnRoad _position) then { _cancel = true; _reason = "Cannot build on a road."; };
  290. };
  291. // No building in trader zones
  292. if(!canbuild) then { _cancel = true; _reason = "Cannot build in a city."; };
  293. if(!placevault) then { _cancel = true; _reason = "Cannot build in a city."; };
  294.  
  295. if(!_cancel) then {
  296.  
  297. _classname = _classnametmp;
  298.  
  299. _location = _position;
  300.  
  301. if((_isAllowedUnderGround == 0) and ((_location select 2) < 0)) then {
  302. _location set [2,0];
  303. };
  304.  
  305. _object setPosATL _location;
  306. cutText [format[(localize "str_epoch_player_138"),_text], "PLAIN DOWN"];
  307.  
  308. _limit = 3;
  309.  
  310. if (DZE_StaticConstructionCount > 0) then {
  311. _limit = DZE_StaticConstructionCount;
  312. }
  313. else {
  314. if(isNumber (configFile >> "CfgVehicles" >> _classname >> "constructioncount")) then {
  315. _limit = getNumber(configFile >> "CfgVehicles" >> _classname >> "constructioncount");
  316. };
  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.  
  385. if (_isPole) then {
  386. [] spawn player_plotPreview;
  387. };
  388.  
  389. _object setVariable ["OEMPos",_location,true];
  390.  
  391. if(_lockable > 1) then {
  392.  
  393. _combinationDisplay = "";
  394.  
  395. switch (_lockable) do {
  396.  
  397. case 2: { // 2 lockbox
  398. _combination_1 = (floor(random 3)) + 100; // 100=red,101=green,102=blue
  399. _combination_2 = floor(random 10);
  400. _combination_3 = floor(random 10);
  401. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  402. dayz_combination = _combination;
  403. if (_combination_1 == 100) then {
  404. _combination_1_Display = "Red";
  405. };
  406. if (_combination_1 == 101) then {
  407. _combination_1_Display = "Green";
  408. };
  409. if (_combination_1 == 102) then {
  410. _combination_1_Display = "Blue";
  411. };
  412. _combinationDisplay = format["%1%2%3",_combination_1_Display,_combination_2,_combination_3];
  413. };
  414.  
  415. case 3: { // 3 combolock
  416. _combination_1 = floor(random 10);
  417. _combination_2 = floor(random 10);
  418. _combination_3 = floor(random 10);
  419. _combination = format["%1%2%3",_combination_1,_combination_2,_combination_3];
  420. dayz_combination = _combination;
  421. _combinationDisplay = _combination;
  422. };
  423.  
  424. case 4: { // 4 safe
  425. _combination_1 = floor(random 10);
  426. _combination_2 = floor(random 10);
  427. _combination_3 = floor(random 10);
  428. _combination_4 = floor(random 10);
  429. _combination = format["%1%2%3%4",_combination_1,_combination_2,_combination_3,_combination_4];
  430. dayz_combination = _combination;
  431. _combinationDisplay = _combination;
  432. };
  433. };
  434.  
  435. _object setVariable ["CharacterID",_combination,true];
  436.  
  437.  
  438. PVDZE_obj_Publish = [_combination,_object,[_dir,_location],_classname];
  439. publicVariableServer "PVDZE_obj_Publish";
  440.  
  441. cutText [format[(localize "str_epoch_player_140"),_combinationDisplay,_text], "PLAIN DOWN", 5];
  442.  
  443.  
  444. } else {
  445. _object setVariable ["CharacterID",dayz_characterID,true];
  446.  
  447. // fire?
  448. if(_object isKindOf "Land_Fire_DZ") then {
  449. _object spawn player_fireMonitor;
  450. } else {
  451. PVDZE_obj_Publish = [dayz_characterID,_object,[_dir,_location],_classname];
  452. publicVariableServer "PVDZE_obj_Publish";
  453. };
  454. };
  455. } else {
  456. deleteVehicle _object;
  457. cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  458. };
  459.  
  460. } else {
  461. r_interrupt = false;
  462. if (vehicle player == player) then {
  463. [objNull, player, rSwitchMove,""] call RE;
  464. player playActionNow "stop";
  465. };
  466.  
  467. deleteVehicle _object;
  468.  
  469. cutText [(localize "str_epoch_player_46") , "PLAIN DOWN"];
  470. };
  471.  
  472. } else {
  473. deleteVehicle _object;
  474. cutText [format[(localize "str_epoch_player_47"),_text,_reason], "PLAIN DOWN"];
  475. };
  476. };
  477.  
  478. DZE_ActionInProgress = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement