Faguss

OFP inKeys function for input from Fwatch

May 21st, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. // Function checking if given string/array with strings is in _keys array
  2. // If so then it returns true
  3. // and sets _pressed variable to that string/last array item
  4.  
  5.  
  6. private ["_item", "_return", "_last", "_i", "_j", "_max"];
  7. _return = false;
  8.  
  9. if (_this in [_this]) then
  10. {
  11. // for single string
  12. if (_this in _keys && !(_this in _pressed)) then
  13. {
  14. // click
  15. _pressed = _pressed + [_this];
  16. _return = true;
  17. };
  18.  
  19. // release
  20. if (!(_this in _keys) && _this in _pressed) then
  21. {
  22. _pressed = _pressed - [_this];
  23. };
  24. }
  25.  
  26.  
  27. else
  28.  
  29.  
  30. {
  31. _item =+ _this;
  32.  
  33. // Sub-Arrays - alternative keys
  34. _i = 0;
  35. while "_i < count _item" do
  36. {
  37. // If a sub-array
  38. if (!((_item select _i) in [(_item select _i)])) then
  39. {
  40. // Remove from _pressed
  41. "if (!(_x in _keys)) then {_pressed=_pressed-[_x]}" forEach (_item select _i);
  42.  
  43. // If one of the key is pressed
  44. _j = 0;
  45. _max = count (_item select _i);
  46. while "_j < _max" do
  47. {
  48. if (((_item select _i) select _j) in _keys) then {_item set [_i, (_item select _i) select _j]; _j=_max};
  49. _j = _j + 1;
  50. };
  51.  
  52. // If none were pressed
  53. if (_j==_max) then {_item set [_i, "false"]};
  54. };
  55. _i = _i + 1;
  56. };
  57.  
  58.  
  59.  
  60. // for an array
  61. _last = _item select (count _item -1);
  62.  
  63. if ("_x in _keys" count _item == count _item && !(_last in _pressed)) then
  64. {
  65. // click
  66. _pressed = _pressed + [_last];
  67. _return = true;
  68. };
  69.  
  70. // release
  71. if (!(_last in _keys) && _last in _pressed) then
  72. {
  73. _pressed = _pressed - [_last];
  74. };
  75. };
  76.  
  77. _return
Add Comment
Please, Sign In to add comment