Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // addon_info.txt
- "AddonInfo"
- {
- "Default_Keys"
- {
- "01"
- {
- "Key" "W"
- "Command" "+KeyPressUp"
- "Name" "Move Up"
- }
- "02"
- {
- "Key" "A"
- "Command" "+KeyPressLeft"
- "Name" "Move Left"
- }
- "03"
- {
- "Key" "S"
- "Command" "+KeyPressDown"
- "Name" "Move Down"
- }
- "04"
- {
- "Key" "R"
- "Command" "+KeyPressRight"
- "Name" "Move Right"
- }
- "05"
- {
- "Key" "SPACE"
- "Command" "+KeyPressSpace"
- "Name" "Jump"
- }
- }
- }
- // key register
- "use strict";
- function WrapFunction(name)
- {
- return function() { Game[name](); };
- }
- Game.AddCommand("+KeyPressSpace", WrapFunction("OnPressSpace"), "", 0);
- 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("-KeyPressSpace", WrapFunction("OnReleaseSpace"), "", 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
- "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;
- }
- // Space
- Game.OnPressSpace = function() {
- GameEvents.SendCustomGameEventToServer("Player_PressSpace", {});
- }
- Game.OnReleaseSpace = function() { }
- 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