Advertisement
Guest User

player_build

a guest
Jul 13th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.57 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. /*-- Add another item for recipe here by changing _qtyI, "Item_Classname", and add recipe into build_list.sqf array!
  124. Dont forget to add recipe to recipelist so your players can know how to make object via recipe
  125. // if ("Item_Classname" in _mags) then {
  126. // _qtyI = {_x == "Item_Classname"} count magazines player;
  127. // _buildables set [count _buildables, _qtyI];
  128. // _itemG = "Item_Classname";
  129. // } else { _qtyI = 0; _buildables set [count _buildables, _qtyI]; };
  130. */
  131.  
  132. // Check what object is returned from global array, then return classname
  133. for "_i" from 0 to ((count allbuildables) - 1) do
  134. {
  135. _buildable = (allbuildables select _i) select _i - _i;
  136. _result = [_buildables,_buildable] call BIS_fnc_areEqual;
  137. if (_result) exitWith {
  138. _classname = (allbuildables select _i) select _i - _i + 1;
  139. _requirements = (allbuildables select _i) select _i - _i + 2;
  140. _chosenRecipe = _buildable;
  141. };
  142. _buildable = [];
  143. };
  144. // Quit here if no proper recipe is acquired else set names properly
  145. if (_classname == "") then {cutText ["You need the EXACT amount of whatever you are trying to build without extras.", "PLAIN DOWN"];call _funcExitScript;};
  146. if (_classname == "Grave") then {_text = "Booby Trap";};
  147. if (_classname == "Concrete_Wall_EP1") then {_text = "Gate Concrete Wall";};
  148. if (_classname == "Infostand_2_EP1") then {_text = "Gate Panel Keypad Access";};
  149. if (_classname != "Infostand_2_EP1" &&
  150. _classname != "Concrete_Wall_EP1" &&
  151. _classname != "Grave") then {
  152. //_text = _classname;
  153. _text = getText (configFile >> "CfgVehicles" >> _classname >> "displayName");
  154. };
  155. _buildable = [];
  156.  
  157. //Get Requirements from build_list.sqf global array [_attachCoords, _startPos, _modDir, _toolBox, _eTool, _medWait, _longWait, _inBuilding, _roadAllowed, _inTown];
  158. _attachCoords = _requirements select 0;
  159. _startPos = _requirements select 1;
  160. _modDir = _requirements select 2;
  161. _toolBox = _requirements select 3;
  162. _eTool = _requirements select 4;
  163. _medWait = _requirements select 5;
  164. _longWait = _requirements select 6;
  165. _inBuilding = _requirements select 7;
  166. _roadAllowed = _requirements select 8;
  167. _inTown = _requirements select 9;
  168. _isSimulated = _requirements select 12;
  169. _isDestrutable = _requirements select 13;
  170. // Get _startPos for object
  171. _location = player modeltoworld _startPos;
  172.  
  173. //Check Requirements
  174. if (_toolBox) then {
  175. if (!_hasToolbox) then {cutText [format["You need a tool box to build %1",_text], "PLAIN DOWN",1];call _funcExitScript; };
  176. };
  177. if (_eTool) then {
  178. if (!_hasEtool) then {cutText [format["You need an entrenching tool to build %1",_text], "PLAIN DOWN",1];call _funcExitScript; };
  179. };
  180. if (_inBuilding) then {
  181. if (_isOk) then {cutText [format["%1 cannot be built inside of buildings!",_text], "PLAIN DOWN",1];call _funcExitScript; };
  182. };
  183. if (!_roadAllowed) then { // Do another check for object being on road
  184. _onRoad = isOnRoad _locationPlayer;
  185. if(_onRoad) then {cutText [format["You cannot build %1 on the road",_text], "PLAIN DOWN",1];call _funcExitScript;};
  186. };
  187. if (!_inTown) then {
  188. for "_i" from 0 to ((count allbuild_notowns) - 1) do
  189. {
  190. _check_town = (allbuild_notowns select _i) select _i - _i;
  191. if (_town_name == _check_town) then {
  192. _townRange = (allbuild_notowns select _i) select _i - _i + 1;
  193. if (_locationPlayer distance _town_pos <= _townRange) then {
  194. cutText [format["You cannot build %1 within %2 meters of area %3",_text, _townRange, _town_name], "PLAIN DOWN",1];call _funcExitScript;
  195. };
  196. };
  197. };
  198. };
  199.  
  200. //Check if other panels nearby
  201. _panelNearest2 = nearestObjects [player, ["Infostand_2_EP1"], 300];
  202. 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;};
  203.  
  204. // Begin building process
  205. _buildCheck = false;
  206. _buildReady = false;
  207. player allowdamage false;
  208. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  209. _object setDir (getDir player);
  210. if (_modDir > 0) then {
  211. _object setDir (getDir player) + _modDir;
  212. };
  213. player allowdamage true;
  214. hint "";
  215. cutText ["-Build process started. Move around to re-position\n-Stay still to begin build timer", "PLAIN DOWN", 10];
  216. while {!_buildReady} do {
  217. hintsilent "-Build process started. \n-Move around to re-position\n-Stay still to begin build timer";
  218. _playerCombat = player;
  219. _isInCombat = _playerCombat getVariable["startcombattimer",0];
  220. _dialog = findDisplay 106;
  221. if ((speed player < 9 && speed player > 0) || (speed player > -7 && speed player < 0)) then {
  222. _object attachto [player, _attachCoords];
  223. _object setDir (getDir player) + _modDir;
  224. _inProgress = true;
  225. } else {
  226. if (_inProgress) then {
  227. detach _object;
  228. sleep 0.03;
  229. _location = getposATL _object;
  230. _dir = getDir _object;
  231. _object setpos [(getposATL _object select 0),(getposATL _object select 1), 0];
  232. _location = _object modeltoworld [0,0,0];
  233. deletevehicle _object;
  234. _object = createVehicle [_classname, _location, [], 0, "CAN_COLLIDE"];
  235. _object setDir _dir;
  236. _object setpos [(getposATL _object select 0),(getposATL _object select 1), 0];
  237. _cntLoop = 50;
  238. _inProgress = false;
  239. while {speed player == 0 && !_buildReady} do {
  240. sleep 0.1;
  241. if (_cntLoop <= 100 && _cntLoop % 10 == 0) then {
  242. cutText [format["Building of %1 starts in %2 seconds. Move to restart timer and position",_text, (_cntLoop / 10)], "PLAIN DOWN",1];
  243. };
  244. // Cancel build if rules broken
  245. _isInCombat = _playerCombat getVariable["startcombattimer",0];
  246. _dialog = findDisplay 106;
  247. if ((!(isNull _dialog) || _isInCombat > 0) && (isPlayer _playerCombat) ) then {
  248. detach _object;
  249. deletevehicle _object;
  250. cutText [format["Build canceled for %1. Player in combat or opened gear.",_text], "PLAIN DOWN",1];call _funcExitScript;
  251. if (!_roadAllowed) then { // Check object being placed on road
  252. _onRoad = isOnRoad getposATL(_object);
  253. if(_onRoad) then {cutText [format["You cannot build %1 on the road",_text], "PLAIN DOWN",1];call _funcExitScript;};
  254. };
  255. };
  256. _cntLoop = _cntLoop - 1;
  257. if (_cntLoop <= 0) then {
  258. _buildReady = true;
  259. _cntLoop = 0;
  260. };
  261. };
  262. };
  263. };
  264. // Cancel build if rules broken
  265. if ((!(isNull _dialog) || (speed player > 9 || speed player < -7) || _isInCombat > 0) && (isPlayer _playerCombat) ) then {
  266. detach _object;
  267. deletevehicle _object;
  268. cutText [format["Build canceled for %1. Player moving too fast, in combat or opened gear.",_text], "PLAIN DOWN",1];call _funcExitScript;
  269. };
  270. sleep 0.03;
  271. };
  272. if (_buildReady) then {
  273. cutText [format["Building beginning for %1.",_text], "PLAIN DOWN",1];
  274. } else {cutText [format["Build canceled for %1. Something went wrong!",_text], "PLAIN DOWN",1];call _funcExitScript;};
  275. // Begin Building
  276. //Do quick check to see if player is not playing nice after placing object
  277. _locationPlayer = player modeltoworld [0,0,0];
  278. _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  279. _canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder); //USE!!
  280. _isWater = (surfaceIsWater _locationPlayer) or dayz_isSwimming;
  281. _inVehicle = (vehicle player != player);
  282. _isOk = [player,_building] call fnc_isInsideBuilding;
  283. if (_inBuilding) then {
  284. if (_isOk) then {deletevehicle _object; cutText [format["%1 cannot be built inside of buildings!",_text], "PLAIN DOWN",1];call _funcExitScript; };
  285. };
  286. // Did player walk object into restricted town?
  287. _closestTown = (nearestLocations [player,["NameCityCapital","NameCity","NameVillage"],25600]) select 0;
  288. _town_name = text _closestTown;
  289. _town_pos = position _closestTown;
  290. if (!_inTown) then {
  291. for "_i" from 0 to ((count allbuild_notowns) - 1) do
  292. {
  293. _check_town = (allbuild_notowns select _i) select _i - _i;
  294. if (_town_name == _check_town) then {
  295. _townRange = (allbuild_notowns select _i) select _i - _i + 1;
  296. if (_locationPlayer distance _town_pos <= _townRange) then {
  297. deletevehicle _object; cutText [format["You cannot build %1 within %2 meters of area %3",_text, _townRange, _town_name], "PLAIN DOWN",1];call _funcExitScript;
  298. };
  299. };
  300. };
  301. };
  302.  
  303. r_interrupt = false;
  304. r_doLoop = true;
  305. _cntLoop = 0;
  306. //Physically begin building
  307. switch (true) do
  308. {
  309. case(_longWait):
  310. {
  311. _cnt = _longWloop;
  312. _cnt = _cnt * 10;
  313. for "_i" from 0 to _longWloop do
  314. {
  315. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  316. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  317. 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;};
  318. player playActionNow "Medic";
  319. sleep 1;
  320. [player,"repair",0,false] call dayz_zombieSpeak;
  321. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  322. //DayZ interrupt feature like when canceling bandaging
  323. while {r_doLoop} do {
  324. if (r_interrupt) then {
  325. r_doLoop = false;
  326. };
  327. if (_cntLoop >= 100) then {
  328. r_doLoop = false;
  329. _finished = true;
  330. };
  331. sleep .1;
  332. _cntLoop = _cntLoop + 1;
  333. };
  334. if (r_interrupt) then {
  335. deletevehicle _object;
  336. [objNull, player, rSwitchMove,""] call RE;
  337. player playActionNow "stop";
  338. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  339. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  340. breakOut "exit";
  341. };
  342. r_doLoop = true;
  343. _cntLoop = 0;
  344. _cnt = _cnt - 10;
  345. };
  346. sleep 1.5;
  347. };
  348. case(_medWait):
  349. {
  350. _cnt = _medWloop;
  351. _cnt = _cnt * 10;
  352. for "_i" from 0 to _medWloop do
  353. {
  354. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  355. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  356. 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;};
  357. player playActionNow "Medic";
  358. sleep 1;
  359. [player,"repair",0,false] call dayz_zombieSpeak;
  360. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  361. while {r_doLoop} do {
  362. if (r_interrupt) then {
  363. r_doLoop = false;
  364. };
  365. if (_cntLoop >= 100) then {
  366. r_doLoop = false;
  367. _finished = true;
  368. };
  369. sleep .1;
  370. _cntLoop = _cntLoop + 1;
  371. };
  372. if (r_interrupt) then {
  373. deletevehicle _object;
  374. [objNull, player, rSwitchMove,""] call RE;
  375. player playActionNow "stop";
  376. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  377. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  378. breakOut "exit";
  379. };
  380. r_doLoop = true;
  381. _cntLoop = 0;
  382. _cnt = _cnt - 10;
  383. };
  384. sleep 1.5;
  385. };
  386. case(!_medWait && !_longWait):
  387. {
  388. _cnt = _smallWloop;
  389. _cnt = _cnt * 10;
  390. for "_i" from 0 to _smallWloop do
  391. {
  392. cutText [format["Building %1. %2 seconds left.\nMove from current position to cancel",_text,_cnt + 10], "PLAIN DOWN",1];
  393. if (player distance _locationPlayer > 1) then {deletevehicle _object; cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1]; call _funcExitScript;};
  394. 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;};
  395. player playActionNow "Medic";
  396. sleep 1;
  397. [player,"repair",0,false] call dayz_zombieSpeak;
  398. _id = [player,50,true,(getPosATL player)] spawn player_alertZombies;
  399. while {r_doLoop} do {
  400. if (r_interrupt) then {
  401. r_doLoop = false;
  402. };
  403. if (_cntLoop >= 100) then {
  404. r_doLoop = false;
  405. _finished = true;
  406. };
  407. sleep .1;
  408. _cntLoop = _cntLoop + 1;
  409. };
  410. if (r_interrupt) then {
  411. deletevehicle _object;
  412. [objNull, player, rSwitchMove,""] call RE;
  413. player playActionNow "stop";
  414. cutText [format["Build canceled for %1, position of player moved",_text], "PLAIN DOWN",1];
  415. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
  416. breakOut "exit";
  417. };
  418. r_doLoop = true;
  419. _cntLoop = 0;
  420. _cnt = _cnt - 10;
  421. };
  422. sleep 1.5;
  423. };
  424. };
  425. // Do last check to see if player attempted to remvoe buildables
  426. _mags = magazines player;
  427. _buildables = []; // reset original buildables
  428. if ("ItemTankTrap" in _mags) then {
  429. _qtyT = {_x == "ItemTankTrap"} count magazines player;
  430. _buildables set [count _buildables, _qtyT];
  431. } else { _qtyT = 0; _buildables set [count _buildables, _qtyT]; };
  432.  
  433. if ("ItemSandbag" in _mags) then {
  434. _qtyS = {_x == "ItemSandbag"} count magazines player;
  435. _buildables set [count _buildables, _qtyS];
  436. } else { _qtyS = 0; _buildables set [count _buildables, _qtyS]; };
  437.  
  438. if ("ItemWire" in _mags) then {
  439. _qtyW = {_x == "ItemWire"} count magazines player;
  440. _buildables set [count _buildables, _qtyW];
  441. } else { _qtyW = 0; _buildables set [count _buildables, _qtyW]; };
  442. if ("PartWoodPile" in _mags) then {
  443. _qtyL = {_x == "PartWoodPile"} count magazines player;
  444. _buildables set [count _buildables, _qtyL];
  445. } else { _qtyL = 0; _buildables set [count _buildables, _qtyL]; };
  446.  
  447. if ("PartGeneric" in _mags) then {
  448. _qtyM = {_x == "PartGeneric"} count magazines player;
  449. _buildables set [count _buildables, _qtyM];
  450. } else { _qtyM = 0; _buildables set [count _buildables, _qtyM]; };
  451.  
  452. if ("HandGrenade_West" in _mags) then {
  453. _qtyG = {_x == "HandGrenade_West"} count magazines player;
  454. _buildables set [count _buildables, _qtyG];
  455. } else { _qtyG = 0; _buildables set [count _buildables, _qtyG]; };
  456.  
  457. // Check if it matches again
  458. _result = [_buildables,_chosenRecipe] call BIS_fnc_areEqual;
  459.  
  460. if (_result) then {
  461. //Build final product!
  462. //_object setpos [((_object modeltoworld [0,0,0]) select 0),((_object modeltoworld [0,0,0]) select 1), 0];
  463. //_location = getposATL _object;
  464. //_dir = getDir _object;
  465. //Finish last requirement checks, _isSimulated disables objects physics if specified, _isDestructable checks if object needs to be invincible
  466. if (!_isSimulated) then {
  467. _object enablesimulation false;
  468. };
  469. if (!_isDestructable) then {
  470. _object addEventHandler ["HandleDamage", {false}];
  471. };
  472.  
  473.  
  474. // set the codes for gate
  475. //--------------------------------
  476. /* Old Method
  477. _uidDir = _dir;
  478. _uidDir = round(_uidDir);
  479. _p1 = round(_location select 0);
  480. _p2 = round(_location select 1);
  481. //_p3 = round(_location select 2);
  482. _uid = format["%1,%2,%3",_p1,_p2,_uidDir];
  483. */
  484. // New Method
  485. _uidDir = _dir;
  486. _uidDir = round(_uidDir);
  487. _uid = "";
  488. {
  489. _x = _x * 10;
  490. if ( _x < 0 ) then { _x = _x * -10 };
  491. _uid = _uid + str(round(_x));
  492. } forEach _location;
  493. _uid = _uid + str(round(_dir));
  494. // ------------------------------------------------------------------------kikyou2 Random Keycode Start---------------------------------------------------------------------
  495. _coder = random(9999); //generating random number between 0-9999
  496. if (_coder < 1000) then { //checks whether the number is < 1000
  497. _coder = _coder + 1000; //adds 1000 to the number if its < 1000 to make sure that the code will be 4 digits long
  498. };
  499. _code = round _coder; //remove all digits after comma
  500.  
  501. // ------------------------------------------------------------------------kikyou2 Random Keycode End-----------------------------------------------------------------------
  502. //--------------------------------
  503.  
  504. switch (_classname) do
  505. {
  506. case "Grave":
  507. {
  508. cutText [format["You have constructed a %1, crawl away so you dont set it off!",_text], "PLAIN DOWN",1];
  509. _object setVariable ["isBomb", true];
  510. };
  511. case "Infostand_2_EP1":
  512. {
  513. 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];
  514. };
  515. default {
  516. cutText [format["You have constructed a %1\n Keycode for object removal: %2 .\n",_text,_code], "PLAIN DOWN",60]
  517. //cutText [format[localize "str_build_01",_text], "PLAIN DOWN"];
  518. };
  519. };
  520. //Remove required magazines
  521. if (_qtyT > 0) then {
  522. for "_i" from 0 to _qtyT do
  523. {
  524. player removeMagazine _itemT;
  525. };
  526. };
  527. if (_qtyS > 0) then {
  528. for "_i" from 0 to _qtyS do
  529. {
  530. player removeMagazine _itemS;
  531. };
  532. };
  533. if (_qtyW > 0) then {
  534. for "_i" from 0 to _qtyW do
  535. {
  536. player removeMagazine _itemW;
  537. };
  538. };
  539. if (_qtyL > 0) then {
  540. for "_i" from 0 to _qtyL do
  541. {
  542. player removeMagazine _itemL;
  543. };
  544. };
  545. if (_qtyM > 0) then {
  546. for "_i" from 0 to _qtyM do
  547. {
  548. player removeMagazine _itemM;
  549. };
  550. };
  551. //Grenade only is needed when building booby trap
  552. if (_qtyG > 0 && _classname == "Grave") then {
  553. for "_i" from 0 to _qtyG do
  554. {
  555. player removeMagazine _itemG;
  556. };
  557. };
  558.  
  559. // Send to database
  560. if ((typeOf _object) in allbuildables_class) then {
  561. _fuel = _code / 1000; //added to calculate valid fuel value for the database
  562. _object setVariable ["characterID",dayz_playerUID,true];
  563.  
  564. PVDZ_obj_Publish = [dayz_playerUID,_object,[_dir,_location],_classname,_fuel,_code]; //added _code to pass to the publishObj function to prevent calculation errors
  565. publicVariableServer "PVDZ_obj_Publish";
  566. } else { //Send to database if part of _allowedObjects
  567.  
  568. _object setVariable ["characterID",dayz_characterID,true];
  569.  
  570. PVDZ_obj_Publish = [dayz_characterID,_object,[_dir,_location],_classname];
  571. publicVariableServer "PVDZ_obj_Publish";
  572. };
  573. } else {cutText ["You need the EXACT amount of whatever you are trying to build without extras.", "PLAIN DOWN"];call _funcExitScript;};
  574. player allowdamage true;
  575. procBuild = false;_playerCombat setVariable["startcombattimer", 1, true];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement