Advertisement
Guest User

player_build.sqf

a guest
Oct 16th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.10 KB | None | 0 0
  1. /*
  2. Base Building DayZ by Daimyo
  3. */
  4. private["_funcExitScript","_playerCombat","_isSimulated","_isDestructable","_townRange","_longWloop","_medWloop","_smallWloop","_inTown","_inProgress","_modDir","_startPos","_tObjectPos","_buildable","_chosenRecipe","_cnt","_cntLoop","_dialog","_buildReady","_buildCheck","_isInCombat","_playerCombat","_check_town","_eTool","_toolBox","_town_pos","_town_name","_closestTown","_roadAllowed","_toolsNeeded","_inBuilding","_attachCoords","_requirements","_result","_alreadyBuilt","_uidDir","_p1","_p2","_uid","_worldspace","_panelNearest2","_staticObj","_onRoad","_itemL","_itemM","_itemG","_qtyL","_qtyM","_qtyG","_cntLoop","_finished","_checkComplete","_objectTemp","_locationPlayer","_object","_id","_isOk","_text","_mags","_hasEtool","_canDo","_hasToolbox","_inVehicle","_isWater","_onLadder","_building","_medWait","_longWait","_location","_isOk","_dir","_classname","_item","_itemT","_itemS","_itemW","_qtyT","_qtyS","_qtyW"];
  5.  
  6. // Location placement declarations
  7. _locationPlayer = player modeltoworld [0,0,0];
  8. _location = player modeltoworld [0,0,0]; // Used for object start location and to keep track of object position throughout
  9. _attachCoords = [0,0,0];
  10. _dir = getDir player;
  11. _building = nearestObject [player, "Building"];
  12. _staticObj = nearestObject [player, "Static"];
  13.  
  14. // Restriction Checks
  15. _hasEtool = "ItemEtool" in weapons player;
  16. _hasToolbox = "ItemToolbox" in items player;
  17. _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  18. _canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); //USE!!
  19. _isWater = (surfaceIsWater _locationPlayer) or dayz_isSwimming;
  20. _inVehicle = (vehicle player != player);
  21. _isOk = [player,_building] call fnc_isInsideBuilding;
  22. _closestTown = (nearestLocations [player,["NameCityCapital","NameCity","NameVillage","Airport"],25600]) select 0;
  23. _town_name = text _closestTown;
  24. _town_pos = position _closestTown;
  25.  
  26. // Booleans Some not used, possibly use later
  27. _roadAllowed = false;
  28. _medWait = false;
  29. _longWait = false;
  30. _checkComplete = false;
  31. _finished = false;
  32. _eTool = false;
  33. _toolBox = false;
  34. _alreadyBuilt = false;
  35. _inBuilding = false;
  36. _inTown = false;
  37. _inProgress = false;
  38. _result = false;
  39. _isSimulated = false;
  40. _isDestructable = false;
  41. // Strings
  42. _classname = "";
  43. _check_town = "";
  44.  
  45. // Other
  46. _cntLoop = 0;
  47. _chosenRecipe = [];
  48. _requirements = [];
  49. _buildable = [];
  50. _buildables = [];
  51. _longWloop = 2;
  52. _medWloop = 1;
  53. _smallWloop = 0;
  54. _cnt = 0;
  55. _playerCombat = player;
  56.  
  57. // Function to exit script without combat activate
  58. _funcExitScript = {
  59. procBuild = false;
  60. breakOut "exit";
  61. };
  62.  
  63. // Do first checks to see if player can build before counting
  64. if (procBuild) then {cutText ["Your already building!", "PLAIN DOWN"];breakOut "exit";};
  65. if(_isWater) then {cutText [localize "str_player_26", "PLAIN DOWN"];call _funcExitScript;};
  66. if(_onLadder) then {cutText [localize "str_player_21", "PLAIN DOWN"];call _funcExitScript;};
  67. if (_inVehicle) then {cutText ["Can't do this in vehicle", "PLAIN DOWN"];call _funcExitScript;};
  68. disableSerialization;
  69. closedialog 1;
  70. // Ashfor Fix: Did player try to drop mag and keep action active (not really needed but leave here just in case)
  71. //_item = _this;
  72. //if (_item in (magazines player) ) then { // needs };
  73. // Global variables for loop method, procBuild may not be needed if implemented in fn_selfactions.sqf
  74. if (dayz_combat == 1) then {
  75. cutText ["Your currently in combat, time reduced to 3 seconds. \nCanceling/escaping will set you back into combat", "PLAIN DOWN"];
  76. sleep 3;
  77. _playerCombat setVariable["combattimeout", 0, true];
  78. dayz_combat = 0;
  79. };
  80. r_interrupt = false;
  81. r_doLoop = true;
  82. procBuild = true;
  83. //Global build_list reference params:
  84. //[_qtyT, _qtyS, _qtyW, _qtyL, _qtyM, _qtyG], "Classname", [_attachCoords, _toolBox, _eTool, _medWait, _longWait, _inBuilding, _roadAllowed, _inTown];
  85. call gear_ui_init;
  86. // Count mags in player inventory and add to an array
  87. _mags = magazines player;
  88. if ("ItemTankTrap" in _mags) then {
  89. _qtyT = {_x == "ItemTankTrap"} count magazines player;
  90. _buildables set [count _buildables, _qtyT];
  91. _itemT = "ItemTankTrap";
  92. } else { _qtyT = 0; _buildables set [count _buildables, _qtyT]; };
  93.  
  94. if ("ItemSandbag" in _mags) then {
  95. _qtyS = {_x == "ItemSandbag"} count magazines player;
  96. _buildables set [count _buildables, _qtyS];
  97. _itemS = "ItemSandbag";
  98. } else { _qtyS = 0; _buildables set [count _buildables, _qtyS]; };
  99.  
  100. if ("ItemWire" in _mags) then {
  101. _qtyW = {_x == "ItemWire"} count magazines player;
  102. _buildables set [count _buildables, _qtyW];
  103. _itemW = "ItemWire";
  104. } else { _qtyW = 0; _buildables set [count _buildables, _qtyW]; };
  105. if ("PartWoodPile" in _mags) then {
  106. _qtyL = {_x == "PartWoodPile"} count magazines player;
  107. _buildables set [count _buildables, _qtyL];
  108. _itemL = "PartWoodPile";
  109. } else { _qtyL = 0; _buildables set [count _buildables, _qtyL]; };
  110.  
  111. if ("PartGeneric" in _mags) then {
  112. _qtyM = {_x == "PartGeneric"} count magazines player;
  113. _buildables set [count _buildables, _qtyM];
  114. _itemM = "PartGeneric";
  115. } else { _qtyM = 0; _buildables set [count _buildables, _qtyM]; };
  116.  
  117. if ("HandGrenade_West" in _mags) then {
  118. _qtyG = {_x == "HandGrenade_West"} count magazines player;
  119. _buildables set [count _buildables, _qtyG];
  120. _itemG = "HandGrenade_West";
  121. } else { _qtyG = 0; _buildables set [count _buildables, _qtyG]; };
  122.  
  123. if ("ItemJerrycan" in _mags) then {
  124. _qtyJ = {_x == "ItemJerrycan"} count magazines player;
  125. _buildables set [count _buildables, _qtyJ];
  126. _itemJ = "ItemJerrycan";
  127. } else { _qtyJ = 0; _buildables set [count _buildables, _qtyJ]; };
  128. /*-- Add another item for recipe here by changing _qtyI, "Item_Classname", and add recipe into build_list.sqf array!
  129. Dont forget to add recipe to recipelist so your players can know how to make object via recipe
  130. // if ("Item_Classname" in _mags) then {
  131. // _qtyI = {_x == "Item_Classname"} count magazines player;
  132. // _buildables set [count _buildables, _qtyI];
  133. // _itemG = "Item_Classname";
  134. // } else { _qtyI = 0; _buildables set [count _buildables, _qtyI]; };
  135. */
  136.  
  137. // Check what object is returned from global array, then return classname
  138. for "_i" from 0 to ((count allbuildables) - 1) do
  139. {
  140. _buildable = (allbuildables select _i) select _i - _i;
  141. _result = [_buildables,_buildable] call BIS_fnc_areEqual;
  142. if (_result) exitWith {
  143. _classname = (allbuildables select _i) select _i - _i + 1;
  144. _requirements = (allbuildables select _i) select _i - _i + 2;
  145. _chosenRecipe = _buildable;
  146. };
  147. _buildable = [];
  148. };
  149. // Quit here if no proper recipe is acquired else set names properly
  150. if (_classname == "") then {cutText ["You need the EXACT amount of whatever you are trying to build without extras.", "PLAIN DOWN"];call _funcExitScript;};
  151. if (_classname == "Grave") then {_text = "Booby Trap";};
  152. if (_classname == "Concrete_Wall_EP1") then {_text = "Gate Concrete Wall";};
  153. if (_classname == "Infostand_2_EP1") then {_text = "Gate Panel Keypad Access";};
  154. if (_classname != "Infostand_2_EP1" &&
  155. _classname != "Concrete_Wall_EP1" &&
  156. _classname != "Grave") then {
  157. //_text = _classname;
  158. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  159. };
  160. _buildable = [];
  161.  
  162. //Get Requirements from build_list.sqf global array [_attachCoords, _startPos, _modDir, _toolBox, _eTool, _medWait, _longWait, _inBuilding, _roadAllowed, _inTown];
  163. _attachCoords = _requirements select 0;
  164. _startPos = _requirements select 1;
  165. _modDir = _requirements select 2;
  166. _toolBox = _requirements select 3;
  167. _eTool = _requirements select 4;
  168. _medWait = _requirements select 5;
  169. _longWait = _requirements select 6;
  170. _inBuilding = _requirements select 7;
  171. _roadAllowed = _requirements select 8;
  172. _inTown = _requirements select 9;
  173. _isSimulated = _requirements select 12;
  174. _isDestrutable = _requirements select 13;
  175. // Get _startPos for object
  176. _location = player modeltoworld _startPos;
  177.  
  178. //Check Requirements
  179. if (_toolBox) then {
  180. if (!_hasToolbox) then {cutText [format["You need a tool box to build %1",_text], "PLAIN DOWN",1];call _funcExitScript; };
  181. };
  182. if (_eTool) then {
  183. if (!_hasEtool) then {cutText [format["You need an entrenching tool to build %1",_text], "PLAIN DOWN",1];call _funcExitScript; };
  184. };
  185. if (_inBuilding) then {
  186. if (_isOk) then {cutText [format["%1 cannot be built inside of buildings!",_text], "PLAIN DOWN",1];call _funcExitScript; };
  187. };
  188. if (!_roadAllowed) then { // Do another check for object being on road
  189. _onRoad = isOnRoad _locationPlayer;
  190. if(_onRoad) then {cutText [format["You cannot build %1 on the road",_text], "PLAIN DOWN",1];call _funcExitScript;};
  191. };
  192. if (!_inTown) then {
  193. for "_i" from 0 to ((count allbuild_notowns) - 1) do
  194. {
  195. _check_town = (allbuild_notowns select _i) select _i - _i;
  196. if (_town_name == _check_town) then {
  197. _townRange = (allbuild_notowns select _i) select _i - _i + 1;
  198. if (_locationPlayer distance _town_pos <= _townRange) then {
  199. cutText [format["You cannot build %1 within %2 meters of area %3",_text, _townRange, _town_name], "PLAIN DOWN",1];call _funcExitScript;
  200. };
  201. };
  202. };
  203. };
  204.  
  205. //Check if other panels nearby
  206. _panelNearest2 = nearestObjects [player, ["Infostand_2_EP1"], 300];
  207. 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;};
  208.  
  209. // Begin building process
  210. _buildCheck = false;
  211. _buildReady = false;
  212. player allowdamage false;
  213. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  214. _object setDir (getDir player);
  215. if (_modDir > 0) then {
  216. _object setDir (getDir player) + _modDir;
  217. };
  218. player allowdamage true;
  219. hint "";
  220. cutText ["-Build process started. Move around to re-position\n-Stay still to begin build timer", "PLAIN DOWN", 10];
  221. while {!_buildReady} do {
  222. hintsilent "-Build process started. \n-Move around to re-position\n-Stay still to begin build timer";
  223. _playerCombat = player;
  224. _isInCombat = _playerCombat getVariable["startcombattimer",0];
  225. _dialog = findDisplay 106;
  226. if ((speed player < 9 && speed player > 0) || (speed player > -7 && speed player < 0)) then {
  227. _object attachto [player, _attachCoords];
  228. _object setDir (getDir player) + _modDir;
  229. _inProgress = true;
  230. } else {
  231. if (_inProgress) then {
  232. detach _object;
  233. sleep 0.03;
  234. _location = getposATL _object;
  235. _dir = getDir _object;
  236. _object setpos [(getposATL _object select 0),(getposATL _object select 1), 0];
  237. _location = _object modeltoworld [0,0,0];
  238. deletevehicle _object;
  239. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  240. _object setDir _dir;
  241. _object setpos [(getposATL _object select 0),(getposATL _object select 1), 0];
  242. _cntLoop = 50;
  243. _inProgress = false;
  244. while {speed player == 0 && !_buildReady} do {
  245. sleep 0.1;
  246. if (_cntLoop <= 100 && _cntLoop % 10 == 0) then {
  247. cutText [format["Building of %1 starts in %2 seconds. Move to restart timer and position",_text, (_cntLoop / 10)], "PLAIN DOWN",1];
  248. };
  249. // Cancel build if rules broken
  250. _isInCombat = _playerCombat getVariable["startcombattimer",0];
  251. _dialog = findDisplay 106;
  252. if ((!(isNull _dialog) || _isInCombat > 0) && (isPlayer _playerCombat) ) then {
  253. detach _object;
  254. deletevehicle _object;
  255. cutText [format["Build canceled for %1. Player in combat or opened gear.",_text], "PLAIN DOWN",1];call _funcExitScript;
  256. if (!_roadAllowed) then { // Check object being placed on road
  257. _onRoad = isOnRoad getposATL(_object);
  258. if(_onRoad) then {cutText [format["You cannot build %1 on the road",_text], "PLAIN DOWN",1];call _funcExitScript;};
  259. };
  260. };
  261. _cntLoop = _cntLoop - 1;
  262. if (_cntLoop <= 0) then {
  263. _buildReady = true;
  264. _cntLoop = 0;
  265. };
  266. };
  267. };
  268. };
  269. // Cancel build if rules broken
  270. if ((!(isNull _dialog) || (speed player > 9 || speed player < -7) || _isInCombat > 0) && (isPlayer _playerCombat) ) then {
  271. detach _object;
  272. deletevehicle _object;
  273. cutText [format["Build canceled for %1. Player moving too fast, in combat or opened gear.",_text], "PLAIN DOWN",1];call _funcExitScript;
  274. };
  275. sleep 0.03;
  276. };
  277. if (_buildReady) then {
  278. cutText [format["Building beginning for %1.",_text], "PLAIN DOWN",1];
  279. } else {cutText [format["Build canceled for %1. Something went wrong!",_text], "PLAIN DOWN",1];call _funcExitScript;};
  280. // Begin Building
  281. //Do quick check to see if player is not playing nice after placing object
  282. _locationPlayer = player modeltoworld [0,0,0];
  283. _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  284. _canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); //USE!!
  285. _isWater = (surfaceIsWater _locationPlayer) or dayz_isSwimming;
  286. _inVehicle = (vehicle player != player);
  287. _isOk = [player,_building] call fnc_isInsideBuilding;
  288. if (_inBuilding) then {
  289. if (_isOk) then {deletevehicle _object; cutText [format["%1 cannot be built inside of buildings!",_text], "PLAIN DOWN",1];call _funcExitScript; };
  290. };
  291. // Did player walk object into restricted town?
  292. _closestTown = (nearestLocations [player,["NameCityCapital","NameCity","NameVillage"],25600]) select 0;
  293. _town_name = text _closestTown;
  294. _town_pos = position _closestTown;
  295. if (!_inTown) then {
  296. for "_i" from 0 to ((count allbuild_notowns) - 1) do
  297. {
  298. _check_town = (allbuild_notowns select _i) select _i - _i;
  299. if (_town_name == _check_town) then {
  300. _townRange = (allbuild_notowns select _i) select _i - _i + 1;
  301. if (_locationPlayer distance _town_pos <= _townRange) then {
  302. deletevehicle _object; cutText [format["You cannot build %1 within %2 meters of area %3",_text, _townRange, _town_name], "PLAIN DOWN",1];call _funcExitScript;
  303. };
  304. };
  305. };
  306. };
  307.  
  308. r_interrupt = false;
  309. r_doLoop = true;
  310. _cntLoop = 0;
  311. //Physically begin building
  312. switch (true) do
  313. {
  314. case(_longWait):
  315. {
  316. _cnt = _longWloop;
  317. _cnt = _cnt * 10;
  318. for "_i" from 0 to _longWloop do
  319. {
  320. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  321. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  322. 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;};
  323. player playActionNow "Medic";
  324. sleep 1;
  325. [player,"repair",0,false] call dayz_zombieSpeak;
  326. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  327. //DayZ interrupt feature like when canceling bandaging
  328. while {r_doLoop} do {
  329. if (r_interrupt) then {
  330. r_doLoop = false;
  331. };
  332. if (_cntLoop >= 100) then {
  333. r_doLoop = false;
  334. _finished = true;
  335. };
  336. sleep .1;
  337. _cntLoop = _cntLoop + 1;
  338. };
  339. if (r_interrupt) then {
  340. deletevehicle _object;
  341. [objNull, player, rSwitchMove,""] call RE;
  342. player playActionNow "stop";
  343. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  344. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  345. breakOut "exit";
  346. };
  347. r_doLoop = true;
  348. _cntLoop = 0;
  349. _cnt = _cnt - 10;
  350. };
  351. sleep 1.5;
  352. };
  353. case(_medWait):
  354. {
  355. _cnt = _medWloop;
  356. _cnt = _cnt * 10;
  357. for "_i" from 0 to _medWloop do
  358. {
  359. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  360. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  361. 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;};
  362. player playActionNow "Medic";
  363. sleep 1;
  364. [player,"repair",0,false] call dayz_zombieSpeak;
  365. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  366. while {r_doLoop} do {
  367. if (r_interrupt) then {
  368. r_doLoop = false;
  369. };
  370. if (_cntLoop >= 100) then {
  371. r_doLoop = false;
  372. _finished = true;
  373. };
  374. sleep .1;
  375. _cntLoop = _cntLoop + 1;
  376. };
  377. if (r_interrupt) then {
  378. deletevehicle _object;
  379. [objNull, player, rSwitchMove,""] call RE;
  380. player playActionNow "stop";
  381. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  382. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  383. breakOut "exit";
  384. };
  385. r_doLoop = true;
  386. _cntLoop = 0;
  387. _cnt = _cnt - 10;
  388. };
  389. sleep 1.5;
  390. };
  391. case(!_medWait && !_longWait):
  392. {
  393. _cnt = _smallWloop;
  394. _cnt = _cnt * 10;
  395. for "_i" from 0 to _smallWloop do
  396. {
  397. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  398. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  399. 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;};
  400. player playActionNow "Medic";
  401. sleep 1;
  402. [player,"repair",0,false] call dayz_zombieSpeak;
  403. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  404. while {r_doLoop} do {
  405. if (r_interrupt) then {
  406. r_doLoop = false;
  407. };
  408. if (_cntLoop >= 100) then {
  409. r_doLoop = false;
  410. _finished = true;
  411. };
  412. sleep .1;
  413. _cntLoop = _cntLoop + 1;
  414. };
  415. if (r_interrupt) then {
  416. deletevehicle _object;
  417. [objNull, player, rSwitchMove,""] call RE;
  418. player playActionNow "stop";
  419. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  420. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  421. breakOut "exit";
  422. };
  423. r_doLoop = true;
  424. _cntLoop = 0;
  425. _cnt = _cnt - 10;
  426. };
  427. sleep 1.5;
  428. };
  429. };
  430. // Do last check to see if player attempted to remvoe buildables
  431. _mags = magazines player;
  432. _buildables = []; // reset original buildables
  433. if ("ItemTankTrap" in _mags) then {
  434. _qtyT = {_x == "ItemTankTrap"} count magazines player;
  435. _buildables set [count _buildables, _qtyT];
  436. } else { _qtyT = 0; _buildables set [count _buildables, _qtyT]; };
  437.  
  438. if ("ItemSandbag" in _mags) then {
  439. _qtyS = {_x == "ItemSandbag"} count magazines player;
  440. _buildables set [count _buildables, _qtyS];
  441. } else { _qtyS = 0; _buildables set [count _buildables, _qtyS]; };
  442.  
  443. if ("ItemWire" in _mags) then {
  444. _qtyW = {_x == "ItemWire"} count magazines player;
  445. _buildables set [count _buildables, _qtyW];
  446. } else { _qtyW = 0; _buildables set [count _buildables, _qtyW]; };
  447. if ("PartWoodPile" in _mags) then {
  448. _qtyL = {_x == "PartWoodPile"} count magazines player;
  449. _buildables set [count _buildables, _qtyL];
  450. } else { _qtyL = 0; _buildables set [count _buildables, _qtyL]; };
  451.  
  452. if ("PartGeneric" in _mags) then {
  453. _qtyM = {_x == "PartGeneric"} count magazines player;
  454. _buildables set [count _buildables, _qtyM];
  455. } else { _qtyM = 0; _buildables set [count _buildables, _qtyM]; };
  456.  
  457. if ("HandGrenade_West" in _mags) then {
  458. _qtyG = {_x == "HandGrenade_West"} count magazines player;
  459. _buildables set [count _buildables, _qtyG];
  460. } else { _qtyG = 0; _buildables set [count _buildables, _qtyG]; };
  461.  
  462. if ("ItemJerrycan" in _mags) then {
  463. _qtyJ = {_x == "ItemJerrycan"} count magazines player;
  464. _buildables set [count _buildables, _qtyJ];
  465. _itemJ = "ItemJerrycan";
  466. } else { _qtyJ = 0; _buildables set [count _buildables, _qtyJ]; };
  467. // Check if it matches again
  468. _result = [_buildables,_chosenRecipe] call BIS_fnc_areEqual;
  469.  
  470. if (_result) then {
  471. //Build final product!
  472. //_object setpos [((_object modeltoworld [0,0,0]) select 0),((_object modeltoworld [0,0,0]) select 1), 0];
  473. //_location = getposATL _object;
  474. //_dir = getDir _object;
  475. //Finish last requirement checks, _isSimulated disables objects physics if specified, _isDestructable checks if object needs to be invincible
  476. if (!_isSimulated) then {
  477. _object enablesimulation false;
  478. };
  479. if (!_isDestructable) then {
  480. _object addEventHandler ["HandleDamage", {false}];
  481. };
  482.  
  483.  
  484. // set the codes for gate
  485. //--------------------------------
  486. /* Old Method
  487. _uidDir = _dir;
  488. _uidDir = round(_uidDir);
  489. _p1 = round(_location select 0);
  490. _p2 = round(_location select 1);
  491. //_p3 = round(_location select 2);
  492. _uid = format["%1,%2,%3",_p1,_p2,_uidDir];
  493. */
  494. // New Method
  495. _uidDir = _dir;
  496. _uidDir = round(_uidDir);
  497. _uid = "";
  498. {
  499. _x = _x * 10;
  500. if ( _x < 0 ) then { _x = _x * -10 };
  501. _uid = _uid + str(round(_x));
  502. } forEach _location;
  503. _uid = _uid + str(round(_dir));
  504.  
  505. //--------------------------------
  506.  
  507. switch (_classname) do
  508. {
  509. case "Grave":
  510. {
  511. cutText [format["You have constructed a %1, crawl away so you dont set it off!",_text], "PLAIN DOWN",1];
  512. _object setVariable ["isBomb", true];
  513. };
  514. case "Infostand_2_EP1":
  515. {
  516. 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,_uid], "PLAIN DOWN",60];
  517. };
  518. default {
  519. cutText [format["You have constructed a %1\n Keycode for object removal: %2 .\n",_text,_uid], "PLAIN DOWN",60];
  520. //cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  521. };
  522. };
  523. //Remove required magazines
  524. if (_qtyT > 0) then {
  525. for "_i" from 0 to _qtyT do
  526. {
  527. player removeMagazine _itemT;
  528. };
  529. };
  530. if (_qtyS > 0) then {
  531. for "_i" from 0 to _qtyS do
  532. {
  533. player removeMagazine _itemS;
  534. };
  535. };
  536. if (_qtyW > 0) then {
  537. for "_i" from 0 to _qtyW do
  538. {
  539. player removeMagazine _itemW;
  540. };
  541. };
  542. if (_qtyL > 0) then {
  543. for "_i" from 0 to _qtyL do
  544. {
  545. player removeMagazine _itemL;
  546. };
  547. };
  548. if (_qtyM > 0) then {
  549. for "_i" from 0 to _qtyM do
  550. {
  551. player removeMagazine _itemM;
  552. };
  553. };
  554. //Grenade only is needed when building booby trap
  555. if (_qtyG > 0 && _classname == "Grave") then {
  556. for "_i" from 0 to _qtyG do
  557. {
  558. player removeMagazine _itemG;
  559. };
  560. };
  561. if (_qtyJ > 0 ) then {
  562.  
  563. for "_i" from 0 to _qtyJ do
  564. {
  565. player removeMagazine _itemJ;
  566. };
  567. };
  568.  
  569. // Send to database
  570. _object setVariable ["characterID",dayz_characterID,true];
  571. dayzPublishObj = [dayz_characterID,_object,[_dir,_location],_classname];
  572. publicVariableServer "dayzPublishObj";
  573. if (isServer) then {
  574. dayzPublishObj call server_publishObj;
  575. };
  576. } else {cutText ["You need the EXACT amount of whatever you are trying to build without extras.", "PLAIN DOWN"];call _funcExitScript;};
  577.  
  578. player allowdamage true;
  579. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement