Advertisement
Guest User

Untitled

a guest
Dec 21st, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.39 KB | None | 0 0
  1. #include "..\..\script_macros.hpp"
  2. /*
  3. * File: fn_keyHandler.sqf
  4. * Author: Bryan "Tonic" Boardwine
  5. *
  6. * Description:
  7. * Main key handler for event 'keyDown'.
  8. */
  9. private ["_handled","_shift","_alt","_code","_ctrl","_alt","_ctrlKey","_veh","_locked","_interactionKey","_mapKey","_interruptionKeys"];
  10. _ctrl = _this select 0;
  11. _code = _this select 1;
  12. _shift = _this select 2;
  13. _ctrlKey = _this select 3;
  14. _alt = _this select 4;
  15. _speed = speed cursorObject;
  16. _handled = false;
  17.  
  18. _interactionKey = if (count (actionKeys "User10") isEqualTo 0) then {219} else {(actionKeys "User10") select 0};
  19. _mapKey = (actionKeys "ShowMap" select 0);
  20. //hint str _code;
  21. _interruptionKeys = [17,30,31,32]; //A,S,W,D
  22.  
  23. //Vault handling...
  24. if ((_code in (actionKeys "GetOver") || _code in (actionKeys "salute") || _code in (actionKeys "SitDown") || _code in (actionKeys "Throw") || _code in (actionKeys "GetIn") || _code in (actionKeys "GetOut") || _code in (actionKeys "Fire") || _code in (actionKeys "ReloadMagazine") || _code in [16,18]) && ((player getVariable ["restrained",false]) || (player getVariable ["playerSurrender",false]) || life_isknocked || life_istazed)) exitWith {
  25. true;
  26. };
  27.  
  28. if (life_action_inUse) exitWith {
  29. if (!life_interrupted && _code in _interruptionKeys) then {life_interrupted = true;};
  30. _handled;
  31. };
  32.  
  33. //Hotfix for Interaction key not being able to be bound on some operation systems.
  34. if (!(count (actionKeys "User10") isEqualTo 0) && {(inputAction "User10" > 0)}) exitWith {
  35. //Interaction key (default is Left Windows, can be mapped via Controls -> Custom -> User Action 10)
  36. if (!life_action_inUse) then {
  37. [] spawn {
  38. private "_handle";
  39. _handle = [] spawn life_fnc_actionKeyHandler;
  40. waitUntil {scriptDone _handle};
  41. life_action_inUse = false;
  42. };
  43. };
  44. true;
  45. };
  46.  
  47. if (life_container_active) exitwith {
  48. //ignore movement actions
  49. private _allowedMoves = [
  50. "MoveForward",
  51. "MoveBack",
  52. "TurnLeft",
  53. "TurnRight",
  54. "MoveFastForward",
  55. "MoveSlowForward",
  56. "turbo",
  57. "TurboToggle",
  58. "MoveLeft",
  59. "MoveRight",
  60. "WalkRunTemp",
  61. "WalkRunToggle",
  62. "AdjustUp",
  63. "AdjustDown",
  64. "AdjustLeft",
  65. "AdjustRight",
  66. "Stand",
  67. "Crouch",
  68. "Prone",
  69. "MoveUp",
  70. "MoveDown",
  71. "LeanLeft",
  72. "LeanLeftToggle",
  73. "LeanRight",
  74. "LeanRightToggle"
  75. ];
  76. if (({_code in (actionKeys _x)} count _allowedMoves) > 0) exitwith {
  77. false;
  78. };
  79. //handle other keys
  80. if (_code isEqualTo 57) then {//space key -> place
  81. life_storagePlacing = 0 spawn life_fnc_placestorage;
  82. } else { //other keys -> abort
  83. if (!isNull life_storagePlacing) exitWith {}; //already placing down a box
  84. if (!isNull life_container_activeObj) then {
  85. deleteVehicle life_container_activeObj;
  86. titleText [localize "STR_NOTF_PlaceContainerAbort", "PLAIN"];
  87. };
  88. life_container_active = false;
  89. };
  90. true;
  91. };
  92.  
  93. switch (_code) do {
  94. // -- Disable commander/tactical view
  95. if (LIFE_SETTINGS(getNumber,"disableCommanderView") isEqualTo 1) then {
  96. private _CommandMode = actionKeys "tacticalView";
  97.  
  98. if (_code in _CommandMode) then {
  99. hint localize "STR_NOTF_CommanderView";
  100. _handled = true;
  101. };
  102. };
  103.  
  104. //Space key for Jumping
  105. case 57: {
  106. if (isNil "jumpActionTime") then {jumpActionTime = 0;};
  107. if (_shift && {!(animationState player isEqualTo "AovrPercMrunSrasWrflDf")} && {isTouchingGround player} && {stance player isEqualTo "STAND"} && {speed player > 2} && {!life_is_arrested} && {((velocity player) select 2) < 2.5} && {time - jumpActionTime > 1.5}) then {
  108. jumpActionTime = time; //Update the time.
  109. [player] remoteExec ["life_fnc_jumpFnc",RANY]; //Global execution
  110. _handled = true;
  111. };
  112. };
  113.  
  114. //Surrender (Shift + B)
  115. case 48: {
  116. if (_shift) then {
  117. if (player getVariable ["playerSurrender",false]) then {
  118. player setVariable ["playerSurrender",false,true];
  119. } else {
  120. [] spawn life_fnc_surrender;
  121. };
  122. _handled = true;
  123. };
  124. };
  125.  
  126. //Map Key
  127. case _mapKey: {
  128. switch (playerSide) do {
  129. case west: {if (!visibleMap) then {[] spawn life_fnc_copMarkers;}};
  130. case independent: {if (!visibleMap) then {[] spawn life_fnc_medicMarkers;}};
  131. case civilian: {if (!visibleMap) then {[] spawn life_fnc_civMarkers;}};
  132. };
  133. };
  134.  
  135. //Holster / recall weapon. (Shift + H)
  136. case 35: {
  137. if (_shift && !_ctrlKey && !(currentWeapon player isEqualTo "")) then {
  138. life_curWep_h = currentWeapon player;
  139. player action ["SwitchWeapon", player, player, 100];
  140. player switchCamera cameraView;
  141. };
  142.  
  143. if (!_shift && _ctrlKey && !isNil "life_curWep_h" && {!(life_curWep_h isEqualTo "")}) then {
  144. if (life_curWep_h in [primaryWeapon player,secondaryWeapon player,handgunWeapon player]) then {
  145. player selectWeapon life_curWep_h;
  146. };
  147. };
  148. };
  149.  
  150. //Interaction key (default is Left Windows, can be mapped via Controls -> Custom -> User Action 10)
  151. case _interactionKey: {
  152. if (!life_action_inUse) then {
  153. [] spawn {
  154. private "_handle";
  155. _handle = [] spawn life_fnc_actionKeyHandler;
  156. waitUntil {scriptDone _handle};
  157. life_action_inUse = false;
  158. };
  159. };
  160. };
  161.  
  162. //Restraining (Shift + R)
  163. case 19: {
  164. if (_shift) then {_handled = true;};
  165. if (_shift && playerSide isEqualTo west && {!isNull cursorObject} && {cursorObject isKindOf "Man"} && {(isPlayer cursorObject)} && {(side cursorObject in [civilian,independent])} && {alive cursorObject} && {cursorObject distance player < 3.5} && {!(cursorObject getVariable "Escorting")} && {!(cursorObject getVariable "restrained")} && {speed cursorObject < 1}) then {
  166. [] call life_fnc_restrainAction;
  167. };
  168. };
  169.  
  170. //Knock out, this is experimental and yeah... (Shift + G)
  171. case 34: {
  172. if (_shift) then {_handled = true;};
  173. if (_shift && playerSide isEqualTo civilian && !isNull cursorObject && cursorObject isKindOf "Man" && isPlayer cursorObject && alive cursorObject && cursorObject distance player < 4 && speed cursorObject < 1) then {
  174. if ((animationState cursorObject) != "Incapacitated" && (currentWeapon player == primaryWeapon player || currentWeapon player == handgunWeapon player) && currentWeapon player != "" && !life_knockout && !(player getVariable ["restrained",false]) && !life_istazed && !life_isknocked) then {
  175. [cursorObject] spawn life_fnc_knockoutAction;
  176. };
  177. };
  178. };
  179.  
  180. //T Key (Trunk)
  181. case 20: {
  182. if (!_alt && {!_ctrlKey} && {!dialog} && {!life_action_inUse} && {!(player getVariable ["playerSurrender",false])} && {!(player getVariable ["restrained",false])} && {!life_isknocked} && {!life_istazed}) then {
  183. if (!(isNull objectParent player) && alive vehicle player) then {
  184. if ((vehicle player) in life_vehicles) then {
  185. [vehicle player] spawn life_fnc_openInventory;
  186. };
  187. } else {
  188. private "_list";
  189. _list = ((ASLtoATL (getPosASL player)) nearEntities [["Box_IND_Grenades_F","B_supplyCrate_F"], 2.5]) select 0;
  190. if (!(isNil "_list")) then {
  191. _house = nearestObject [(ASLtoATL (getPosASL _list)), "House"];
  192. if (_house getVariable ["locked", false]) then {
  193. hint localize "STR_House_ContainerDeny";
  194. } else {
  195. [_list] spawn life_fnc_openInventory;
  196. };
  197. } else {
  198. _list = ["landVehicle","Air","Ship"];
  199. if (KINDOF_ARRAY(cursorObject,_list) && {player distance cursorObject < 7} && {isNull objectParent player} && {alive cursorObject} && {!life_action_inUse}) then {
  200. if (cursorObject in life_vehicles || {locked cursorObject isEqualTo 0}) then {
  201. [cursorObject] spawn life_fnc_openInventory;
  202. };
  203. };
  204. };
  205. };
  206. };
  207. };
  208.  
  209. //L Key?
  210. case 38: {
  211. //If cop run checks for turning lights on.
  212. if (_shift && playerSide in [west,independent]) then {
  213. if (!(isNull objectParent player) && (typeOf vehicle player) in ["C_Offroad_01_F","B_MRAP_01_F","C_SUV_01_F","C_Hatchback_01_sport_F","B_Heli_Light_01_F","B_Heli_Transport_01_F"]) then {
  214. if (!isNil {vehicle player getVariable "lights"}) then {
  215. if (playerSide isEqualTo west) then {
  216. [vehicle player] call life_fnc_sirenLights;
  217. } else {
  218. [vehicle player] call life_fnc_medicSirenLights;
  219. };
  220. _handled = true;
  221. };
  222. };
  223. };
  224.  
  225. if (!_alt && !_ctrlKey) then { [] call life_fnc_radar; };
  226. };
  227.  
  228. //Y Player Menu
  229. case 21: {
  230. if (!_alt && !_ctrlKey && !dialog && !(player getVariable ["restrained",false]) && {!life_action_inUse}) then {
  231. [] call life_fnc_p_openMenu;
  232. };
  233. };
  234.  
  235. //F Key
  236. case 33: {
  237. if (playerSide in [west,independent] && {vehicle player != player} && {!life_siren_active} && {((driver vehicle player) == player)}) then {
  238. [] spawn {
  239. life_siren_active = true;
  240. sleep 4.7;
  241. life_siren_active = false;
  242. };
  243.  
  244. _veh = vehicle player;
  245. if (isNil {_veh getVariable "siren"}) then {_veh setVariable ["siren",false,true];};
  246. if ((_veh getVariable "siren")) then {
  247. titleText [localize "STR_MISC_SirensOFF","PLAIN"];
  248. _veh setVariable ["siren",false,true];
  249. } else {
  250. titleText [localize "STR_MISC_SirensON","PLAIN"];
  251. _veh setVariable ["siren",true,true];
  252. if (playerSide isEqualTo west) then {
  253. [_veh] remoteExec ["life_fnc_copSiren",RCLIENT];
  254. } else {
  255. [_veh] remoteExec ["life_fnc_medicSiren",RCLIENT];
  256. };
  257. };
  258. };
  259. };
  260.  
  261. //O Key
  262. case 24: {
  263. if (_shift) then {
  264. if !(soundVolume isEqualTo 1) then {
  265. 1 fadeSound 1;
  266. systemChat localize "STR_MISC_soundnormal";
  267. } else {
  268. 1 fadeSound 0.1;
  269. systemChat localize "STR_MISC_soundfade";
  270. };
  271. };
  272. };
  273.  
  274. //U Key
  275. case 22: {
  276. if (!_alt && !_ctrlKey) then {
  277. if (isNull objectParent player) then {
  278. _veh = cursorObject;
  279. } else {
  280. _veh = vehicle player;
  281. };
  282.  
  283. if (_veh isKindOf "House_F" && {playerSide isEqualTo civilian}) then {
  284. if (_veh in life_vehicles && {player distance _veh < 20}) then {
  285. _door = [_veh] call life_fnc_nearestDoor;
  286. if (_door isEqualTo 0) exitWith {hint localize "STR_House_Door_NotNear"};
  287. _locked = _veh getVariable [format ["bis_disabled_Door_%1",_door],0];
  288.  
  289. if (_locked isEqualTo 0) then {
  290. _veh setVariable [format ["bis_disabled_Door_%1",_door],1,true];
  291. _veh animateSource [format ["Door_%1_source", _door], 0];
  292. systemChat localize "STR_House_Door_Lock";
  293. } else {
  294. _veh setVariable [format ["bis_disabled_Door_%1",_door],0,true];
  295. _veh animateSource [format ["Door_%1_source", _door], 1];
  296. systemChat localize "STR_House_Door_Unlock";
  297. };
  298. };
  299. } else {
  300. _locked = locked _veh;
  301. if (_veh in life_vehicles && {player distance _veh < 20}) then {
  302. if (_locked isEqualTo 2) then {
  303. if (local _veh) then {
  304. _veh lock 0;
  305.  
  306. // BI
  307. _veh animateDoor ["door_back_R",1];
  308. _veh animateDoor ["door_back_L",1];
  309. _veh animateDoor ['door_R',1];
  310. _veh animateDoor ['door_L',1];
  311. _veh animateDoor ['Door_L_source',1];
  312. _veh animateDoor ['Door_rear',1];
  313. _veh animateDoor ['Door_rear_source',1];
  314. _veh animateDoor ['Door_1_source',1];
  315. _veh animateDoor ['Door_2_source',1];
  316. _veh animateDoor ['Door_3_source',1];
  317. _veh animateDoor ['Door_LM',1];
  318. _veh animateDoor ['Door_RM',1];
  319. _veh animateDoor ['Door_LF',1];
  320. _veh animateDoor ['Door_RF',1];
  321. _veh animateDoor ['Door_LB',1];
  322. _veh animateDoor ['Door_RB',1];
  323. _veh animateDoor ['DoorL_Front_Open',1];
  324. _veh animateDoor ['DoorR_Front_Open',1];
  325. _veh animateDoor ['DoorL_Back_Open',1];
  326. _veh animateDoor ['DoorR_Back_Open ',1];
  327. } else {
  328. [_veh,0] remoteExecCall ["life_fnc_lockVehicle",_veh];
  329.  
  330. _veh animateDoor ["door_back_R",1];
  331. _veh animateDoor ["door_back_L",1];
  332. _veh animateDoor ['door_R',1];
  333. _veh animateDoor ['door_L',1];
  334. _veh animateDoor ['Door_L_source',1];
  335. _veh animateDoor ['Door_rear',1];
  336. _veh animateDoor ['Door_rear_source',1];
  337. _veh animateDoor ['Door_1_source',1];
  338. _veh animateDoor ['Door_2_source',1];
  339. _veh animateDoor ['Door_3_source',1];
  340. _veh animateDoor ['Door_LM',1];
  341. _veh animateDoor ['Door_RM',1];
  342. _veh animateDoor ['Door_LF',1];
  343. _veh animateDoor ['Door_RF',1];
  344. _veh animateDoor ['Door_LB',1];
  345. _veh animateDoor ['Door_RB',1];
  346. _veh animateDoor ['DoorL_Front_Open',1];
  347. _veh animateDoor ['DoorR_Front_Open',1];
  348. _veh animateDoor ['DoorL_Back_Open',1];
  349. _veh animateDoor ['DoorR_Back_Open ',1];
  350. };
  351. systemChat localize "STR_MISC_VehUnlock";
  352. [_veh,"unlockCarSound"] remoteExec ["life_fnc_say3D",RANY];
  353. } else {
  354. if (local _veh) then {
  355. _veh lock 2;
  356.  
  357. _veh animateDoor ["door_back_R",0];
  358. _veh animateDoor ["door_back_L",0];
  359. _veh animateDoor ['door_R',0];
  360. _veh animateDoor ['door_L',0];
  361. _veh animateDoor ['Door_L_source',0];
  362. _veh animateDoor ['Door_rear',0];
  363. _veh animateDoor ['Door_rear_source',0];
  364. _veh animateDoor ['Door_1_source',0];
  365. _veh animateDoor ['Door_2_source',0];
  366. _veh animateDoor ['Door_3_source',0];
  367. _veh animateDoor ['Door_LM',0];
  368. _veh animateDoor ['Door_RM',0];
  369. _veh animateDoor ['Door_LF',0];
  370. _veh animateDoor ['Door_RF',0];
  371. _veh animateDoor ['Door_LB',0];
  372. _veh animateDoor ['Door_RB',0];
  373. _veh animateDoor ['DoorL_Front_Open',0];
  374. _veh animateDoor ['DoorR_Front_Open',0];
  375. _veh animateDoor ['DoorL_Back_Open',0];
  376. _veh animateDoor ['DoorR_Back_Open ',0];
  377. } else {
  378. [_veh,2] remoteExecCall ["life_fnc_lockVehicle",_veh];
  379.  
  380. _veh animateDoor ["door_back_R",0];
  381. _veh animateDoor ["door_back_L",0];
  382. _veh animateDoor ['door_R',0];
  383. _veh animateDoor ['door_L',0];
  384. _veh animateDoor ['Door_L_source',0];
  385. _veh animateDoor ['Door_rear',0];
  386. _veh animateDoor ['Door_rear_source',0];
  387. _veh animateDoor ['Door_1_source',0];
  388. _veh animateDoor ['Door_2_source',0];
  389. _veh animateDoor ['Door_3_source',0];
  390. _veh animateDoor ['Door_LM',0];
  391. _veh animateDoor ['Door_RM',0];
  392. _veh animateDoor ['Door_LF',0];
  393. _veh animateDoor ['Door_RF',0];
  394. _veh animateDoor ['Door_LB',0];
  395. _veh animateDoor ['Door_RB',0];
  396. _veh animateDoor ['DoorL_Front_Open',0];
  397. _veh animateDoor ['DoorR_Front_Open',0];
  398. _veh animateDoor ['DoorL_Back_Open',0];
  399. _veh animateDoor ['DoorR_Back_Open ',0];
  400. };
  401. systemChat localize "STR_MISC_VehLock";
  402. [_veh,"lockCarSound"] remoteExec ["life_fnc_say3D",RANY];
  403. };
  404. };
  405. };
  406. };
  407. };
  408.  
  409. _handled;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement