Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // keybind_register.js
- "use strict";
- function WrapFunction(name)
- {
- return function() { Game[name](); };
- }
- Game.AddCommand("+KeyPressUp", WrapFunction("OnPressUp"), "", 0);
- Game.AddCommand("+KeyPressLeft", WrapFunction("OnPressLeft"), "", 0);
- Game.AddCommand("+KeyPressDown", WrapFunction("OnPressDown"), "", 0);
- Game.AddCommand("+KeyPressRight", WrapFunction("OnPressRight"), "", 0);
- Game.AddCommand("-KeyPressUp", WrapFunction("OnReleaseUp"), "", 0);
- Game.AddCommand("-KeyPressLeft", WrapFunction("OnReleaseLeft"), "", 0);
- Game.AddCommand("-KeyPressDown", WrapFunction("OnReleaseDown"), "", 0);
- Game.AddCommand("-KeyPressRight", WrapFunction("OnReleaseRight"), "", 0);
- (function()
- {
- $.Msg("controls/keybind_register.js loaded.");
- })();
- // keys.js
- "use strict";
- var ISPRESSED_UP, ISPRESSED_DOWN, ISPRESSED_RIGHT, ISPRESSED_LEFT = false;
- var localHeroIndex;
- var stopped;
- var keyHasChanged = true;
- // Pressing keys
- Game.OnPressUp = function() {
- keyHasChanged = true;
- ISPRESSED_UP = true;
- }
- Game.OnPressDown = function() {
- keyHasChanged = true;
- ISPRESSED_DOWN = true;
- }
- Game.OnPressRight = function() {
- keyHasChanged = true;
- ISPRESSED_RIGHT = true;
- }
- Game.OnPressLeft = function() {
- keyHasChanged = true;
- ISPRESSED_LEFT = true;
- }
- // Releasing keys
- Game.OnReleaseUp = function() {
- keyHasChanged = true;
- ISPRESSED_UP = false;
- }
- Game.OnReleaseDown = function() {
- keyHasChanged = true;
- ISPRESSED_DOWN = false;
- }
- Game.OnReleaseRight = function() {
- keyHasChanged = true;
- ISPRESSED_RIGHT = false;
- }
- Game.OnReleaseLeft = function() {
- keyHasChanged = true;
- ISPRESSED_LEFT = false;
- }
- function Move()
- {
- if(keyHasChanged == true)
- {
- GameEvents.SendCustomGameEventToServer("Player_ChangeKeys", {
- "right" : ISPRESSED_RIGHT,
- "left" : ISPRESSED_LEFT,
- "up" : ISPRESSED_UP,
- "down" : ISPRESSED_DOWN });
- keyHasChanged = false;
- }
- $.Schedule(1/30, Move);
- }
- (function()
- {
- $.Msg("controls/keys.js loaded.");
- $.Schedule(1/30, Move);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement