Advertisement
Guest User

Key Handler

a guest
Jul 30th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.52 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) then {
  48. switch (_code) do {
  49. //space key
  50. case 57: {
  51. [] spawn life_fnc_placestorage;
  52. };
  53. };
  54. true;
  55. };
  56.  
  57. switch (_code) do {
  58. //Space key for Jumping
  59. case 57: {
  60. if (isNil "jumpActionTime") then {jumpActionTime = 0;};
  61. 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 {
  62. jumpActionTime = time; //Update the time.
  63. [player] remoteExec ["life_fnc_jumpFnc",RANY]; //Global execution
  64. _handled = true;
  65. };
  66. };
  67.  
  68. //Surrender (Shift + B)
  69. case 48: {
  70. if (_shift) then {
  71. if (player getVariable ["playerSurrender",false]) then {
  72. player setVariable ["playerSurrender",false,true];
  73. } else {
  74. [] spawn life_fnc_surrender;
  75. };
  76. _handled = true;
  77. };
  78. };
  79.  
  80. //Map Key
  81. case _mapKey: {
  82. switch (playerSide) do {
  83. case west: {if (!visibleMap) then {[] spawn life_fnc_copMarkers;}};
  84. case independent: {if (!visibleMap) then {[] spawn life_fnc_medicMarkers;}};
  85. case civilian: {if (!visibleMap) then {[] spawn life_fnc_civMarkers;}};
  86. };
  87. };
  88.  
  89. //PushToTalk handler...
  90. if (_code in actionKeys "PushToTalk") then {
  91. switch (currentChannel) do {
  92. case 0: {_isSet = setCurrentChannel 5;};
  93. };
  94. };
  95.  
  96. if(_code in actionKeys "PrevChannel") exitWith {
  97.  
  98. if(currentChannel <= 3) then {
  99.  
  100. //--- Return the mic status
  101. ctrlText ((findDisplay 55) displayCtrl 101) == "\A3\ui_f\data\igui\rscingameui\rscdisplayvoicechat\microphone_ca.paa"
  102.  
  103. };
  104.  
  105. };
  106.  
  107. //--- Next Channel Switch
  108. if(_code in actionKeys "NextChannel") exitWith {
  109.  
  110. if(currentChannel >= 5) then {
  111.  
  112. //--- Return the mic status
  113. ctrlText ((findDisplay 55) displayCtrl 101) == "\A3\ui_f\data\igui\rscingameui\rscdisplayvoicechat\microphone_ca.paa"
  114.  
  115. };
  116.  
  117. };
  118.  
  119. //--- Speaking Key for Either selected channel, direct, side or VON was pressed. Process it
  120. if(_code in actionKeys "PushToTalk" || _code in actionKeys "PushToTalkSide" || _code in actionKeys "PushToTalkDirect" || _code in actionKeys "VoiceOverNet") exitWith {
  121.  
  122. if(currentChannel > 5 || currentChannel < 3) then {
  123.  
  124. setCurrentChannel 5;
  125.  
  126. };
  127. };
  128.  
  129. //Holster / recall weapon. (Shift + H)
  130. case 35: {
  131. if (_shift && !_ctrlKey && !(currentWeapon player isEqualTo "")) then {
  132. life_curWep_h = currentWeapon player;
  133. player action ["SwitchWeapon", player, player, 100];
  134. player switchCamera cameraView;
  135. };
  136.  
  137. if (!_shift && _ctrlKey && !isNil "life_curWep_h" && {!(life_curWep_h isEqualTo "")}) then {
  138. if (life_curWep_h in [primaryWeapon player,secondaryWeapon player,handgunWeapon player]) then {
  139. player selectWeapon life_curWep_h;
  140. };
  141. };
  142. };
  143.  
  144. //Interaction key (default is Left Windows, can be mapped via Controls -> Custom -> User Action 10)
  145. case _interactionKey: {
  146. if (!life_action_inUse) then {
  147. [] spawn {
  148. private "_handle";
  149. _handle = [] spawn life_fnc_actionKeyHandler;
  150. waitUntil {scriptDone _handle};
  151. life_action_inUse = false;
  152. };
  153. };
  154. };
  155.  
  156. //Restraining (Shift + R)
  157. case 19: {
  158. if (_shift) then {_handled = true;};
  159. 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 {
  160. [] call life_fnc_restrainAction;
  161. };
  162. };
  163.  
  164. //Knock out, this is experimental and yeah... (Shift + G)
  165. case 34: {
  166. if (_shift) then {_handled = true;};
  167. if (_shift && playerSide isEqualTo civilian && !isNull cursorObject && cursorObject isKindOf "Man" && isPlayer cursorObject && alive cursorObject && cursorObject distance player < 4 && speed cursorObject < 1) then {
  168. 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 {
  169. [cursorObject] spawn life_fnc_knockoutAction;
  170. };
  171. };
  172. };
  173.  
  174. //T Key (Trunk)
  175. case 20: {
  176. if (!_alt && !_ctrlKey && !dialog && {!life_action_inUse}) then {
  177. if (vehicle player != player && alive vehicle player) then {
  178. if ((vehicle player) in life_vehicles) then {
  179. [vehicle player] spawn life_fnc_openInventory;
  180. };
  181. } else {
  182. private "_list";
  183. _list = ((ASLtoATL (getPosASL player)) nearEntities [["Box_IND_Grenades_F","B_supplyCrate_F"], 2.5]) select 0;
  184. if (!(isNil "_list")) then {
  185. _house = nearestObject [(ASLtoATL (getPosASL _list)), "House"];
  186. if (_house getVariable ["locked", false]) then {
  187. hint localize "STR_House_ContainerDeny";
  188. } else {
  189. [_list] spawn life_fnc_openInventory;
  190. };
  191. } else {
  192. _list = ["landVehicle","Air","Ship"];
  193. if (KINDOF_ARRAY(cursorObject,_list) && {player distance cursorObject < 7} && {isNull objectParent player} && {alive cursorObject} && {!life_action_inUse}) then {
  194. if (cursorObject in life_vehicles) then {
  195. [cursorObject] spawn life_fnc_openInventory;
  196. };
  197. };
  198. };
  199. };
  200. };
  201. };
  202.  
  203. //L Key?
  204. case 38: {
  205. //If cop run checks for turning lights on.
  206. if (_shift && playerSide in [west,independent]) then {
  207. if (vehicle player != 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 {
  208. if (!isNil {vehicle player getVariable "lights"}) then {
  209. if (playerSide isEqualTo west) then {
  210. [vehicle player] call life_fnc_sirenLights;
  211. } else {
  212. [vehicle player] call life_fnc_medicSirenLights;
  213. };
  214. _handled = true;
  215. };
  216. };
  217. };
  218.  
  219. if (!_alt && !_ctrlKey) then { [] call life_fnc_radar; };
  220. };
  221.  
  222. //Y Player Menu
  223. case 21: {
  224. if (!_alt && !_ctrlKey && !dialog && !(player getVariable ["restrained",false]) && {!life_action_inUse}) then {
  225. if (!_shift) then {
  226. [] call life_fnc_p_openMenu;
  227. } else {
  228. [] call life_fnc_altisPhone;
  229. };
  230. };
  231. };
  232.  
  233. case 207:
  234. {
  235. if(_shift) then {
  236. switch (player getVariable["Earplugs",0]) do {
  237. case 0: {hintSilent "Ear Plugs 90%"; 1 fadeSound 0.1; player setVariable ["Earplugs", 10]; };
  238. case 10: {hintSilent "Ear Plugs 60%"; 1 fadeSound 0.4; player setVariable ["Earplugs", 40]; };
  239. case 40: {hintSilent "Ear Plugs 30%"; 1 fadeSound 0.7; player setVariable ["Earplugs", 70]; };
  240. case 70: {hintSilent "Ear Plugs Removed"; 1 fadeSound 1; player setVariable ["Earplugs", 0]; };
  241. };
  242. };
  243. };
  244.  
  245. //F Key
  246. case 33: {
  247. if (playerSide in [west,independent] && {vehicle player != player} && {!life_siren_active} && {((driver vehicle player) == player)}) then {
  248. [] spawn {
  249. life_siren_active = true;
  250. sleep 4.7;
  251. life_siren_active = false;
  252. };
  253.  
  254. _veh = vehicle player;
  255. if (isNil {_veh getVariable "siren"}) then {_veh setVariable ["siren",false,true];};
  256. if ((_veh getVariable "siren")) then {
  257. titleText [localize "STR_MISC_SirensOFF","PLAIN"];
  258. _veh setVariable ["siren",false,true];
  259. } else {
  260. titleText [localize "STR_MISC_SirensON","PLAIN"];
  261. _veh setVariable ["siren",true,true];
  262. if (playerSide isEqualTo west) then {
  263. [_veh] remoteExec ["life_fnc_copSiren",RCLIENT];
  264. } else {
  265. [_veh] remoteExec ["life_fnc_medicSiren",RCLIENT];
  266. };
  267. };
  268. };
  269. };
  270.  
  271. //O Key
  272. case 24: {
  273. if (_shift) then {
  274. if (soundVolume != 1) then {
  275. 1 fadeSound 1;
  276. systemChat localize "STR_MISC_soundnormal";
  277. } else {
  278. 1 fadeSound 0.1;
  279. systemChat localize "STR_MISC_soundfade";
  280. };
  281. };
  282. };
  283.  
  284. //U Key
  285. case 22: {
  286. if (!_alt && !_ctrlKey) then {
  287. if (isNull objectParent player) then {
  288. _veh = cursorObject;
  289. } else {
  290. _veh = vehicle player;
  291. };
  292.  
  293. if (_veh isKindOf "House_F" && {playerSide isEqualTo civilian}) then {
  294. if (_veh in life_vehicles && player distance _veh < 8) then {
  295. _door = [_veh] call life_fnc_nearestDoor;
  296. if (_door isEqualTo 0) exitWith {hint localize "STR_House_Door_NotNear"};
  297. _locked = _veh getVariable [format["bis_disabled_Door_%1",_door],0];
  298.  
  299. if (_locked isEqualTo 0) then {
  300. _veh setVariable [format["bis_disabled_Door_%1",_door],1,true];
  301. _veh animate [format["door_%1_rot",_door],0];
  302. systemChat localize "STR_House_Door_Lock";
  303. } else {
  304. _veh setVariable [format["bis_disabled_Door_%1",_door],0,true];
  305. _veh animate [format["door_%1_rot",_door],1];
  306. systemChat localize "STR_House_Door_Unlock";
  307. };
  308. };
  309. } else {
  310. _locked = locked _veh;
  311. if (_veh in life_vehicles && player distance _veh < 8) then {
  312. if (_locked isEqualTo 2) then {
  313. if (local _veh) then {
  314. _veh lock 0;
  315.  
  316. // BI
  317. _veh animateDoor ["door_back_R",1];
  318. _veh animateDoor ["door_back_L",1];
  319. _veh animateDoor ['door_R',1];
  320. _veh animateDoor ['door_L',1];
  321. _veh animateDoor ['Door_L_source',1];
  322. _veh animateDoor ['Door_rear',1];
  323. _veh animateDoor ['Door_rear_source',1];
  324. _veh animateDoor ['Door_1_source',1];
  325. _veh animateDoor ['Door_2_source',1];
  326. _veh animateDoor ['Door_3_source',1];
  327. _veh animateDoor ['Door_LM',1];
  328. _veh animateDoor ['Door_RM',1];
  329. _veh animateDoor ['Door_LF',1];
  330. _veh animateDoor ['Door_RF',1];
  331. _veh animateDoor ['Door_LB',1];
  332. _veh animateDoor ['Door_RB',1];
  333. _veh animateDoor ['DoorL_Front_Open',1];
  334. _veh animateDoor ['DoorR_Front_Open',1];
  335. _veh animateDoor ['DoorL_Back_Open',1];
  336. _veh animateDoor ['DoorR_Back_Open ',1];
  337. } else {
  338. [_veh,0] remoteExecCall ["life_fnc_lockVehicle",_veh];
  339.  
  340. _veh animateDoor ["door_back_R",1];
  341. _veh animateDoor ["door_back_L",1];
  342. _veh animateDoor ['door_R',1];
  343. _veh animateDoor ['door_L',1];
  344. _veh animateDoor ['Door_L_source',1];
  345. _veh animateDoor ['Door_rear',1];
  346. _veh animateDoor ['Door_rear_source',1];
  347. _veh animateDoor ['Door_1_source',1];
  348. _veh animateDoor ['Door_2_source',1];
  349. _veh animateDoor ['Door_3_source',1];
  350. _veh animateDoor ['Door_LM',1];
  351. _veh animateDoor ['Door_RM',1];
  352. _veh animateDoor ['Door_LF',1];
  353. _veh animateDoor ['Door_RF',1];
  354. _veh animateDoor ['Door_LB',1];
  355. _veh animateDoor ['Door_RB',1];
  356. _veh animateDoor ['DoorL_Front_Open',1];
  357. _veh animateDoor ['DoorR_Front_Open',1];
  358. _veh animateDoor ['DoorL_Back_Open',1];
  359. _veh animateDoor ['DoorR_Back_Open ',1];
  360. };
  361. systemChat localize "STR_MISC_VehUnlock";
  362. [_veh,"UnlockCarSound"] remoteExec ["life_fnc_say3D",RANY];
  363. } else {
  364. if (local _veh) then {
  365. _veh lock 2;
  366.  
  367. _veh animateDoor ["door_back_R",0];
  368. _veh animateDoor ["door_back_L",0];
  369. _veh animateDoor ['door_R',0];
  370. _veh animateDoor ['door_L',0];
  371. _veh animateDoor ['Door_L_source',0];
  372. _veh animateDoor ['Door_rear',0];
  373. _veh animateDoor ['Door_rear_source',0];
  374. _veh animateDoor ['Door_1_source',0];
  375. _veh animateDoor ['Door_2_source',0];
  376. _veh animateDoor ['Door_3_source',0];
  377. _veh animateDoor ['Door_LM',0];
  378. _veh animateDoor ['Door_RM',0];
  379. _veh animateDoor ['Door_LF',0];
  380. _veh animateDoor ['Door_RF',0];
  381. _veh animateDoor ['Door_LB',0];
  382. _veh animateDoor ['Door_RB',0];
  383. _veh animateDoor ['DoorL_Front_Open',0];
  384. _veh animateDoor ['DoorR_Front_Open',0];
  385. _veh animateDoor ['DoorL_Back_Open',0];
  386. _veh animateDoor ['DoorR_Back_Open ',0];
  387. } else {
  388. [_veh,2] remoteExecCall ["life_fnc_lockVehicle",_veh];
  389.  
  390. _veh animateDoor ["door_back_R",0];
  391. _veh animateDoor ["door_back_L",0];
  392. _veh animateDoor ['door_R',0];
  393. _veh animateDoor ['door_L',0];
  394. _veh animateDoor ['Door_L_source',0];
  395. _veh animateDoor ['Door_rear',0];
  396. _veh animateDoor ['Door_rear_source',0];
  397. _veh animateDoor ['Door_1_source',0];
  398. _veh animateDoor ['Door_2_source',0];
  399. _veh animateDoor ['Door_3_source',0];
  400. _veh animateDoor ['Door_LM',0];
  401. _veh animateDoor ['Door_RM',0];
  402. _veh animateDoor ['Door_LF',0];
  403. _veh animateDoor ['Door_RF',0];
  404. _veh animateDoor ['Door_LB',0];
  405. _veh animateDoor ['Door_RB',0];
  406. _veh animateDoor ['DoorL_Front_Open',0];
  407. _veh animateDoor ['DoorR_Front_Open',0];
  408. _veh animateDoor ['DoorL_Back_Open',0];
  409. _veh animateDoor ['DoorR_Back_Open ',0];
  410. };
  411. systemChat localize "STR_MISC_VehLock";
  412. [_veh,"LockCarSound"] remoteExec ["life_fnc_say3D",RANY];
  413. };
  414. };
  415. };
  416. };
  417. };
  418. };
  419.  
  420. _handled;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement