Guest User

@Dayz/dayz_code/compile/fn_SelfActions

a guest
Mar 19th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.86 KB | None | 0 0
  1. scriptName "Functions\misc\fn_selfActions.sqf";
  2. /***********************************************************
  3. ADD ACTIONS FOR SELF
  4. - Function
  5. - [] call fnc_usec_selfActions;
  6. ************************************************************/
  7. _vehicle = vehicle player;
  8. _inVehicle = (_vehicle != player);
  9. _cursorTarget = cursorTarget;
  10. _primaryWeapon = primaryWeapon player;
  11. _currentWeapon = currentWeapon player;
  12. _onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
  13. //_canDrink = count nearestObjects [getPosATL player, ["Land_pumpa","Land_water_tank"], 2] > 0;
  14.  
  15. _nearLight = nearestObject [player,"LitObject"];
  16. _canPickLight = false;
  17.  
  18. if (!isNull _nearLight) then {
  19. if (_nearLight distance player < 4) then {
  20. _canPickLight = isNull (_nearLight getVariable ["owner",objNull]);
  21. };
  22. };
  23.  
  24. _canDo = (!r_drag_sqf and !r_player_unconscious and !_onLadder);
  25.  
  26. //Grab Flare
  27. if (_canPickLight and !dayz_hasLight) then {
  28. if (s_player_grabflare < 0) then {
  29. _text = getText (configFile >> "CfgAmmo" >> (typeOf _nearLight) >> "displayName");
  30. s_player_grabflare = player addAction [format[localize "str_actions_medical_15",_text], "\z\addons\dayz_code\actions\flare_pickup.sqf",_nearLight, 1, false, true, "", ""];
  31. s_player_removeflare = player addAction [format[localize "str_actions_medical_17",_text], "\z\addons\dayz_code\actions\flare_remove.sqf",_nearLight, 1, false, true, "", ""];
  32. };
  33. } else {
  34. player removeAction s_player_grabflare;
  35. player removeAction s_player_removeflare;
  36. s_player_grabflare = -1;
  37. s_player_removeflare = -1;
  38. };
  39.  
  40. if (dayz_onBack != "" && !dayz_onBackActive && !_inVehicle && !_onLadder && !r_player_unconscious) then {
  41. if (s_player_equip_carry < 0) then {
  42. _text = getText (configFile >> "CfgWeapons" >> dayz_onBack >> "displayName");
  43. s_player_equip_carry = player addAction [format[localize "STR_ACTIONS_WEAPON", _text], "\z\addons\dayz_code\actions\player_switchWeapon.sqf", "action", 0.5, false, true];
  44. };
  45. } else {
  46. player removeAction s_player_equip_carry;
  47. s_player_equip_carry = -1;
  48. };
  49.  
  50. //fishing
  51. if ((_currentWeapon in Dayz_fishingItems) && !dayz_fishingInprogress && !_inVehicle && !dayz_isSwimming) then {
  52. if (s_player_fishing < 0) then {
  53. s_player_fishing = player addAction [localize "STR_ACTION_CAST", "\z\addons\dayz_code\actions\player_goFishing.sqf",player, 0.5, false, true];
  54. };
  55. } else {
  56. player removeAction s_player_fishing;
  57. s_player_fishing = -1;
  58. };
  59. if ((_primaryWeapon in Dayz_fishingItems) && !dayz_fishingInprogress && (_inVehicle and (driver _vehicle != player))) then {
  60. if (s_player_fishing_veh < 0) then {
  61. s_player_fishing_veh = _vehicle addAction [localize "STR_ACTION_CAST", "\z\addons\dayz_code\actions\player_goFishing.sqf",_vehicle, 0.5, false, true];
  62. };
  63. } else {
  64. _vehicle removeAction s_player_fishing_veh;
  65. s_player_fishing_veh = -1;
  66. };
  67.  
  68. _canDoThis=false;
  69. if (_canDo and !_inVehicle and !dayz_isSwimming) then {
  70. {
  71. _waterHoles = if (typeOf _x == "waterHoleProxy") then {nearestObjects [_x, [], 1];} else {[_x];};
  72. {
  73. _w2m = _x worldToModel (getPosATL player);
  74. _bb = (boundingbox _x) select 1;
  75. _dir = [player, _x] call BIS_fnc_relativeDirTo; if (_dir > 180) then {_dir = _dir - 360};
  76. if (((abs _dir < 45) and {(_x distance player < 2.22)}) // wells, kasna, pumpa
  77. or {((("" == typeOf _x) and ((_w2m select 2) < 0.05)) and {((abs(_w2m select 0) < (_bb select 0)) and (abs(_w2m select 1) < (_bb select 1)))})}) exitWith { // ponds
  78. _canDoThis = true;
  79. };
  80. } count _waterHoles;
  81. if (_canDoThis) exitWith {
  82. if (s_player_Drinkfromhands < 0) then {
  83. s_player_Drinkfromhands = player addAction [localize "str_player_31_drink", "\z\addons\dayz_code\actions\player_drinkWater.sqf",player, 0.5, false, true];
  84. };
  85. };
  86. } foreach nearestObjects [player, ["waterHoleProxy", "Land_pumpa"], 50];
  87. };
  88. if (!_canDoThis and s_player_Drinkfromhands >= 0) then {
  89. player removeAction s_player_Drinkfromhands;
  90. s_player_Drinkfromhands = -1;
  91. };
  92.  
  93. if (!isNull _cursorTarget and !_inVehicle and (player distance _cursorTarget < 4) and _canDo) then {
  94. //Has some kind of target
  95. _isVehicle = _cursorTarget isKindOf "AllVehicles";
  96. _isBicycle = _cursorTarget isKindOf "Bicycle";
  97. _isMan = _cursorTarget isKindOf "Man";
  98. _isAnimal = _cursorTarget isKindOf "Animal";
  99. _isZombie = _cursorTarget isKindOf "zZombie_base";
  100. _isDestructable = _cursorTarget isKindOf "BuiltItems";
  101. //_isTent = _cursorTarget isKindOf "TentStorage";
  102. //_isStash = _cursorTarget isKindOf "StashSmall";
  103. //_isMediumStash = _cursorTarget isKindOf "StashMedium";
  104. _isHarvested = _cursorTarget getVariable["meatHarvested",false];
  105. _isGenerator = _cursorTarget isKindOf "Generator_DZ";
  106. _ownerID = _cursorTarget getVariable ["characterID","0"];
  107. _isVehicletype = typeOf _cursorTarget in ["ATV_US_EP1","ATV_CZ_EP1"];
  108. _isFuel = false;
  109. _hasFuel20 = "ItemJerrycan" in magazines player;
  110. _hasFuel5 = "ItemFuelcan" in magazines player;
  111. _hasEmptyFuelCan = (("ItemJerrycanEmpty" in magazines player) || ("ItemFuelcanEmpty" in magazines player));
  112. _hasToolbox = "ItemToolbox" in items player;
  113. _hasbottleitem = (("ItemWaterbottle" in magazines player) || ("ItemWaterBottleInfected" in magazines player) || ("ItemWaterBottleSafe" in magazines player));
  114. _isAlive = alive _cursorTarget;
  115. _canmove = canmove _cursorTarget;
  116. _text = getText (configFile >> "CfgVehicles" >> typeOf _cursorTarget >> "displayName");
  117. _isPlant = typeOf _cursorTarget in Dayz_plants;
  118. _istypeTent = (_cursorTarget isKindOf "TentStorage_base") or (_cursorTarget isKindOf "IC_Tent");
  119. _upgradeItems = ["TentStorage","TentStorage0","TentStorage1","TentStorage2","TentStorage3","StashSmall","StashSmall1","StashSmall2","StashSmall3","StashSmall4","StashMedium","StashMedium1","StashMedium2","StashMedium3","DomeTentStorage","DomeTentStorage0","DomeTentStorage1","DomeTentStorage2","DomeTentStorage3","DomeTentStorage4"];
  120.  
  121. _isCampSite = _cursorTarget isKindOf "IC_Fireplace1";
  122.  
  123. //fuel tanks
  124. if (_hasEmptyFuelCan) then {
  125. //_isFuel = typeOf _cursorTarget in ["Land_Ind_TankSmall","Land_fuel_tank_big","Land_fuel_tank_stairs","Land_wagon_tanker","Land_fuelstation","Land_fuelstation_army"];
  126. _isFuel = (_cursorTarget isKindOf "Land_Ind_TankSmall") or (_cursorTarget isKindOf "Land_fuel_tank_big") or (_cursorTarget isKindOf "Land_fuel_tank_stairs") or (_cursorTarget isKindOf "Land_wagon_tanker");
  127. };
  128.  
  129. //remove gathered plant if empty
  130. if(_isPlant) then {
  131. _cursorTarget call player_gather;
  132. };
  133.  
  134. //flip vehicle
  135. if ((_isVehicletype) and !_canmove and _isAlive and (player distance _cursorTarget >= 2) and (count (crew _cursorTarget))== 0 and ((vectorUp _cursorTarget) select 2) < 0.5) then {
  136. if (s_player_flipveh < 0) then {
  137. s_player_flipveh = player addAction [format[localize "str_actions_flipveh",_text], "\z\addons\dayz_code\actions\player_flipvehicle.sqf",_cursorTarget, 1, true, true, "", ""];
  138. };
  139. } else {
  140. player removeAction s_player_flipveh;
  141. s_player_flipveh = -1;
  142. };
  143.  
  144. //Allow player to fill Fuel can
  145. if(_hasEmptyFuelCan and _isFuel and !_isZombie and !_isAnimal and !_isMan and !a_player_jerryfilling) then {
  146. if (s_player_fillfuel < 0) then {
  147. s_player_fillfuel = player addAction [localize "str_actions_self_10", "\z\addons\dayz_code\actions\jerry_fill.sqf",[], 1, false, true, "", ""];
  148. };
  149. } else {
  150. player removeAction s_player_fillfuel;
  151. s_player_fillfuel = -1;
  152. };
  153.  
  154. if (damage _cursorTarget < 1) then {
  155. //Allow player to fill vehicle 20L
  156. if(_hasFuel20 and !_isZombie and !_isAnimal and !_isMan and (_isVehicle or _isGenerator) and (fuel _cursorTarget < 1) and !a_player_jerryfilling) then {
  157. if (s_player_fillfuel20 < 0) then {
  158. s_player_fillfuel20 = player addAction [format[localize "str_actions_medical_10",_text,"20"], "\z\addons\dayz_code\actions\refuel.sqf",["ItemJerrycan"], 0, true, true, "", "'ItemJerrycan' in magazines player"];
  159. };
  160. } else {
  161. player removeAction s_player_fillfuel20;
  162. s_player_fillfuel20 = -1;
  163. };
  164.  
  165. //Allow player to fill vehicle 5L
  166. if(_hasFuel5 and !_isZombie and !_isAnimal and !_isMan and (_isVehicle or _isGenerator) and (fuel _cursorTarget < 1) and !a_player_jerryfilling) then {
  167. if (s_player_fillfuel5 < 0) then {
  168. s_player_fillfuel5 = player addAction [format[localize "str_actions_medical_10",_text,"5"], "\z\addons\dayz_code\actions\refuel.sqf",["ItemFuelcan"], 0, true, true, "", "'ItemFuelcan' in magazines player"];
  169. };
  170. } else {
  171. player removeAction s_player_fillfuel5;
  172. s_player_fillfuel5 = -1;
  173. };
  174. /*
  175. //power on Gen
  176. if (_isGenerator AND (fuel _cursorTarget > 0)) then {
  177. player action["EngineOn", _cursorTarget];
  178. };
  179. */
  180. //
  181. //Allow player to spihon vehicles
  182. if (_hasEmptyFuelCan and !_isZombie and !_isAnimal and !_isMan and _isVehicle and !_isBicycle and !a_player_jerryfilling and (fuel _cursorTarget > 0)) then {
  183. if (s_player_siphonfuel < 0) then {
  184. s_player_siphonfuel = player addAction [format[localize "str_siphon_start"], "\z\addons\dayz_code\actions\siphonFuel.sqf",_cursorTarget, 0, true, true, "", ""];
  185. };
  186. } else {
  187. player removeAction s_player_siphonfuel;
  188. s_player_siphonfuel = -1;
  189. };
  190. } else {
  191. player removeAction s_player_fillfuel20;
  192. s_player_fillfuel20 = -1;
  193. player removeAction s_player_fillfuel5;
  194. s_player_fillfuel5 = -1;
  195. player removeAction s_player_siphonfuel;
  196. s_player_siphonfuel = -1;
  197. };
  198.  
  199. //Harvested
  200. if (!alive _cursorTarget and _isAnimal and !_isHarvested) then {
  201. //_hasknife = {_x in ["ItemKnife","ItemKnife5","ItemKnife4","ItemKnife3","ItemKnife2","ItemKnifeBlunt"]} count items player > 0;
  202. //make sure the player has a knife
  203. //if (_hasknife) then {
  204. if (s_player_butcher < 0) then {
  205. s_player_butcher = player addAction [localize "str_actions_self_04", "\z\addons\dayz_code\actions\gather_meat.sqf",_cursorTarget, 3, true, true, "", ""];
  206. };
  207. //} else {
  208. // player removeAction s_player_butcher;
  209. // s_player_butcher = -1;
  210. //};
  211. } else {
  212. player removeAction s_player_butcher;
  213. s_player_butcher = -1;
  214. };
  215.  
  216. //Fireplace Actions check
  217. if (_cursorTarget call isInflamed) then {
  218. _hasRawMeat = {_x in Dayz_meatraw} count magazines player > 0;
  219. _hastinitem = {_x in boil_tin_cans} count magazines player > 0;
  220.  
  221. //Cook Meat
  222. if (_hasRawMeat and !a_player_cooking) then {
  223. if (s_player_cook < 0) then {
  224. s_player_cook = player addAction [localize "str_actions_self_05", "\z\addons\dayz_code\actions\cook.sqf",_cursorTarget, 3, true, true, "", ""];
  225. };
  226. };
  227. //Boil Water
  228. if (_hastinitem and _hasbottleitem and !a_player_boil) then {
  229. if (s_player_boil < 0) then {
  230. s_player_boil = player addAction [localize "str_actions_boilwater", "\z\addons\dayz_code\actions\boil.sqf",_cursorTarget, 3, true, true, "", ""];
  231. };
  232. };
  233. } else {
  234. if (a_player_cooking) then {
  235. player removeAction s_player_cook;
  236. s_player_cook = -1;
  237. };
  238. if (a_player_boil) then {
  239. player removeAction s_player_boil;
  240. s_player_boil = -1;
  241. };
  242. };
  243.  
  244. if(_cursorTarget == dayz_hasFire) then {
  245. if ((s_player_fireout < 0) and !(_cursorTarget call isInflamed) and (player distance _cursorTarget < 3)) then {
  246. s_player_fireout = player addAction [localize "str_actions_self_06", "\z\addons\dayz_code\actions\fire_pack.sqf",_cursorTarget, 0, false, true, "",""];
  247. };
  248. } else {
  249. player removeAction s_player_fireout;
  250. s_player_fireout = -1;
  251. };
  252.  
  253. //remove Own objects
  254. if (_ownerID == dayz_characterID) then {
  255. if(_isDestructable and _hasToolbox) then {
  256. if (s_player_deleteBuild < 0) then {
  257. s_player_deleteBuild = player addAction [format[localize "str_actions_delete",_text], "\z\addons\dayz_code\actions\remove.sqf",_cursorTarget, 1, true, true, "", ""];
  258. };
  259. } else {
  260. player removeAction s_player_deleteBuild;
  261. s_player_deleteBuild = -1;
  262. };
  263.  
  264. //upgrade items
  265. if (typeOf _cursorTarget in _upgradeItems) then {
  266. if (s_player_upgradestroage < 0) then {
  267. if (isText (configFile >> "CfgVehicles" >> (typeof _cursorTarget) >> "Upgrade" >> "create")) then {
  268. _displayName = getText (configFile >> "CfgVehicles" >> (typeOf _cursorTarget) >> "displayName");
  269. s_player_upgradestroage = player addAction [format[localize "str_upgrade",_displayName], "\z\addons\dayz_code\actions\object_upgradeStorage.sqf",_cursorTarget, 0, false, true, "",""];
  270. };
  271. };
  272. } else {
  273. player removeAction s_player_upgradestroage;
  274. s_player_upgradestroage = -1
  275. };
  276. if (_istypeTent) then {
  277. if (_ownerID == dayz_characterID) then {
  278. //Packing my tent
  279. if (s_player_packtent < 0) then {
  280. s_player_packtent = player addAction [localize "str_actions_self_07", "\z\addons\dayz_code\actions\tent_pack.sqf",_cursorTarget, 0, false, true, "",""];
  281. };
  282. //sleep
  283. if (s_player_sleep < 0) then {
  284. s_player_sleep = player addAction [localize "str_actions_self_sleep", "\z\addons\dayz_code\actions\player_sleep.sqf",_cursorTarget, 0, false, true, "",""];
  285. };
  286. };
  287. } else {
  288. player removeAction s_player_packtent;
  289. s_player_packtent = -1;
  290. player removeAction s_player_sleep;
  291. s_player_sleep = -1;
  292. };
  293. } else {
  294. player removeAction s_player_deleteBuild;
  295. s_player_deleteBuild = -1;
  296. player removeAction s_player_upgradestroage;
  297. s_player_upgradestroage = -1;
  298. player removeAction s_player_packtent;
  299. s_player_packtent = -1;
  300. player removeAction s_player_sleep;
  301. s_player_sleep = -1;
  302. };
  303. //other tents
  304. if (_istypeTent) then {
  305. //destory tents
  306. //Located in variables Dayz_Ignators = ["ItemMatchbox","Item5Matchbox","Item4Matchbox","Item3Matchbox","Item2Matchbox","Item1Matchbox"];
  307. _hasIgnators = {_x in Dayz_Ignators} count items player > 0;
  308. if ((_hasFuel20 or _hasFuel5) AND (_hasIgnators)) then {
  309. if (s_player_destorytent < 0) then {
  310. s_player_destorytent = player addAction [localize "str_actions_self_destorytent", "\z\addons\dayz_code\actions\player_destroyTent.sqf",_cursorTarget, 0, false, true, "",""];
  311. };
  312. } else {
  313. player removeAction s_player_destorytent;
  314. s_player_destorytent = -1;
  315. };
  316.  
  317. if (typeOf _cursorTarget in ["IC_DomeTent","IC_Tent"]) then {
  318. if (s_player_packtentinfected < 0) then {
  319. s_player_packtentinfected = player addAction [localize "str_actions_self_07", "\z\addons\dayz_code\actions\tent_pack.sqf",_cursorTarget, 0, false, true, "",""];
  320. };
  321. } else {
  322. player removeAction s_player_packtentinfected;
  323. s_player_packtentinfected = -1;
  324. };
  325. };
  326.  
  327. //Study Body
  328. if (_isMan and !_isAlive and !_isZombie and !_isAnimal) then {
  329. if (s_player_studybody < 0) then {
  330. s_player_studybody = player addAction [localize "str_action_studybody", "\z\addons\dayz_code\actions\study_body.sqf",_cursorTarget, 0, false, true, "",""];
  331. };
  332. } else {
  333. player removeAction s_player_studybody;
  334. s_player_studybody = -1;
  335. };
  336. /*
  337. //Carbomb
  338. _hasCarBomb = "ItemCarBomb" in magazines player;
  339. if (((cursorTarget isKindOf "Car") || (cursorTarget isKindOf "Air") || (cursorTarget isKindOf "Motorcycle")) and _hasCarBomb) then {
  340. if (s_player_attach_bomb < 0) then {
  341. s_player_attach_bomb = player addAction [localize "str_bombAttach", "\z\addons\dayz_code\actions\player_attach_bomb.sqf",cursorTarget, 3, true, true, "", ""];
  342. };
  343. } else {
  344. player removeAction s_player_attach_bomb;
  345. s_player_attach_bomb = -1;
  346. };
  347. */
  348. //Repairing Vehicles
  349. if ((dayz_myCursorTarget != _cursorTarget) and _isVehicle and !_isMan and _hasToolbox and (damage _cursorTarget < 1)) then {
  350. if (s_player_repair_crtl < 0) then {
  351. dayz_myCursorTarget = _cursorTarget;
  352. _menu = dayz_myCursorTarget addAction [localize "str_actions_rapairveh", "\z\addons\dayz_code\actions\repair_vehicle.sqf",_cursorTarget, 0, true, false, "",""];
  353. _menu1 = dayz_myCursorTarget addAction [localize "str_actions_salvageveh", "\z\addons\dayz_code\actions\salvage_vehicle.sqf",_cursorTarget, 0, true, false, "",""];
  354. s_player_repairActions set [count s_player_repairActions,_menu];
  355. s_player_repairActions set [count s_player_repairActions,_menu1];
  356. s_player_repair_crtl = 1;
  357. } else {
  358. {dayz_myCursorTarget removeAction _x} forEach s_player_repairActions;
  359. s_player_repairActions = [];
  360. s_player_repair_crtl = -1;
  361. };
  362. };
  363. } else {
  364. //Engineering
  365. {dayz_myCursorTarget removeAction _x} count s_player_repairActions;s_player_repairActions = [];
  366. player removeAction s_player_repair_crtl;
  367. s_player_repair_crtl = -1;
  368. dayz_myCursorTarget = objNull;
  369. //Others
  370. //player removeAction s_player_forceSave;
  371. //s_player_forceSave = -1;
  372. player removeAction s_player_flipveh;
  373. s_player_flipveh = -1;
  374. player removeAction s_player_sleep;
  375. s_player_sleep = -1;
  376. player removeAction s_player_deleteBuild;
  377. s_player_deleteBuild = -1;
  378. player removeAction s_player_butcher;
  379. s_player_butcher = -1;
  380. player removeAction s_player_cook;
  381. s_player_cook = -1;
  382. player removeAction s_player_boil;
  383. s_player_boil = -1;
  384. player removeAction s_player_fireout;
  385. s_player_fireout = -1;
  386. player removeAction s_player_packtent;
  387. s_player_packtent = -1;
  388. player removeAction s_player_packtentinfected;
  389. s_player_packtentinfected = -1;
  390. player removeAction s_player_fillfuel;
  391. s_player_fillfuel = -1;
  392. player removeAction s_player_studybody;
  393. s_player_studybody = -1;
  394. //fuel
  395. player removeAction s_player_fillfuel20;
  396. s_player_fillfuel20 = -1;
  397. player removeAction s_player_fillfuel5;
  398. s_player_fillfuel5 = -1;
  399. //Allow player to siphon vehicle fuel
  400. player removeAction s_player_siphonfuel;
  401. s_player_siphonfuel = -1;
  402. //Allow player to gather
  403. player removeAction s_player_gather;
  404. s_player_gather = -1;
  405. player removeAction s_player_destorytent;
  406. s_player_destorytent = -1;
  407. // player removeAction s_player_attach_bomb;
  408. // s_player_attach_bomb = -1;
  409. //debug
  410. //player removeAction s_player_debugCheck;
  411. //s_player_debugCheck = -1;
  412. player removeAction s_player_upgradestroage;
  413. s_player_upgradestroage = -1
  414. };
  415.  
  416. //Monitor
  417. player setVariable ["selfActions", diag_ticktime, false];
Add Comment
Please, Sign In to add comment