Advertisement
Guest User

fn_keyHandler

a guest
Aug 2nd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.82 KB | None | 0 0
  1. #include <macro.h>
  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 cursorTarget;
  16. _handled = false;
  17.  
  18. _interactionKey = if(count (actionKeys "User10") == 0) then {219} else {(actionKeys "User10") select 0};
  19. _mapKey = actionKeys "ShowMap" select 0;
  20. //hintSilent 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")) && {(player getVariable ["restrained",false])}) 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") != 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. {
  39. private["_handle"];
  40. _handle = [] spawn life_fnc_actionKeyHandler;
  41. waitUntil {scriptDone _handle};
  42. life_action_inUse = false;
  43. };
  44. };
  45. true;
  46. };
  47.  
  48. switch (_code) do
  49. {
  50. //Space key for Jumping
  51. case 57:
  52. {
  53. if(isNil "jumpActionTime") then {jumpActionTime = 0;};
  54. if(_shift && {animationState player != "AovrPercMrunSrasWrflDf"} && {isTouchingGround player} && {stance player == "STAND"} && {speed player > 2} && {!life_is_arrested} && {(velocity player) select 2 < 2.5} && {time - jumpActionTime > 1.5}) then {
  55. jumpActionTime = time; //Update the time.
  56. [player,true] spawn life_fnc_jumpFnc; //Local execution
  57. [[player,false],"life_fnc_jumpFnc",nil,FALSE] call life_fnc_MP; //Global execution
  58. _handled = true;
  59. };
  60. };
  61.  
  62. //Map Key
  63. case _mapKey:
  64. {
  65. switch (playerSide) do
  66. {
  67. case west: {if(!visibleMap) then {[] spawn life_fnc_copMarkers;}};
  68. case independent: {if(!visibleMap) then {[] spawn life_fnc_medicMarkers;}};
  69. case civilian: {if(!visibleMap) then {[] spawn life_fnc_gangMarkers;}};
  70. };
  71. };
  72.  
  73. //Surrender... shift + g
  74. case 34:
  75. {
  76. if(_shift) then {_handled = true;};
  77.  
  78. if (_shift) then
  79. {
  80. if (vehicle player == player && !(player getVariable ["restrained", false]) && (animationState player) != "Incapacitated" && !life_istazed) then
  81. {
  82. if (player getVariable ["surrender", false]) then
  83. {
  84. player setVariable ["surrender", false, true];
  85. } else
  86. {
  87. [] spawn life_fnc_surrender;
  88. };
  89. };
  90. };
  91. };
  92.  
  93. //Holster / recall weapon.
  94. case 35:
  95. {
  96. if(_shift && !_ctrlKey && currentWeapon player != "") then {
  97. life_curWep_h = currentWeapon player;
  98. player action ["SwitchWeapon", player, player, 100];
  99. player switchcamera cameraView;
  100. };
  101.  
  102. if(!_shift && _ctrlKey && !isNil "life_curWep_h" && {(life_curWep_h != "")}) then {
  103. if(life_curWep_h in [primaryWeapon player,secondaryWeapon player,handgunWeapon player]) then {
  104. player selectWeapon life_curWep_h;
  105. };
  106. };
  107. };
  108.  
  109. //Interaction key (default is Left Windows, can be mapped via Controls -> Custom -> User Action 10)
  110. case _interactionKey:
  111. {
  112. if(!life_action_inUse) then {
  113. [] spawn
  114. {
  115. private["_handle"];
  116. _handle = [] spawn life_fnc_actionKeyHandler;
  117. waitUntil {scriptDone _handle};
  118. life_action_inUse = false;
  119. };
  120. };
  121. };
  122.  
  123. //Knock out - Shift + T
  124. case 47:
  125. {
  126. if(_shift) then {_handled = true;};
  127. if(_shift && playerSide == civilian && !isNull cursorTarget && cursorTarget isKindOf "Man" && isPlayer cursorTarget && alive cursorTarget && cursorTarget distance player < 4 && speed cursorTarget < 1) then
  128. {
  129. if((animationState cursorTarget) != "Incapacitated" && (currentWeapon player == primaryWeapon player OR currentWeapon player == handgunWeapon player) && currentWeapon player != "" && !life_knockout && !(player getVariable["restrained",false]) && !life_istazed) then
  130. {
  131. [cursorTarget] spawn life_fnc_knockoutAction;
  132. };
  133. };
  134. };
  135.  
  136. //Restraining (Shift + R)
  137. case 19:
  138. {
  139. if(_shift) then {_handled = true;};
  140. if(_shift && playerSide == west && !isNull cursorTarget && cursorTarget isKindOf "Man" && (isPlayer cursorTarget) && (side cursorTarget in [civilian,independent]) && alive cursorTarget && cursorTarget distance player < 3.5 && !(cursorTarget getVariable "Escorting") && !(cursorTarget getVariable "restrained") && speed cursorTarget < 1) then
  141. {
  142. [] call life_fnc_restrainAction;
  143. };
  144. };
  145.  
  146. //T Key (Trunk)
  147. case 20:
  148. {
  149. if(!_alt && !_ctrlKey) then
  150. {
  151. if(vehicle player != player && alive vehicle player) then
  152. {
  153. if((vehicle player) in life_vehicles) then
  154. {
  155. [vehicle player] call life_fnc_openInventory;
  156. };
  157. }
  158. else
  159. {
  160. if((cursorTarget isKindOf "Car" OR cursorTarget isKindOf "Air" OR cursorTarget isKindOf "Ship" OR cursorTarget isKindOf "House_F") && player distance cursorTarget < 7 && vehicle player == player && alive cursorTarget) then
  161. {
  162. if(cursorTarget in life_vehicles OR {!(cursorTarget getVariable ["locked",true])}) then
  163. {
  164. [cursorTarget] call life_fnc_openInventory;
  165. };
  166. };
  167. };
  168. };
  169. };
  170.  
  171. //L Key?
  172. case 38:
  173. {
  174. //If cop run checks for turning lights on.
  175. if(_shift && playerSide in [west,independent]) then {
  176. 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","C_Hatchback_01_F"]) then {
  177. if(!isNil {vehicle player getVariable "lights"}) then {
  178. if(playerSide == west) then {
  179. [vehicle player] call life_fnc_sirenLights;
  180. } else {
  181. [vehicle player] call life_fnc_sirenLights;
  182. };
  183. _handled = true;
  184. };
  185. };
  186. };
  187.  
  188. if(!_alt && !_ctrlKey) then { [] call life_fnc_radar; };
  189. };
  190.  
  191. //F Key
  192. case 33:
  193. {
  194. if (vehicle player != player && (typeOf vehicle player) in["C_Offroad_01_repair_F","B_Truck_01_transport_F"]) exitWith {hintSilent "Sirene nicht verfügbar"};
  195. if(playerSide in [west,independent] && vehicle player != player && !life_siren_active && ((driver vehicle player) == player)) then
  196. {
  197. [] spawn
  198. {
  199. life_siren_active = true;
  200. uiSleep 4.5;
  201. life_siren_active = false;
  202. };
  203. _veh = vehicle player;
  204. if(isNil {_veh getVariable "siren"}) then {_veh setVariable["siren",false,true];};
  205. if((_veh getVariable "siren")) then
  206. {
  207. titleText ["Sirene AUS","PLAIN"];
  208. _veh setVariable["siren",false,true];
  209. }
  210. else
  211. {
  212. titleText ["Sirene AN","PLAIN"];
  213. _veh setVariable["siren",true,true];
  214. if(playerSide == west) then {
  215. [[_veh],"life_fnc_copSiren",nil,true] spawn life_fnc_MP;
  216. } else {
  217. [[_veh],"life_fnc_medicSiren",nil,true] spawn life_fnc_MP;
  218. };
  219. };
  220. };
  221. };
  222.  
  223. //Ö Key
  224. case 39:
  225. {
  226. if(playerSide in [west] && vehicle player != player && !life_siren_active && ((driver vehicle player) == player)) then
  227. {
  228. [] spawn
  229. {
  230. life_siren_active = true;
  231. uiSleep 7;
  232. life_siren_active = false;
  233. };
  234. _veh = vehicle player;
  235. if(isNil {_veh getVariable "siren2"}) then {_veh setVariable["siren2",false,true];};
  236. if((_veh getVariable "siren2")) then
  237. {
  238. titleText ["Warnung AUS","PLAIN"];
  239. _veh setVariable["siren2",false,true];
  240. }
  241. else
  242. {
  243. titleText ["Warnung AN","PLAIN"];
  244. _veh setVariable["siren2",true,true];
  245. if(playerSide == west) then {
  246. [[_veh],"life_fnc_copSiren2",nil,true] spawn life_fnc_MP;
  247. } else {
  248. [[_veh],"life_fnc_medicSiren",nil,true] spawn life_fnc_MP;
  249. };
  250. };
  251. };
  252. };
  253.  
  254. //Shift+O Zipties
  255. case 24:
  256. {
  257. if(_shift) then {_handled = true;};
  258. if(playerSide in [west,independent]) exitWith {};
  259. if !(license_civ_rebel) exitWith { hintSilent "You need a rebel license !"; };
  260. if(_shift && playerSide == civilian && !isNull cursorTarget && cursorTarget isKindOf "Man" && (isPlayer cursorTarget) && (side cursorTarget in [civilian,east]) && alive cursorTarget && cursorTarget distance player < 3.5 && !(cursorTarget getVariable "Escorting") && !(cursorTarget getVariable "restrained") && speed cursorTarget < 1) then
  261. {
  262. if([false,"zipties",1] call life_fnc_handleInv) then
  263. {
  264. [] call life_fnc_restrainAction;
  265. hintSilent "You have cuffed him! ";
  266. } else {
  267. hintSilent "You don't have zipties";
  268. };
  269. };
  270. };
  271.  
  272. //U Key
  273. case 22:
  274. {
  275. if(!_alt && !_ctrlKey) then {
  276. if(vehicle player == player) then {
  277. _veh = cursorTarget;
  278. } else {
  279. _veh = vehicle player;
  280. };
  281.  
  282. if(_veh isKindOf "House_F" && playerSide == civilian) then {
  283. if(_veh in life_vehicles && player distance _veh < 8) then {
  284. _door = [_veh] call life_fnc_nearestDoor;
  285. if(_door == 0) exitWith {hintSilent "You're not near a door"};
  286. _locked = _veh getVariable [format["bis_disabled_Door_%1",_door],0];
  287. if(_locked == 0) then {
  288. _veh setVariable[format["bis_disabled_Door_%1",_door],1,true];
  289. _veh animate [format["door_%1_rot",_door],0];
  290. systemChat "The door has been locked";
  291. } else {
  292. _veh setVariable[format["bis_disabled_Door_%1",_door],0,true];
  293. _veh animate [format["door_%1_rot",_door],1];
  294. systemChat "The door has been opened";
  295. };
  296. };
  297. } else {
  298. _locked = locked _veh;
  299. if(_veh in life_vehicles && player distance _veh < 8) then {
  300. if(_locked == 2) then {
  301. if(local _veh) then {
  302. _veh lock 0;
  303. } else {
  304. [[_veh,0],"life_fnc_lockVehicle",_veh,false] spawn life_fnc_MP;
  305. };
  306. systemChat "You have unlocked the vehicle";
  307. [[_veh],"life_fnc_LockCarSound",nil,true] spawn life_fnc_MP;
  308. } else {
  309. if(local _veh) then {
  310. _veh lock 2;
  311. } else {
  312. [[_veh,2],"life_fnc_lockVehicle",_veh,false] spawn life_fnc_MP;
  313. };
  314. systemChat "You have locked the vehicle";
  315. [[_veh],"life_fnc_UnLockCarSound",nil,true] spawn life_fnc_MP;
  316. };
  317. };
  318. };
  319. };
  320. };
  321.  
  322. //EMP Konsole - K
  323. case 37:
  324. {
  325. if (!_shift && !_alt && !_ctrlKey && (playerSide == west) && (vehicle player != player && (typeOf vehicle player) in ["B_Heli_Light_01_F"])) then
  326. {
  327. [] call life_fnc_openEmpMenu; [_this] call life_fnc_isEmpOperator;
  328. };
  329. };
  330.  
  331. //Pickaxe - Q
  332. case 41:
  333. {
  334. if((!life_action_inUse) && (vehicle player == player) ) then
  335. {
  336. {
  337. _str = [_x] call life_fnc_varToStr;
  338. _val = missionNameSpace getVariable _x;
  339. if(_val > 0 ) then
  340. {
  341. if( _str == "Spitzhacke" || _str == "pickaxe" ) then
  342. {
  343. [] spawn life_fnc_pickAxeUse;
  344. };
  345. };
  346. } foreach life_inv_items;
  347. }
  348. };
  349.  
  350. //SmartPhone Shift + 1
  351. case 2:
  352. {
  353. if(_shift) then {_handled = true;};
  354. if (_shift) then
  355. {
  356. if(!_alt && !_ctrlKey && !dialog) then
  357. {
  358. [] call life_fnc_callCellPhone;
  359. };
  360. };
  361. };
  362.  
  363. //Wanted List Shift + 2
  364. case 3:
  365. {
  366. if(playerSide in [independent,civilian]) exitWith {};
  367. if(_shift) then {_handled = true;};
  368. if (_shift) then
  369. {
  370. if(!_alt && !_ctrlKey && !dialog) then
  371. {
  372. [] call life_fnc_wantedMenu;
  373. };
  374. };
  375. };
  376.  
  377. //Wanted List Shift + 3
  378. case 4:
  379. {
  380. if(playerSide in [independent,civilian]) exitWith {};
  381. if(_shift) then {_handled = true;};
  382. if (_shift) then
  383. {
  384. if(!_alt && !_ctrlKey && !dialog) then
  385. {
  386. createDialog "life_wantedadd2";
  387. };
  388. };
  389. };
  390.  
  391. // O Schranken öffnen
  392. case 40:
  393. {
  394. if (!_shift && !_alt && !_ctrlKey && (playerSide in [west,independent]) && (vehicle player != player)) then {
  395. [] call life_fnc_copOpener;
  396. };
  397. };
  398.  
  399. //Ü Nagelbänder
  400. case 26:
  401. {
  402. if(vehicle player != player) exitWith {hintSilent "You're in a vehicle!"};
  403. if(playerSide == west) then {
  404.  
  405. if(!isNull life_spikestrip) exitWith {hintSilent "You have placed a SpikeStrip"};
  406. if(([false,"spikeStrip",1] call life_fnc_handleInv)) then
  407. {
  408. [] spawn life_fnc_spikeStrip;
  409. };
  410.  
  411. };
  412. };
  413.  
  414. case 59: // F1
  415. {
  416. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  417. closeDialog 0;
  418. hintc "This button got blocked from the server";
  419. _handled = false;
  420. };
  421.  
  422. case 60: // F2
  423. {
  424. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  425. closeDialog 0;
  426. hintc "This button got blocked from the server";
  427. _handled = false;
  428. };
  429.  
  430. case 61: // F3
  431. {
  432. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  433. closeDialog 0;
  434. _handled = false;
  435. };
  436.  
  437. case 62: // F4
  438. {
  439. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  440. closeDialog 0;
  441. _handled = false;
  442. };
  443.  
  444. case 63: // F5
  445. {
  446. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  447. closeDialog 0;
  448. _handled = false;
  449. };
  450.  
  451. case 64: //F6 key
  452. {
  453. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  454. closeDialog 0;
  455. _handled = false;
  456. };
  457.  
  458. case 65: // F7 Key
  459. {
  460. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  461. closeDialog 0;
  462. _handled = false;
  463. };
  464.  
  465. case 66: //F8 key
  466. {
  467. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  468. closeDialog 0;
  469. _handled = false;
  470. };
  471.  
  472. case 67: //F9 key
  473. {
  474. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  475. closeDialog 0;
  476. _handled = false;
  477. };
  478.  
  479. case 68: //10 key
  480. {
  481. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  482. closeDialog 0;
  483. _handled = false;
  484. };
  485.  
  486. case 211: //DELETE key
  487. {
  488. if(__GETC__(life_adminlevel) > 0) exitWith {hintSilent "AdminLogin successfull"};
  489. closeDialog 0;
  490. _handled = false;
  491. };
  492. };
  493. _handled;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement