Advertisement
Guest User

Untitled

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