Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.03 KB | None | 0 0
  1. /*
  2. File: fn_keyHandler.sqf
  3. Author: Bryan "Tonic" Boardwine
  4.  
  5. Description:
  6. Main key handler for event 'keyDown'
  7. */
  8. private ["_handled","_shift","_alt","_code","_ctrl","_alt","_ctrlKey","_veh","_locked","_interactionKey","_mapKey","_interruptionKeys"];
  9. _ctrl = _this select 0;
  10. _code = _this select 1;
  11. _shift = _this select 2;
  12. _ctrlKey = _this select 3;
  13. _alt = _this select 4;
  14. _speed = speed cursorTarget;
  15. _handled = false;
  16.  
  17. _interactionKey = if(count (actionKeys "User10") == 0) then {219} else {(actionKeys "User10") select 0};
  18. _mapKey = actionKeys "ShowMap" select 0;
  19. //hint str _code;
  20. _interruptionKeys = [17,30,31,32]; //A,S,W,D
  21.  
  22. //Vault handling...
  23. if((_code in (actionKeys "GetOver") || _code in (actionKeys "salute")) && {(player getVariable ["restrained",false])}) exitWith {
  24. true;
  25. };
  26.  
  27. if(life_action_inUse) exitWith {
  28. if(!life_interrupted && _code in _interruptionKeys) then {life_interrupted = true;};
  29. _handled;
  30. };
  31.  
  32. //Hotfix for Interaction key not being able to be bound on some operation systems.
  33. if(count (actionKeys "User10") != 0 && {(inputAction "User10" > 0)}) exitWith {
  34. //Interaction key (default is Left Windows, can be mapped via Controls -> Custom -> User Action 10)
  35. if(!life_action_inUse) then {
  36. [] spawn
  37. {
  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. switch (_code) do
  48. {
  49. //Space key for Jumping
  50. case 57:
  51. {
  52. if(isNil "jumpActionTime") then {jumpActionTime = 0;};
  53. 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 {
  54. jumpActionTime = time; //Update the time.
  55. [player,true] spawn life_fnc_jumpFnc; //Local execution
  56. [[player,false],"life_fnc_jumpFnc",nil,FALSE] call life_fnc_MP; //Global execution
  57. _handled = true;
  58. };
  59. };
  60.  
  61. //Map Key
  62. case _mapKey:
  63. {
  64. switch (playerSide) do
  65. {
  66. case west: {if(!visibleMap) then {[] spawn life_fnc_copMarkers;}};
  67. case independent: {if(!visibleMap) then {[] spawn life_fnc_medicMarkers;}};
  68. };
  69. };
  70.  
  71. //Holster / recall weapon.
  72. case 35:
  73. {
  74. if(_shift && !_ctrlKey && currentWeapon player != "") then {
  75. life_curWep_h = currentWeapon player;
  76. player action ["SwitchWeapon", player, player, 100];
  77. player switchcamera cameraView;
  78. };
  79.  
  80. if(!_shift && _ctrlKey && !isNil "life_curWep_h" && {(life_curWep_h != "")}) then {
  81. if(life_curWep_h in [primaryWeapon player,secondaryWeapon player,handgunWeapon player]) then {
  82. player selectWeapon life_curWep_h;
  83. };
  84. };
  85. };
  86.  
  87. //Interaction key (default is Left Windows, can be mapped via Controls -> Custom -> User Action 10)
  88. case _interactionKey:
  89. {
  90. if(!life_action_inUse) then {
  91. [] spawn
  92. {
  93. private["_handle"];
  94. _handle = [] spawn life_fnc_actionKeyHandler;
  95. waitUntil {scriptDone _handle};
  96. life_action_inUse = false;
  97. };
  98. };
  99. };
  100.  
  101. //Restraining (Shift + R)
  102. case 19:
  103. {
  104. if(_shift) then {_handled = true;};
  105. 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
  106. {
  107. [] call life_fnc_restrainAction;
  108. };
  109. };
  110.  
  111. //Knock out, this is experimental and yeah...
  112. case 34:
  113. {
  114. if(_shift) then {_handled = true;};
  115. if(_shift && playerSide == civilian && !isNull cursorTarget && cursorTarget isKindOf "Man" && isPlayer cursorTarget && alive cursorTarget && cursorTarget distance player < 4 && speed cursorTarget < 1) then
  116. {
  117. if((animationState cursorTarget) != "Incapacitated" && (currentWeapon player == primaryWeapon player OR currentWeapon player == handgunWeapon player) && currentWeapon player != "" && !life_knockout && !(player getVariable["restrained",false]) && !life_istazed) then
  118. {
  119. [cursorTarget] spawn life_fnc_knockoutAction;
  120. };
  121. };
  122. };
  123.  
  124. //T Key (Trunk)
  125. case 20:
  126. {
  127. if(!_alt && !_ctrlKey) then
  128. {
  129. if(vehicle player != player && alive vehicle player) then
  130. {
  131. if((vehicle player) in life_vehicles) then
  132. {
  133. [vehicle player] call life_fnc_openInventory;
  134. };
  135. }
  136. else
  137. {
  138. 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
  139. {
  140. if(cursorTarget in life_vehicles OR {!(cursorTarget getVariable ["locked",true])}) then
  141. {
  142. [cursorTarget] call life_fnc_openInventory;
  143. };
  144. };
  145. };
  146. };
  147. };
  148. //L Key?
  149. case 38:
  150. {
  151. //If cop run checks for turning lights on.
  152. if(_shift && playerSide in [west,independent]) then {
  153. if(vehicle player != player && (typeOf vehicle player) in ["C_Offroad_01_F","B_MRAP_01_F","C_SUV_01_F"]) then {
  154. if(!isNil {vehicle player getVariable "lights"}) then {
  155. if(playerSide == west) then {
  156. [vehicle player] call life_fnc_sirenLights;
  157. } else {
  158. [vehicle player] call life_fnc_medicSirenLights;
  159. };
  160. _handled = true;
  161. };
  162. };
  163. };
  164.  
  165. if(!_alt && !_ctrlKey) then { [] call life_fnc_radar; };
  166. };
  167. //Y Player Menu
  168. case 21:
  169. {
  170. if(!_alt && !_ctrlKey && !dialog) then
  171. {
  172. [] call life_fnc_p_openMenu;
  173. };
  174. };
  175.  
  176. //F Key
  177. case 33:
  178. {
  179. if(playerSide in [west,independent] && vehicle player != player && !life_siren_active && ((driver vehicle player) == player)) then
  180. {
  181. [] spawn
  182. {
  183. life_siren_active = true;
  184. sleep 4.7;
  185. life_siren_active = false;
  186. };
  187. _veh = vehicle player;
  188. if(isNil {_veh getVariable "siren"}) then {_veh setVariable["siren",false,true];};
  189. if((_veh getVariable "siren")) then
  190. {
  191. titleText [localize "STR_MISC_SirensOFF","PLAIN"];
  192. _veh setVariable["siren",false,true];
  193. }
  194. else
  195. {
  196. titleText [localize "STR_MISC_SirensON","PLAIN"];
  197. _veh setVariable["siren",true,true];
  198. if(playerSide == west) then {
  199. [[_veh],"life_fnc_copSiren",nil,true] spawn life_fnc_MP;
  200. } else {
  201. //I do not have a custom sound for this and I really don't want to go digging for one, when you have a sound uncomment this and change medicSiren.sqf in the medical folder.
  202. //[[_veh],"life_fnc_medicSiren",nil,true] spawn life_fnc_MP;
  203. };
  204. };
  205. };
  206. };
  207. //U Key
  208. case 22:
  209. {
  210. if(!_alt && !_ctrlKey) then {
  211. if(vehicle player == player) then {
  212. _veh = cursorTarget;
  213. } else {
  214. _veh = vehicle player;
  215. };
  216.  
  217. if(_veh isKindOf "House_F" && playerSide == civilian) then {
  218. if(_veh in life_vehicles && player distance _veh < 8) then {
  219. _door = [_veh] call life_fnc_nearestDoor;
  220. if(_door == 0) exitWith {hint localize "STR_House_Door_NotNear"};
  221. _locked = _veh getVariable [format["bis_disabled_Door_%1",_door],0];
  222. if(_locked == 0) then {
  223. _veh setVariable[format["bis_disabled_Door_%1",_door],1,true];
  224. _veh animate [format["door_%1_rot",_door],0];
  225. systemChat localize "STR_House_Door_Lock";
  226. } else {
  227. _veh setVariable[format["bis_disabled_Door_%1",_door],0,true];
  228. _veh animate [format["door_%1_rot",_door],1];
  229. systemChat localize "STR_House_Door_Unlock";
  230. };
  231. };
  232. } else {
  233. _locked = locked _veh;
  234. if(_veh in life_vehicles && player distance _veh < 8) then {
  235. if(_locked == 2) then {
  236. if(local _veh) then {
  237. _veh lock 0;
  238. } else {
  239. [[_veh,0],"life_fnc_lockVehicle",_veh,false] spawn life_fnc_MP;
  240. };
  241. systemChat localize "STR_MISC_VehUnlock";
  242. } else {
  243. if(local _veh) then {
  244. _veh lock 2;
  245. } else {
  246. [[_veh,2],"life_fnc_lockVehicle",_veh,false] spawn life_fnc_MP;
  247. };
  248. systemChat localize "STR_MISC_VehLock";
  249. };
  250. };
  251. };
  252. };
  253. };
  254. };
  255.  
  256. _handled;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement