Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MarksCode
Last active November 26, 2017 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarksCode/6d061146f821e1f4d4c3cc485afaa5a5 to your computer and use it in GitHub Desktop.
Save MarksCode/6d061146f821e1f4d4c3cc485afaa5a5 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name TagPro State Bot
// @version 0.1
// @include http://tagpro-maptest.koalabeast.com:*
// @include http://tangent.jukejuice.com:*
// @include http://*.newcompte.fr:*
// @author Cap
// ==/UserScript==
tagpro.ready(function() {
waitForStart(run);
});
function waitForStart(fn) {
if (tagpro.state !== 1 || !tagpro.playerId) {
setTimeout(function() {
waitForStart(fn);
}, 100);
} else {
fn();
}
}
function run() {
let id = Object.keys(tagpro.players).filter(p => p !== tagpro.playerId)[0]; // id of other player
move(id);
}
function move(id) {
let x = tagpro.players[tagpro.playerId].x;
let y = tagpro.players[tagpro.playerId].y;
var dest = {
x: tagpro.players[id].x,
y: tagpro.players[id].y
}
if (dest.x > x) {
tagpro.sendKeyPress("left", true);
tagpro.sendKeyPress("right", false);
} else if (dest.x < x) {
tagpro.sendKeyPress("right", true);
tagpro.sendKeyPress("left", false);
} else {
tagpro.sendKeyPress("right", true);
tagpro.sendKeyPress("left", true);
}
if (dest.y > y) {
tagpro.sendKeyPress("up", true);
tagpro.sendKeyPress("down", false);
} else if (dest.y < y) {
tagpro.sendKeyPress("down", true);
tagpro.sendKeyPress("up", false);
} else {
tagpro.sendKeyPress("up", true);
tagpro.sendKeyPress("down", true);
}
setTimeout(function() {
move(id);
}, 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment