Advertisement
epitaque_

Untitled

Oct 29th, 2015
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. // addon_info.txt
  2. "AddonInfo"
  3. {
  4. "Default_Keys"
  5. {
  6. "01"
  7. {
  8. "Key" "W"
  9. "Command" "+KeyPressUp"
  10. "Name" "Move Up"
  11. }
  12. "02"
  13. {
  14. "Key" "A"
  15. "Command" "+KeyPressLeft"
  16. "Name" "Move Left"
  17. }
  18. "03"
  19. {
  20. "Key" "S"
  21. "Command" "+KeyPressDown"
  22. "Name" "Move Down"
  23. }
  24. "04"
  25. {
  26. "Key" "R"
  27. "Command" "+KeyPressRight"
  28. "Name" "Move Right"
  29. }
  30. "05"
  31. {
  32. "Key" "SPACE"
  33. "Command" "+KeyPressSpace"
  34. "Name" "Jump"
  35. }
  36. }
  37. }
  38.  
  39. // key register
  40. "use strict";
  41.  
  42. function WrapFunction(name)
  43. {
  44. return function() { Game[name](); };
  45. }
  46.  
  47. Game.AddCommand("+KeyPressSpace", WrapFunction("OnPressSpace"), "", 0);
  48. Game.AddCommand("+KeyPressUp", WrapFunction("OnPressUp"), "", 0);
  49. Game.AddCommand("+KeyPressLeft", WrapFunction("OnPressLeft"), "", 0);
  50. Game.AddCommand("+KeyPressDown", WrapFunction("OnPressDown"), "", 0);
  51. Game.AddCommand("+KeyPressRight", WrapFunction("OnPressRight"), "", 0);
  52.  
  53. Game.AddCommand("-KeyPressSpace", WrapFunction("OnReleaseSpace"), "", 0);
  54. Game.AddCommand("-KeyPressUp", WrapFunction("OnReleaseUp"), "", 0);
  55. Game.AddCommand("-KeyPressLeft", WrapFunction("OnReleaseLeft"), "", 0);
  56. Game.AddCommand("-KeyPressDown", WrapFunction("OnReleaseDown"), "", 0);
  57. Game.AddCommand("-KeyPressRight", WrapFunction("OnReleaseRight"), "", 0);
  58.  
  59. (function()
  60. {
  61. $.Msg("controls/keybind_register.js loaded.");
  62. })();
  63.  
  64. // keys
  65. "use strict";
  66.  
  67. var ISPRESSED_UP, ISPRESSED_DOWN, ISPRESSED_RIGHT, ISPRESSED_LEFT = false;
  68. var localHeroIndex;
  69. var stopped;
  70. var keyHasChanged = true;
  71.  
  72. // Pressing keys
  73. Game.OnPressUp = function() {
  74. keyHasChanged = true;
  75. ISPRESSED_UP = true;
  76. }
  77. Game.OnPressDown = function() {
  78. keyHasChanged = true;
  79. ISPRESSED_DOWN = true;
  80. }
  81. Game.OnPressRight = function() {
  82. keyHasChanged = true;
  83. ISPRESSED_RIGHT = true;
  84. }
  85. Game.OnPressLeft = function() {
  86. keyHasChanged = true;
  87. ISPRESSED_LEFT = true;
  88. }
  89.  
  90. // Releasing keys
  91. Game.OnReleaseUp = function() {
  92. keyHasChanged = true;
  93. ISPRESSED_UP = false;
  94. }
  95. Game.OnReleaseDown = function() {
  96. keyHasChanged = true;
  97. ISPRESSED_DOWN = false;
  98. }
  99. Game.OnReleaseRight = function() {
  100. keyHasChanged = true;
  101. ISPRESSED_RIGHT = false;
  102. }
  103. Game.OnReleaseLeft = function() {
  104. keyHasChanged = true;
  105. ISPRESSED_LEFT = false;
  106. }
  107.  
  108. // Space
  109. Game.OnPressSpace = function() {
  110. GameEvents.SendCustomGameEventToServer("Player_PressSpace", {});
  111. }
  112. Game.OnReleaseSpace = function() { }
  113.  
  114. function Move()
  115. {
  116. if(keyHasChanged == true)
  117. {
  118. GameEvents.SendCustomGameEventToServer("Player_ChangeKeys", {
  119. "right" : ISPRESSED_RIGHT,
  120. "left" : ISPRESSED_LEFT,
  121. "up" : ISPRESSED_UP,
  122. "down" : ISPRESSED_DOWN });
  123. keyHasChanged = false;
  124. }
  125.  
  126. $.Schedule(1/30, Move);
  127. }
  128.  
  129. (function()
  130. {
  131. $.Msg("controls/keys.js loaded.");
  132. $.Schedule(1/30, Move);
  133. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement