Advertisement
Guest User

player_basebuild.sqf

a guest
Jun 25th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.65 KB | None | 0 0
  1. private ["_locationPlayer","_location","_attachCoords","_dir","_building","_staticObj","_hasEtool","_hasToolbox","_onLadder","_canDo","_isWater","_inVehicle","_isOk","_closestTown","_town_name","_town_pos","_roadAllowed","_medWait","_longWait","_checkComplete","_finished","_eTool","_toolBox","_alreadyBuilt","_inBuilding","_inTown","_inProgress","_result","_isSimulated","_isDestructable","_canBuildOnPlot","_classname","_check_town","_cntLoop","_chosenRecipe","_requirements","_buildable","_buildables","_longWloop","_medWloop","_smallWloop","_cnt","_playerCombat","_funcExitScript","_isPole","_distance","_findNearestPoles","_findNearestPole","_IsNearPlot","_nearestPole","_ownerID","_friendlies","_message","_buildings","_isBuilding","_cancel","_reason","_item","_qtyT","_qtyS","_qtyW","_qtyL","_qtyM","_qtyG","_mags","_itemT","_itemS","_itemW","_itemL","_itemM","_itemG","_qtyB","_itemB","_qtyC","_itemC","_qtyP","_itemP","_qtyBu","_itemBu","_qtyWo","_itemWo","_qtyWoo","_itemWoo","_qtyI","_i","_text","_startPos","_modDir","_isDestrutable","_onRoad","_townRange","_panelNearest2","_buildCheck","_buildReady","_object","_isInCombat","_dialog","_uidDir","_p1","_p2","_p3","_coder","_code","_fuel"];
  2.  
  3. // Location placement declarations
  4. _locationPlayer = player modeltoworld [0,0,0];
  5. _location = player modeltoworld [0,0,0]; // Used for object start location and to keep track of object position throughout
  6. _attachCoords = [0,0,0];
  7. _dir = getDir player;
  8. _building = nearestObject [player, "Building"];
  9. _staticObj = nearestObject [player, "Static"];
  10.  
  11. // Restriction Checks
  12. _hasEtool = "ItemEtool" in weapons player;
  13. _hasToolbox = "ItemToolbox" in items player;
  14. _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  15. _canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); //USE!!
  16. _isWater = (surfaceIsWater _locationPlayer) or dayz_isSwimming;
  17. _inVehicle = (vehicle player != player);
  18. _isOk = [player,_building] call fnc_isInsideBuilding;
  19. _closestTown = (nearestLocations [player,["NameCityCapital","NameCity","NameVillage","Airport"],25600]) select 0;
  20. _town_name = text _closestTown;
  21. _town_pos = position _closestTown;
  22.  
  23. // Booleans Some not used, possibly use later
  24. _roadAllowed = false;
  25. _medWait = false;
  26. _longWait = false;
  27. _checkComplete = false;
  28. _finished = false;
  29. _eTool = false;
  30. _toolBox = false;
  31. _alreadyBuilt = false;
  32. _inBuilding = false;
  33. _inTown = false;
  34. _inProgress = false;
  35. _result = false;
  36. _isSimulated = false;
  37. _isDestructable = false;
  38. _canBuildOnPlot = false;
  39. // Strings
  40. _classname = "";
  41. _check_town = "";
  42.  
  43. // Other
  44. _cntLoop = 0;
  45. _chosenRecipe = [];
  46. _requirements = [];
  47. _buildable = [];
  48. _buildables = [];
  49. _longWloop = 2;
  50. _medWloop = 1;
  51. _smallWloop = 0;
  52. _cnt = 0;
  53. _playerCombat = player;
  54.  
  55. // Function to exit script without combat activate
  56. _funcExitScript = {
  57. procBuild = false;
  58. breakOut "exit";
  59. };
  60.  
  61. _isPole = (_classname == "Plastic_Pole_EP1_DZ");
  62.  
  63. _distance = 30;
  64. if(_isPole) then {
  65. _distance = 45;
  66. };
  67. // check for near plot
  68. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  69. _findNearestPole = [];
  70. {if (alive _x) then {_findNearestPole set [(count _findNearestPole),_x];};} foreach _findNearestPoles;
  71.  
  72. _IsNearPlot = count (_findNearestPole);
  73.  
  74. // If item is plot pole and another one exists within 45m
  75. if(_isPole and _IsNearPlot > 0) exitWith { TradeInprogress = false; cutText ["Cannot build plot pole within 45m of an existing plot." , "PLAIN DOWN"]; };
  76.  
  77. if(_IsNearPlot == 0) then {
  78.  
  79. // Allow building of plot
  80. if(_isPole) then {
  81. _canBuildOnPlot = true;
  82. };
  83.  
  84. } else {
  85. // Since there are plots nearby we check for ownership and then for friend status
  86.  
  87. _nearestPole = _findNearestPole select 0;
  88.  
  89. // Find owner
  90. _ownerID = _nearestPole getVariable["CharacterID","0"];
  91.  
  92. // diag_log format["DEBUG BUILDING: %1 = %2", dayz_characterID, _ownerID];
  93.  
  94. // check if friendly to owner
  95. if(dayz_playerUID == _ownerID) then {
  96. // owner can build anything within his plot except other plots
  97. if(!_isPole) then {
  98. _canBuildOnPlot = true;
  99. };
  100.  
  101. } else {
  102. // disallow building plot
  103. if(!_isPole) then {
  104. _friendlies = player getVariable ["friendlyTo",[]];
  105. // check if friendly to owner
  106. if(_ownerID in _friendlies) then {
  107. _canBuildOnPlot = true;
  108. };
  109. };
  110. };
  111.  
  112. };
  113.  
  114. // _message
  115. if(!_canBuildOnPlot) exitWith { TradeInprogress = false; cutText ["Building requires plot pole within 30m." , "PLAIN DOWN"]; };
  116.  
  117. // testing new way of finding building
  118. _buildings = nearestObjects [(vehicle player), ["Building"], 100];
  119. {
  120. _isBuilding = [(vehicle player),_x] call fnc_isInsideBuilding;
  121. if(_isBuilding) exitWith {
  122. _cancel = true;
  123. _reason = "Cannot build inside another building.";
  124. };
  125. } forEach _buildings;
  126.  
  127. // Do first checks to see if player can build before counting
  128. if (procBuild) then {cutText ["Your already building!", "PLAIN DOWN"];breakOut "exit";};
  129. if(_isWater) then {cutText [localize "str_player_26", "PLAIN DOWN"];call _funcExitScript;};
  130. if(_onLadder) then {cutText [localize "str_player_21", "PLAIN DOWN"];call _funcExitScript;};
  131. if (_inVehicle) then {cutText ["Can't do this in vehicle", "PLAIN DOWN"];call _funcExitScript;};
  132. if (!placevault) then {cutText ["Can't build in a trader city", "PLAIN DOWN"];call _funcExitScript;};
  133. disableSerialization;
  134. closedialog 1;
  135. // Ashfor Fix: Did player try to drop mag and keep action active (not really needed but leave here just in case)
  136. //_item = _this;
  137. //if (_item in (magazines player) ) then { // needs };
  138. // Global variables for loop method, procBuild may not be needed if implemented in fn_selfactions.sqf
  139. if (dayz_combat == 1) then {
  140. cutText ["Your currently in combat, time reduced to 3 seconds. \nCanceling/escaping will set you back into combat", "PLAIN DOWN"];
  141. sleep 3;
  142. _playerCombat setVariable["combattimeout", 0, true];
  143. dayz_combat = 0;
  144. };
  145. r_interrupt = false;
  146. r_doLoop = true;
  147. procBuild = true;
  148. //Global build_list reference params:
  149. //[_qtyT, _qtyS, _qtyW, _qtyL, _qtyM, _qtyG], "Classname", [_attachCoords, _toolBox, _eTool, _medWait, _longWait, _inBuilding, _roadAllowed, _inTown];
  150. call gear_ui_init;
  151. // Count mags in player inventory and add to an array
  152. _mags = magazines player;
  153. if ("ItemTankTrap" in _mags) then {
  154. _qtyT = {_x == "ItemTankTrap"} count magazines player;
  155. _buildables set [count _buildables, _qtyT];
  156. _itemT = "ItemTankTrap";
  157. } else { _qtyT = 0; _buildables set [count _buildables, _qtyT]; };
  158.  
  159. if ("ItemSandbag" in _mags) then {
  160. _qtyS = {_x == "ItemSandbag"} count magazines player;
  161. _buildables set [count _buildables, _qtyS];
  162. _itemS = "ItemSandbag";
  163. } else { _qtyS = 0; _buildables set [count _buildables, _qtyS]; };
  164.  
  165. if ("ItemWire" in _mags) then {
  166. _qtyW = {_x == "ItemWire"} count magazines player;
  167. _buildables set [count _buildables, _qtyW];
  168. _itemW = "ItemWire";
  169. } else { _qtyW = 0; _buildables set [count _buildables, _qtyW]; };
  170.  
  171. if ("PartWoodPile" in _mags) then {
  172. _qtyL = {_x == "PartWoodPile"} count magazines player;
  173. _buildables set [count _buildables, _qtyL];
  174. _itemL = "PartWoodPile";
  175. } else { _qtyL = 0; _buildables set [count _buildables, _qtyL]; };
  176.  
  177. if ("PartGeneric" in _mags) then {
  178. _qtyM = {_x == "PartGeneric"} count magazines player;
  179. _buildables set [count _buildables, _qtyM];
  180. _itemM = "PartGeneric";
  181. } else { _qtyM = 0; _buildables set [count _buildables, _qtyM]; };
  182.  
  183. if ("HandGrenade_West" in _mags) then {
  184. _qtyG = {_x == "HandGrenade_West"} count magazines player;
  185. _buildables set [count _buildables, _qtyG];
  186. _itemG = "HandGrenade_West";
  187. } else { _qtyG = 0; _buildables set [count _buildables, _qtyG]; };
  188.  
  189. /*-- Add another item for recipe here by changing _qtyI, "Item_Classname", and add recipe into build_list.sqf array!
  190. Dont forget to add recipe to recipelist so your players can know how to make object via recipe
  191. // if ("Item_Classname" in _mags) then {
  192. // _qtyI = {_x == "Item_Classname"} count magazines player;
  193. // _buildables set [count _buildables, _qtyI];
  194. // _itemG = "Item_Classname";
  195. // } else { _qtyI = 0; _buildables set [count _buildables, _qtyI]; };
  196. */
  197.  
  198. // Check what object is returned from global array, then return classname
  199. for "_i" from 0 to ((count allbuildables) - 1) do
  200. {
  201. _buildable = (allbuildables select _i) select _i - _i;
  202. _result = [_buildables,_buildable] call BIS_fnc_areEqual;
  203. if (_result) exitWith {
  204. _classname = (allbuildables select _i) select _i - _i + 1;
  205. _requirements = (allbuildables select _i) select _i - _i + 2;
  206. _chosenRecipe = _buildable;
  207. };
  208. _buildable = [];
  209. };
  210. // Quit here if no proper recipe is acquired else set names properly
  211. if (_classname == "") then {cutText ["You need the EXACT amount of whatever you are trying to build without extras.", "PLAIN DOWN"];call _funcExitScript;};
  212. if (_classname == "Grave") then {_text = "Booby Trap";};
  213. if (_classname == "Concrete_Wall_EP1") then {_text = "Gate Concrete Wall";};
  214. if (_classname == "Infostand_2_EP1") then {_text = "Gate Panel Keypad Access";};
  215. if (_classname != "Infostand_2_EP1" &&
  216. _classname != "Concrete_Wall_EP1" &&
  217. _classname != "Grave") then {
  218. //_text = _classname;
  219. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  220. };
  221. _buildable = [];
  222.  
  223. //Get Requirements from build_list.sqf global array [_attachCoords, _startPos, _modDir, _toolBox, _eTool, _medWait, _longWait, _inBuilding, _roadAllowed, _inTown];
  224. _attachCoords = _requirements select 0;
  225. _startPos = _requirements select 1;
  226. _modDir = _requirements select 2;
  227. _toolBox = _requirements select 3;
  228. _eTool = _requirements select 4;
  229. _medWait = _requirements select 5;
  230. _longWait = _requirements select 6;
  231. _inBuilding = _requirements select 7;
  232. _roadAllowed = _requirements select 8;
  233. _inTown = _requirements select 9;
  234. _isSimulated = _requirements select 12;
  235. _isDestrutable = _requirements select 13;
  236. // Get _startPos for object
  237. _location = player modeltoworld _startPos;
  238.  
  239. //Check Requirements
  240. if (_toolBox) then {
  241. if (!_hasToolbox) then {cutText [format["You need a tool box to build %1",_text], "PLAIN DOWN",1];call _funcExitScript; };
  242. };
  243. if (_eTool) then {
  244. if (!_hasEtool) then {cutText [format["You need an entrenching tool to build %1",_text], "PLAIN DOWN",1];call _funcExitScript; };
  245. };
  246. if (_inBuilding) then {
  247. if (_isOk) then {cutText [format["%1 cannot be built inside of buildings!",_text], "PLAIN DOWN",1];call _funcExitScript; };
  248. };
  249. if (!_roadAllowed) then { // Do another check for object being on road
  250. _onRoad = isOnRoad _locationPlayer;
  251. if(_onRoad) then {cutText [format["You cannot build %1 on the road",_text], "PLAIN DOWN",1];call _funcExitScript;};
  252. };
  253. if (!_inTown) then {
  254. for "_i" from 0 to ((count allbuild_notowns) - 1) do
  255. {
  256. _check_town = (allbuild_notowns select _i) select _i - _i;
  257. if (_town_name == _check_town) then {
  258. _townRange = (allbuild_notowns select _i) select _i - _i + 1;
  259. if (_locationPlayer distance _town_pos <= _townRange) then {
  260. cutText [format["You cannot build %1 within %2 meters of area %3",_text, _townRange, _town_name], "PLAIN DOWN",1];call _funcExitScript;
  261. };
  262. };
  263. };
  264. };
  265.  
  266. /*//Check if other panels nearby
  267. _panelNearest2 = nearestObjects [player, ["Infostand_2_EP1"], 300];
  268. if (_classname == "Infostand_2_EP1" && (count _panelNearest2 > 1)) then {cutText ["Only 2 gate panels per base in a 300 meter radius!", "PLAIN DOWN"];call _funcExitScript;};
  269. */
  270. // Begin building process
  271. _buildCheck = false;
  272. _buildReady = false;
  273. player allowdamage false;
  274. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  275. _object setDir (getDir player);
  276. if (_modDir > 0) then {
  277. _object setDir (getDir player) + _modDir;
  278. };
  279. player allowdamage true;
  280. hint "";
  281. cutText ["-Build process started. Move around to re-position\n-Stay still to begin build timer", "PLAIN DOWN", 10];
  282. while {!_buildReady} do {
  283. hintsilent "-Build process started. \n-Move around to re-position\n-Stay still to begin build timer";
  284. _playerCombat = player;
  285. _isInCombat = _playerCombat getVariable["startcombattimer",0];
  286. _dialog = findDisplay 106;
  287. if ((speed player < 9 && speed player > 0) || (speed player > -7 && speed player < 0)) then {
  288. _object attachto [player, _attachCoords];
  289. _object setDir (getDir player) + _modDir;
  290. _inProgress = true;
  291. } else {
  292. if (_inProgress) then {
  293. detach _object;
  294. sleep 0.03;
  295. _location = getposATL _object;
  296. _dir = getDir _object;
  297. _object setpos [(getposATL _object select 0),(getposATL _object select 1), 0];
  298. _cntLoop = 50;
  299. _inProgress = false;
  300. while {speed player == 0 && !_buildReady} do {
  301. sleep 0.1;
  302. if (_cntLoop <= 100 && _cntLoop % 10 == 0) then {
  303. cutText [format["Building of %1 starts in %2 seconds. Move to restart timer and position",_text, (_cntLoop / 10)], "PLAIN DOWN",1];
  304. };
  305. // Cancel build if rules broken
  306. _isInCombat = _playerCombat getVariable["startcombattimer",0];
  307. _dialog = findDisplay 106;
  308. if ((!(isNull _dialog) || _isInCombat > 0) && (isPlayer _playerCombat) ) then {
  309. detach _object;
  310. deletevehicle _object;
  311. cutText [format["Build canceled for %1. Player in combat or opened gear.",_text], "PLAIN DOWN",1];call _funcExitScript;
  312. if (!_roadAllowed) then { // Check object being placed on road
  313. _onRoad = isOnRoad getposATL(_object);
  314. if(_onRoad) then {cutText [format["You cannot build %1 on the road",_text], "PLAIN DOWN",1];call _funcExitScript;};
  315. };
  316. };
  317. _cntLoop = _cntLoop - 1;
  318. if (_cntLoop <= 0) then {
  319. _buildReady = true;
  320. _cntLoop = 0;
  321. };
  322. };
  323. };
  324. };
  325. // Cancel build if rules broken
  326. if ((!(isNull _dialog) || (speed player > 9 || speed player < -7) || _isInCombat > 0) && (isPlayer _playerCombat) ) then {
  327. detach _object;
  328. deletevehicle _object;
  329. cutText [format["Build canceled for %1. Player moving too fast, in combat or opened gear.",_text], "PLAIN DOWN",1];call _funcExitScript;
  330. };
  331. sleep 0.03;
  332. };
  333. if (_buildReady) then {
  334. cutText [format["Building beginning for %1.",_text], "PLAIN DOWN",1];
  335. } else {cutText [format["Build canceled for %1. Something went wrong!",_text], "PLAIN DOWN",1];call _funcExitScript;};
  336. // Begin Building
  337. //Do quick check to see if player is not playing nice after placing object
  338. _locationPlayer = player modeltoworld [0,0,0];
  339. _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  340. _canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); //USE!!
  341. _isWater = (surfaceIsWater _locationPlayer) or dayz_isSwimming;
  342. _inVehicle = (vehicle player != player);
  343. _isOk = [player,_building] call fnc_isInsideBuilding;
  344. if (_inBuilding) then {
  345. if (_isOk) then {deletevehicle _object; cutText [format["%1 cannot be built inside of buildings!",_text], "PLAIN DOWN",1];call _funcExitScript; };
  346. };
  347. // Did player walk object into restricted town?
  348. _closestTown = (nearestLocations [player,["NameCityCapital","NameCity","NameVillage"],25600]) select 0;
  349. _town_name = text _closestTown;
  350. _town_pos = position _closestTown;
  351. if (!_inTown) then {
  352. for "_i" from 0 to ((count allbuild_notowns) - 1) do
  353. {
  354. _check_town = (allbuild_notowns select _i) select _i - _i;
  355. if (_town_name == _check_town) then {
  356. _townRange = (allbuild_notowns select _i) select _i - _i + 1;
  357. if (_locationPlayer distance _town_pos <= _townRange) then {
  358. deletevehicle _object; cutText [format["You cannot build %1 within %2 meters of area %3",_text, _townRange, _town_name], "PLAIN DOWN",1];call _funcExitScript;
  359. };
  360. };
  361. };
  362. };
  363.  
  364. r_interrupt = false;
  365. r_doLoop = true;
  366. _cntLoop = 0;
  367. //Physically begin building
  368. switch (true) do
  369. {
  370. case(_longWait):
  371. {
  372. _cnt = _longWloop;
  373. _cnt = _cnt * 10;
  374. for "_i" from 0 to _longWloop do
  375. {
  376. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  377. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  378. if (!_canDo || _onLadder || _inVehicle || _isWater) then {deletevehicle _object; cutText [format["Build canceled for %1, player is unable to continue",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  379. player playActionNow "Medic";
  380. sleep 1;
  381. [player,"repair",0,false] call dayz_zombieSpeak;
  382. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  383. //DayZ interrupt feature like when canceling bandaging
  384. while {r_doLoop} do {
  385. if (r_interrupt) then {
  386. r_doLoop = false;
  387. };
  388. if (_cntLoop >= 100) then {
  389. r_doLoop = false;
  390. _finished = true;
  391. };
  392. sleep .1;
  393. _cntLoop = _cntLoop + 1;
  394. };
  395. if (r_interrupt) then {
  396. deletevehicle _object;
  397. [objNull, player, rSwitchMove,""] call RE;
  398. player playActionNow "stop";
  399. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  400. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  401. breakOut "exit";
  402. };
  403. r_doLoop = true;
  404. _cntLoop = 0;
  405. _cnt = _cnt - 10;
  406. };
  407. sleep 1.5;
  408. };
  409. case(_medWait):
  410. {
  411. _cnt = _medWloop;
  412. _cnt = _cnt * 10;
  413. for "_i" from 0 to _medWloop do
  414. {
  415. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  416. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  417. if (!_canDo || _onLadder || _inVehicle || _isWater) then {deletevehicle _object; cutText [format["Build canceled for %1, player is unable to continue",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  418. player playActionNow "Medic";
  419. sleep 1;
  420. [player,"repair",0,false] call dayz_zombieSpeak;
  421. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  422. while {r_doLoop} do {
  423. if (r_interrupt) then {
  424. r_doLoop = false;
  425. };
  426. if (_cntLoop >= 100) then {
  427. r_doLoop = false;
  428. _finished = true;
  429. };
  430. sleep .1;
  431. _cntLoop = _cntLoop + 1;
  432. };
  433. if (r_interrupt) then {
  434. deletevehicle _object;
  435. [objNull, player, rSwitchMove,""] call RE;
  436. player playActionNow "stop";
  437. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  438. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  439. breakOut "exit";
  440. };
  441. r_doLoop = true;
  442. _cntLoop = 0;
  443. _cnt = _cnt - 10;
  444. };
  445. sleep 1.5;
  446. };
  447. case(!_medWait && !_longWait):
  448. {
  449. _cnt = _smallWloop;
  450. _cnt = _cnt * 10;
  451. for "_i" from 0 to _smallWloop do
  452. {
  453. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  454. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  455. if (!_canDo || _onLadder || _inVehicle || _isWater) then {deletevehicle _object; cutText [format["Build canceled for %1, player is unable to continue",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  456. player playActionNow "Medic";
  457. sleep 1;
  458. [player,"repair",0,false] call dayz_zombieSpeak;
  459. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  460. while {r_doLoop} do {
  461. if (r_interrupt) then {
  462. r_doLoop = false;
  463. };
  464. if (_cntLoop >= 100) then {
  465. r_doLoop = false;
  466. _finished = true;
  467. };
  468. sleep .1;
  469. _cntLoop = _cntLoop + 1;
  470. };
  471. if (r_interrupt) then {
  472. deletevehicle _object;
  473. [objNull, player, rSwitchMove,""] call RE;
  474. player playActionNow "stop";
  475. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  476. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  477. breakOut "exit";
  478. };
  479. r_doLoop = true;
  480. _cntLoop = 0;
  481. _cnt = _cnt - 10;
  482. };
  483. sleep 1.5;
  484. };
  485. };
  486. // Do last check to see if player attempted to remvoe buildables
  487. _mags = magazines player;
  488. _buildables = []; // reset original buildables
  489. if ("ItemTankTrap" in _mags) then {
  490. _qtyT = {_x == "ItemTankTrap"} count magazines player;
  491. _buildables set [count _buildables, _qtyT];
  492. } else { _qtyT = 0; _buildables set [count _buildables, _qtyT]; };
  493.  
  494. if ("ItemSandbag" in _mags) then {
  495. _qtyS = {_x == "ItemSandbag"} count magazines player;
  496. _buildables set [count _buildables, _qtyS];
  497. } else { _qtyS = 0; _buildables set [count _buildables, _qtyS]; };
  498.  
  499. if ("ItemWire" in _mags) then {
  500. _qtyW = {_x == "ItemWire"} count magazines player;
  501. _buildables set [count _buildables, _qtyW];
  502. } else { _qtyW = 0; _buildables set [count _buildables, _qtyW]; };
  503.  
  504. if ("PartWoodPile" in _mags) then {
  505. _qtyL = {_x == "PartWoodPile"} count magazines player;
  506. _buildables set [count _buildables, _qtyL];
  507. } else { _qtyL = 0; _buildables set [count _buildables, _qtyL]; };
  508.  
  509. if ("PartGeneric" in _mags) then {
  510. _qtyM = {_x == "PartGeneric"} count magazines player;
  511. _buildables set [count _buildables, _qtyM];
  512. } else { _qtyM = 0; _buildables set [count _buildables, _qtyM]; };
  513.  
  514. if ("HandGrenade_West" in _mags) then {
  515. _qtyG = {_x == "HandGrenade_West"} count magazines player;
  516. _buildables set [count _buildables, _qtyG];
  517. } else { _qtyG = 0; _buildables set [count _buildables, _qtyG]; };
  518.  
  519. // Check if it matches again
  520. _result = [_buildables,_chosenRecipe] call BIS_fnc_areEqual;
  521.  
  522. if (_result) then {
  523. //Build final product!
  524. //_object setpos [((_object modeltoworld [0,0,0]) select 0),((_object modeltoworld [0,0,0]) select 1), 0];
  525. //_location = getposATL _object;
  526. //_dir = getDir _object;
  527. //Finish last requirement checks, _isSimulated disables objects physics if specified, _isDestructable checks if object needs to be invincible
  528. if (!_isSimulated) then {
  529. _object enablesimulation false;
  530. };
  531. if (!_isDestructable) then {
  532. _object addEventHandler ["HandleDamage", {false}];
  533. };
  534.  
  535. // set the codes for gate
  536. //--------------------------------
  537. /* Old Method
  538. _uidDir = _dir;
  539. _uidDir = round(_uidDir);
  540. _p1 = round(_location select 0);
  541. _p2 = round(_location select 1);
  542. //_p3 = round(_location select 2);
  543. _uid = format["%1,%2,%3",_p1,_p2,_uidDir];
  544. */
  545. // New Method
  546. _uidDir = _dir;
  547. _uidDir = round(_uidDir);
  548. _uid = "";
  549. {
  550. _x = _x * 10;
  551. if ( _x < 0 ) then { _x = _x * -10 };
  552. _uid = _uid + str(round(_x));
  553. } forEach _location;
  554. _uid = _uid + str(round(_dir));
  555.  
  556. // ------------------------------------------------------------------------kikyou2 Random Keycode Start---------------------------------------------------------------------
  557. _coder = random(9999); //generating random number between 0-9999
  558. if (_coder < 1000) then { //checks whether the number is < 1000
  559. _coder = _coder + 1000; //adds 1000 to the number if its < 1000 to make sure that the code will be 4 digits long
  560. };
  561. _code = round _coder; //remove all digits after comma
  562.  
  563. // ------------------------------------------------------------------------kikyou2 Random Keycode End-----------------------------------------------------------------------
  564.  
  565. //--------------------------------
  566.  
  567. switch (_classname) do
  568. {
  569. case "Grave":
  570. {
  571. cutText [format["You have constructed a %1, crawl away so you dont set it off!",_text], "PLAIN DOWN",1];
  572. _object setVariable ["isBomb", true];
  573. };
  574. case "Infostand_2_EP1":
  575. {
  576. cutText [format["You have constructed a %1, REMEMBER THIS PERMANENT KEYCODE: %2 . Make sure to build 2 (one in/one out) Key Panels as soon as possible to get both codes!",_text,_code], "PLAIN DOWN",60]; //Changed _uid to _code to show the right keycode
  577. };
  578. default {
  579. cutText [format["You have constructed a %1\n Keycode for object removal: %2 .\n",_text,_code], "PLAIN DOWN",60]; //Changed _uid to _code to show the right keycode
  580. //cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  581. };
  582. };
  583. //Remove required magazines
  584. if (_qtyT > 0) then {
  585. for "_i" from 0 to _qtyT do
  586. {
  587. player removeMagazine _itemT;
  588. };
  589. };
  590. if (_qtyS > 0) then {
  591. for "_i" from 0 to _qtyS do
  592. {
  593. player removeMagazine _itemS;
  594. };
  595. };
  596. if (_qtyW > 0) then {
  597. for "_i" from 0 to _qtyW do
  598. {
  599. player removeMagazine _itemW;
  600. };
  601. };
  602. if (_qtyL > 0) then {
  603. for "_i" from 0 to _qtyL do
  604. {
  605. player removeMagazine _itemL;
  606. };
  607. };
  608. if (_qtyM > 0) then {
  609. for "_i" from 0 to _qtyM do
  610. {
  611. player removeMagazine _itemM;
  612. };
  613. };
  614. //Grenade only is needed when building booby trap
  615. if (_qtyG > 0 && _classname == "Grave") then {
  616. for "_i" from 0 to _qtyG do
  617. {
  618. player removeMagazine _itemG;
  619. };
  620. };
  621. /*
  622. _distance = 30;
  623. _canBuildOnPlot = false;
  624. // check for near plot
  625. _findNearestPoles = nearestObjects [(vehicle player), ["Plastic_Pole_EP1_DZ"], _distance];
  626. _findNearestPole = [];
  627. {if (alive _x) then {_findNearestPole set [(count _findNearestPole),_x];};} foreach _findNearestPoles;
  628.  
  629. _IsNearPlot = count (_findNearestPole);
  630.  
  631. if(_IsNearPlot == 0) then {
  632.  
  633. // Allow building of plot
  634. if(_isPole) then {
  635. _canBuildOnPlot = true;
  636. };
  637.  
  638. } else {
  639. // Since there are plots nearby we check for ownership and then for friend status
  640.  
  641. _nearestPole = _findNearestPole select 0;
  642.  
  643. // Find owner
  644. _ownerID = _nearestPole getVariable["CharacterID","0"];
  645.  
  646. // diag_log format["DEBUG BUILDING: %1 = %2", dayz_characterID, _ownerID];
  647.  
  648. // check if friendly to owner
  649. if(dayz_playerUID == _ownerID) then {
  650. // owner can build anything within his plot except other plots
  651. if(!_isPole) then {
  652. _canBuildOnPlot = true;
  653. };
  654.  
  655. } else {
  656. // disallow building plot
  657. if(!_isPole) then {
  658. _friendlies = player getVariable ["friendlyTo",[]];
  659. // check if friendly to owner
  660. if(_ownerID in _friendlies) then {
  661. _canBuildOnPlot = true;
  662. };
  663. };
  664. };
  665.  
  666. };
  667.  
  668. // _message
  669. if(!_canBuildOnPlot) exitWith {deletevehicle _object; cutText ["Abusing not allowed, materials deleted" , "PLAIN DOWN"]; };
  670.  
  671. if (_inBuilding) then {
  672. if (_isOk) then {deletevehicle _object; cutText [format["Abusing not allowed, materials deleted",_text], "PLAIN DOWN",1];call _funcExitScript; };
  673. };
  674. // Did player walk object into restricted town?
  675. _closestTown = (nearestLocations [player,["NameCityCapital","NameCity","NameVillage"],25600]) select 0;
  676. _town_name = text _closestTown;
  677. _town_pos = position _closestTown;
  678. if (!_inTown) then {
  679. for "_i" from 0 to ((count allbuild_notowns) - 1) do
  680. {
  681. _check_town = (allbuild_notowns select _i) select _i - _i;
  682. if (_town_name == _check_town) then {
  683. _townRange = (allbuild_notowns select _i) select _i - _i + 1;
  684. if (_locationPlayer distance _town_pos <= _townRange) then {
  685. deletevehicle _object; cutText [format["You cannot build %1 within %2 meters of area %3",_text, _townRange, _town_name], "PLAIN DOWN",1];call _funcExitScript;
  686. };
  687. };
  688. };
  689. };
  690.  
  691. // testing new way of finding building
  692. _buildings = nearestObjects [(vehicle player), ["Building"], 100];
  693. {
  694. _isBuilding = [(vehicle player),_x] call fnc_isInsideBuilding;
  695. if(_isBuilding) exitWith {
  696. _cancel = true;
  697. _reason = "Abusing not allowed, materials deleted";
  698. };
  699. } forEach _buildings;
  700.  
  701. if (!_roadAllowed) then { // Check object being placed on road
  702. _onRoad = isOnRoad getposATL(_object);
  703. if(_onRoad) then {deletevehicle _object;cutText [format["You cannot build %1 on the road",_text], "PLAIN DOWN",1];call _funcExitScript;};
  704. };
  705.  
  706. if(_isWater) then {cutText ["Abusing not allowed, materials deleted" , "PLAIN DOWN"];deleteVehicle _object;call _funcExitScript;};
  707. if(_onLadder) then {cutText ["Abusing not allowed, materials deleted" , "PLAIN DOWN"];deleteVehicle _object;call _funcExitScript;};
  708. if (_inVehicle) then {cutText ["Abusing not allowed, materials deleted" , "PLAIN DOWN"];deleteVehicle _object;call _funcExitScript;};
  709. if (!placevault) then {cutText ["Abusing not allowed, materials deleted" , "PLAIN DOWN"];deleteVehicle _object;call _funcExitScript;};*/
  710.  
  711. // Send to database
  712. _fuel = _code / 1000; //added to calculate valid fuel value for the database
  713. _object setVariable ["characterID",dayz_playerUID,true];
  714. dayzPublishObj = [dayz_playerUID,_object,[_dir,_location],_classname,_fuel,_code]; //added _code to pass to the publishObj function to prevent calculation errors
  715. publicVariableServer "dayzPublishObj";
  716. if (isServer) then {
  717. dayzPublishObj call server_publishObj;
  718. };
  719.  
  720. } else {cutText ["You need the EXACT amount of whatever you are trying to build without extras.", "PLAIN DOWN"];call _funcExitScript;};
  721.  
  722. player allowdamage true;
  723. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement