Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TagPro Little Helper (with Flag Aimer)
// ==UserScript==
// @name TagPro Little Helper
// @version 0.2.0
// @description Show guides for aiming with bombs, highlight tiles to help with passing through tight spaces, and show position and velocity
// @include *://tagpro.koalabeast.com/game
// @include http://tagpro-maptest.koalabeast.com:*
// @include http://*.newcompte.fr:*
// @include http://tangent.jukejuice.com:*
// @author Some Ball -1
// ==/UserScript==
tagpro.ready(function() {
//Show the position and velocity numbers
var showNumbers = true; //true or false
var showBombAimer = true;
var showFlagAimer = true;
function ab(v1,v2) { return Math.atan((v1.x-v2.x)/(v1.y-v2.y)) };
var xs = [],
ys = [],
fsx = [],
fsy = [],
tiles = [],
show = false;
tagpro.renderer.rectSprites = [];
tagpro.renderer.flagSprites = [];
tagpro.renderer.tileSprites = [];
var old = tagpro.renderer.updatePlayerSpritePosition,
children;
if (tagpro.renderer.layers.background) {
children = tagpro.renderer.layers.background.children;
} else {
let lay = tagpro.renderer.createLayers;
tagpro.renderer.createLayers = function() {
lay();
children = tagpro.renderer.layers.background.children;
}
}
$(window).on('blur',function() { //prevent sticky alt key
let e = $.Event('keyup');
e.altKey = true;
e.keyCode = e.which = 18;
$(document).trigger(e);
});
var info = new PIXI.Text("X:\tY:\nVx:\tVy:",{font: 'bold 8pt Arial', fill: 'white', stroke: 'black', strokeThickness: 3});
info.x = 40;
var permshow = false;
$(document).keydown(function(key) { //unhide
if (key.altKey) show = info.visible = true;
if (permshow && key.altKey && key.shiftKey) permshow = false;
else permshow = key.altKey && key.shiftKey;
});
$(document).keyup(function(key) { //hide
if (!permshow && key.keyCode==18) { //for some reason key.altKey doesn't work
show = info.visible = false;
for (let i = 0;i < tagpro.renderer.rectSprites.length;i++) {
tagpro.renderer.rectSprites[i].alpha = 0; //hide bomb guides
}
for (let i = 0;i < tagpro.renderer.flagSprites.length;i++) {
tagpro.renderer.flagSprites[i].alpha = 0; //hide flag guides
}
for (let i = 0;i < 4;i++) {
tagpro.renderer.tileSprites[i].alpha = 0;
}
}
});
Box2D.Dynamics.b2Body.prototype.GetPosition = function() {
if (!this.getProps && this.player) {
this.getProps = true;
let player = tagpro.players[this.player.id];
Object.defineProperty(player, "position", {
get: function() {
return {x: this.m_xf.position.x * 100, y: this.m_xf.position.y * 100};
}.bind(this)
});
Object.defineProperty(player, "linearVelocity", {
get: function() {
return {x: this.GetLinearVelocity().x, y: this.GetLinearVelocity().y};
}.bind(this)
});
}
return this.m_xf.position;
};
tagpro.renderer.updatePlayerSpritePosition = function (player) {
if (show && player.id===tagpro.playerId) {
if (showNumbers) {
if (!info.parent) player.sprite.addChild(info);
let pos = {}, vel = {}, tilePos = {};
if (player.position) pos = {x: Math.round(player.position.x*100)/100, y: Math.round(player.position.y*100)/100};
if (player.position) tilePos = {x: Math.round((pos.x-20)/40), y: Math.round((pos.y-20)/40)};
if (player.linearVelocity) vel = {x: Math.round(player.linearVelocity.x*100)/100, y: Math.round(player.linearVelocity.y*100)/100};
info.text = "X: "+pos.x+"\tY: "+pos.y+"\nX: "+tilePos.x+"\tY: "+tilePos.y+(vel?"\nVx: "+vel.x+"\tVy: "+vel.y:"");
}
let tiles = [[]];
let steps = [{x: Math.floor, y: Math.floor},{x: Math.floor, y: Math.ceil},{x: Math.ceil, y: Math.floor},{x: Math.ceil, y: Math.ceil}];
let count = 0;
let mepos = {x: Math.round(player.x)+20, y: Math.round(player.y)+20};
for (let i = 0;i < 4;i++) {
let tilePos = {x: steps[i].x(Math.round(tagpro.players[tagpro.playerId].x)/40), y: steps[i].y(Math.round(tagpro.players[tagpro.playerId].y)/40)};
let see = 0;
if (!tiles[tilePos.x]) tiles[tilePos.x] = [];
if (!tiles[tilePos.x][tilePos.y]) {
see = 1;
tiles[tilePos.x][tilePos.y] = true;
tagpro.renderer.tileSprites[i].x = tilePos.x*40;
tagpro.renderer.tileSprites[i].y = tilePos.y*40;
}
tagpro.renderer.tileSprites[i].alpha = see;
}
if (showBombAimer) {
if (tagpro.renderer.rectSprites[0]) { //bomb aimer stuff
if (!tagpro.renderer.rectSprites[0].parent) addRects();
let checks = [];
for(let i = 0;i < xs.length;i++) {
checks[i] = false;
if (Math.sqrt(Math.pow(mepos.x-xs[i],2)+Math.pow(mepos.y-ys[i],2))<120) {
tagpro.renderer.rectSprites[i].alpha = .5;
tagpro.renderer.rectSprites[i].rotation = ((mepos.y<ys[i])?Math.PI:0)-ab(mepos,{x: xs[i],y: ys[i]});
checks[i] = true;
}
}
for (let i = 0;i < tagpro.renderer.rectSprites.length;i++) {
tagpro.renderer.rectSprites[i].alpha = .5*checks[i];
}
}
}
if (showFlagAimer) {
if (tagpro.renderer.flagSprites[0]) { //flag aimer stuff
if (!tagpro.renderer.flagSprites[0].parent) addFlagRects();
let checks = [];
for (let i = 0;i < fsx.length;i++) {
checks[i] = false;
if (Math.sqrt(Math.pow(mepos.x-fsx[i],2)+Math.pow(mepos.y-fsy[i],2))<1000) {
tagpro.renderer.flagSprites[i].alpha = .5;
tagpro.renderer.flagSprites[i].rotation = ((mepos.y<fsy[i])?Math.PI:0)-ab(mepos,{x: fsx[i],y: fsy[i]});
checks[i] = true;
}
}
for (let i = 0;i < tagpro.renderer.flagSprites.length;i++) {
tagpro.renderer.flagSprites[i].alpha = .5*checks[i];
}
}
}
}
old(player);
};
function addRects() {
for (let i = 0;i < tagpro.renderer.rectSprites.length;i++) {
tagpro.renderer.layers.background.addChild(tagpro.renderer.rectSprites[i]);
}
}
function addFlagRects() {
for (let i = 0;i < tagpro.renderer.flagSprites.length;i++) {
tagpro.renderer.layers.background.addChild(tagpro.renderer.flagSprites[i]);
}
}
function createTiles() {
for (let i = 0;i < 4;i++) {
let tile = new PIXI.Graphics();
tile.lineStyle(1, 0x00FF00).drawRect(0,0,40,40).alpha = 0;
tagpro.renderer.tileSprites.push(tile);
tagpro.renderer.layers.background.addChild(tile);
}
}
function findBombs() {
if(!tagpro.map || !tagpro.players[tagpro.playerId]) {
setTimeout(findBombs,50);
return;
}
var me = tagpro.players[tagpro.playerId];
for (let i = 0;i < tagpro.map.length;i++) {
for (let j = 0;j < tagpro.map[i].length;j++) {
if (tagpro.map[i][j]==10 || tagpro.map[i][j]==10.1) {
xs.push(i*40+20);
ys.push(j*40+20);
var rect = new PIXI.Graphics();
rect.beginFill(me.team==1?0xff0000:0x0000ff).drawRect(0,0,10,40*12).alpha = 0;
rect.pivot.x = 5;
rect.x = i*40+20;
rect.y = j*40+20;
tagpro.renderer.rectSprites.push(rect);
} else if ((tagpro.map[i][j] == 3 || tagpro.map[i][j] == 3.1) || (tagpro.map[i][j] == 4 || tagpro.map[i][j] == 4.1) || (tagpro.map[i][j] == 16 || tagpro.map[i][j] == 16.1)) {
fsx.push(i*40+20);
fsy.push(j*40+20);
let rect = new PIXI.Graphics();
rect.beginFill(0x008800).drawRect(0,0,4,1280).alpha = 0;
rect.pivot.x = 5;
rect.x = i*40+20;
rect.y = j*40+20;
tagpro.renderer.flagSprites.push(rect);
}
}
}
setTimeout(function() {
addRects();
addFlagRects()
createTiles();
}, 500);
}
findBombs();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.