Advertisement
DeTrix

player_build.sqf

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