Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.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. //Gathering
  102. case 18:
  103. {
  104. if(playerSide == civilian && !life_action_gathering) then {
  105. _handle = [] spawn life_fnc_gather;
  106. waitUntil {scriptDone _handle};
  107. life_action_gathering = false;
  108. };
  109.  
  110. //pickaxe key :))))))
  111. case 16:
  112. {
  113. if((!life_action_inUse) && (vehicle player == player) ) then
  114. {
  115. {
  116. _str = [_x] call life_fnc_varToStr;
  117. _val = missionNameSpace getVariable _x;
  118. if(_val > 0 ) then
  119. {
  120. if( _str == "Spitzhacke" || _str == "pickaxe" ) then
  121. {
  122. [] spawn life_fnc_pickAxeUse;
  123. };
  124. };
  125. } foreach life_inv_items;
  126. }
  127. };
  128.  
  129. //Restraining (Shift + R)
  130. case 19:
  131. {
  132. if(_shift) then {_handled = true;};
  133. 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
  134. {
  135. [] call life_fnc_restrainAction;
  136. };
  137. };
  138.  
  139. //Knock out, this is experimental and yeah...
  140. case 34:
  141. {
  142. if(_shift) then {_handled = true;};
  143. if(_shift && playerSide == civilian && !isNull cursorTarget && cursorTarget isKindOf "Man" && isPlayer cursorTarget && alive cursorTarget && cursorTarget distance player < 4 && speed cursorTarget < 1) then
  144. {
  145. if((animationState cursorTarget) != "Incapacitated" && (currentWeapon player == primaryWeapon player OR currentWeapon player == handgunWeapon player) && currentWeapon player != "" && !life_knockout && !(player getVariable["restrained",false]) && !life_istazed) then
  146. {
  147. [cursorTarget] spawn life_fnc_knockoutAction;
  148. };
  149. };
  150. };
  151.  
  152. case 62:
  153. {
  154. if(_alt && !alive player) then
  155. {
  156. removeAllWeapons player;
  157. {player removeMagazine _x} foreach (magazines player);
  158. [] call life_fnc_saveGear;
  159. };
  160. };
  161.  
  162. //T Key (Trunk)
  163. case 20:
  164. {
  165. if(!_alt && !_ctrlKey) then
  166. {
  167. if(vehicle player != player && alive vehicle player) then
  168. {
  169. if((vehicle player) in life_vehicles) then
  170. {
  171. [vehicle player] call life_fnc_openInventory;
  172. };
  173. }
  174. else
  175. {
  176. 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
  177. {
  178. if(cursorTarget in life_vehicles OR {!(cursorTarget getVariable ["locked",true])}) then
  179. {
  180. [cursorTarget] call life_fnc_openInventory;
  181. };
  182. };
  183. };
  184. };
  185. };
  186.  
  187. //L Key?
  188. case 38:
  189. {
  190. //If cop run checks for turning lights on.
  191. if(_shift && playerSide in [west,independent]) then {
  192. if(vehicle player != player && (typeOf vehicle player) in ["C_Offroad_01_F","B_MRAP_01_F","C_SUV_01_F"]) then {
  193. if(!isNil {vehicle player getVariable "lights"}) then {
  194. if(playerSide == west) then {
  195. [vehicle player] call life_fnc_sirenLights;
  196. } else {
  197. [vehicle player] call life_fnc_medicSirenLights;
  198. };
  199. _handled = true;
  200. };
  201. };
  202. };
  203.  
  204. if(!_alt && !_ctrlKey) then { [] call life_fnc_radar; };
  205. };
  206. //Y Player Menu
  207. case 21:
  208. {
  209. if(!_alt && !_ctrlKey && !dialog) then
  210. {
  211. [] call life_fnc_p_openMenu;
  212. };
  213. };
  214.  
  215. //F Key
  216. case 33:
  217. {
  218. if(playerSide in [west,independent] && vehicle player != player && !life_siren_active && ((driver vehicle player) == player)) then
  219. {
  220. [] spawn
  221. {
  222. life_siren_active = true;
  223. sleep 4.7;
  224. life_siren_active = false;
  225. };
  226. _veh = vehicle player;
  227. if(isNil {_veh getVariable "siren"}) then {_veh setVariable["siren",false,true];};
  228. if((_veh getVariable "siren")) then
  229. {
  230. titleText [localize "STR_MISC_SirensOFF","PLAIN"];
  231. _veh setVariable["siren",false,true];
  232. }
  233. else
  234. {
  235. titleText [localize "STR_MISC_SirensON","PLAIN"];
  236. _veh setVariable["siren",true,true];
  237. if(playerSide == west) then {
  238. [[_veh],"life_fnc_copSiren",nil,true] spawn life_fnc_MP;
  239. } else {
  240. //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.
  241. [[_veh],"life_fnc_medicSiren",nil,true] spawn life_fnc_MP;
  242. };
  243. };
  244. };
  245. };
  246. //U Key
  247. case 22:
  248. {
  249. if(!_alt && !_ctrlKey) then {
  250. if(vehicle player == player) then {
  251. _veh = cursorTarget;
  252. } else {
  253. _veh = vehicle player;
  254. };
  255.  
  256. if(_veh isKindOf "House_F" && playerSide == civilian) then {
  257. if(_veh in life_vehicles && player distance _veh < 8) then {
  258. _door = [_veh] call life_fnc_nearestDoor;
  259. if(_door == 0) exitWith {hint localize "STR_House_Door_NotNear"};
  260. _locked = _veh getVariable [format["bis_disabled_Door_%1",_door],0];
  261. if(_locked == 0) then {
  262. _veh setVariable[format["bis_disabled_Door_%1",_door],1,true];
  263. _veh animate [format["door_%1_rot",_door],0];
  264. systemChat localize "STR_House_Door_Lock";
  265. } else {
  266. _veh setVariable[format["bis_disabled_Door_%1",_door],0,true];
  267. _veh animate [format["door_%1_rot",_door],1];
  268. systemChat localize "STR_House_Door_Unlock";
  269. };
  270. };
  271. } else {
  272. _locked = locked _veh;
  273. if(_veh in life_vehicles && player distance _veh < 8) then {
  274. if(_locked == 2) then {
  275. if(local _veh) then {
  276. _veh lock 0;
  277. } else {
  278. [[_veh,0],"life_fnc_lockVehicle",_veh,false] spawn life_fnc_MP;
  279. };
  280. systemChat localize "STR_MISC_VehUnlock";
  281. player say3D "unlock";
  282. } else {
  283. if(local _veh) then {
  284. _veh lock 2;
  285. } else {
  286. [[_veh,2],"life_fnc_lockVehicle",_veh,false] spawn life_fnc_MP;
  287. };
  288. systemChat localize "STR_MISC_VehLock";
  289. player say3D "lock";
  290. };
  291. };
  292. };
  293. };
  294. };
  295. };
  296.  
  297. _handled;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement