Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name EggProMouse
- // @version 1.5
- // @description Tweaks for Egg Ball
- // @author Catalyst
- // @match *://*.koalabeast.com/game
- // @include http://*.koalabeast.com:*
- // @include http://*.jukejuice.com:*
- // @include http://*.newcompte.fr:*
- // @updateURL https://gist.github.com/catalyst518/f28accf3d14385470a330ab80c768ee1/raw/EggPro.user.js
- // @downloadURL https://gist.github.com/catalyst518/f28accf3d14385470a330ab80c768ee1/raw/EggPro.user.js
- // ==/UserScript==
- //--------------CHANGELOG--------------
- /*
- Note: All new features are opt-in and will continue to be so in any future updates. This means your settings will be reset to their defaults upon updating.
- ~~~Version 1.4 (July 12, 2019)~~~
- Added support for new SWJ servers.
- Added option to highlight your own ball.
- Added option to lock the camera to your ball, just like in regular TagPro. The script used to do this automatically until something changed in the game code.
- Now you can play either way, but the default is the old script behavior of locked to ball.
- Fixed the aiming line to work with the current version of the game/servers.
- Fixed the autoshoot aim to work with the current version of the game/servers.
- Adjusted the autoshoot rate limiter so you won't get kicked from games for painting the wall. This might need further adjustments.
- Added some checks to disable the effects of this script in regular TagPro games.
- Updated the default imgur urls to use https instead of http so TagPro maintains a secure connection.
- Added default settings:
- highlight=false
- highlight_url="https://i.imgur.com/h23oRYI.png"
- lock_ball=true
- ~~~Version 1.3 (June 19, 2017)~~~
- Added ability to autoshoot when picking up the egg. Activated by holding Left Shift by default (reassign the key in settings).
- Added custom crosshair support.
- Added aiming line.
- Added default settings:
- auto_shoot=false
- custom_crosshair=false
- aim_line=false
- crosshair_url="http://i.imgur.com/Pjxxh20.png"
- auto_key=16
- aim_line_color=0xFF00FF
- aim_line_alpha=1
- */
- //-----------END OF CHANGELOG-----------
- //--------------SETTINGS--------------
- //Put a pink ring around your ball so it doesn't get lost in the chaos.
- var highlight=false;
- //Lock the camera to your ball like in regular tagpro. In eggball, the camera is by default vertically locked to the field giving an out-of-ball sensation.
- var lock_ball=true;
- //Set the value to false to expand viewport while playing. Set the value to true to expand only when spectating.
- var spec_only=false;
- //Set true/false to toggle auto-zoom level when spectating.
- var auto_zoom=true;
- //Set the value to true to use a pixel perfect egg. Set to false to use the vanilla egg.
- var pp_egg=true;
- //Set the value to true to use the custom, improved map. Set to false to use the vanilla map.
- var imp_map=true;
- //Set the value to true to enable autoshooting when picking up the egg. Set to false to disable.
- var auto_shoot=true;
- //Set the value to true to use a custom crosshair. Set to false to use the default crosshair.
- var custom_crosshair=true;
- //Set the value to true to enable an aiming line to your cursor position. Set to false to disable.
- var aim_line=true;
- //Set url of custom egg image (23x23 for pixel perfect). Only applies if pp_egg=true.
- var egg_url="https://i.imgur.com/B1F1BI5.png";
- //Set url of custom egg team indicator image (29x29). Only applies if pp_egg=true.
- var egg_team_url="https://i.imgur.com/P0l0yVA.png";
- //Set url of custom field image. Only applies if imp_map=true.
- var field_url="https://i.imgur.com/vF0f6g0.png";
- //Set url of custom crosshair image (designed for 32x32). Only applies if custom_crosshair=true.
- var crosshair_url="https://i.imgur.com/Pjxxh20.png";
- //Set url of the highlight ring around your ball. Only applies if highlight=true.
- var highlight_url="https://i.imgur.com/h23oRYI.png"
- //Set autoshoot key. Default is Left Shift (16). Only applies if auto_shoot=true.
- //Use this app to get the correct keycode: https://codepen.io/chriscoyier/full/mPgoYJ/ or see https://msdn.microsoft.com/en-us/library/aa243025(v=vs.60).aspx
- var auto_key=16;
- //Set the color of the aiming line in hex with 0x prefix. Default is 0xFF00FF (matches the custom crosshair). Only applies if aim_line=true.
- var aim_line_color=0xFF00FF;
- //Set the transparency of the aiming line. Ranges from 0 (transparent) to 1 (opaque). Only applies if aim_line=true.
- var aim_line_alpha=1;
- //-----------END OF SETTINGS-----------
- var oldh=0;
- var oldw=0;
- var eggball=false;
- tagpro.ready(function() {
- tagpro.socket.on('map', function(data) {
- if (data.info.name=="Egg Ball"){
- eggball=true;
- if(custom_crosshair) {
- $("<style type='text/css'>canvas{cursor: url("+crosshair_url+") 16 16, crosshair !important;}</style>").appendTo("head");
- }
- }
- });
- tagpro.socket.on("eggBall", function(data) {
- gameState = data.state;
- eggHolder = tagpro.players[data.holder];
- if(auto_shoot && auto && eggHolder===tagpro.players[tagpro.playerId]){
- autoShoot();
- }
- updateTeamWithEgg();
- eggball=true;
- });
- var stage = tagpro.renderer.stage;
- var container = tagpro.renderer.gameContainer;
- var MousePos = { x: 0, y: 0 };
- var auto=false;
- stage.interactive = true;
- stage.mousemove = function(e) {
- MousePos.x = e.data.global.x;
- MousePos.y = e.data.global.y;
- };
- onmousemove=function(e){
- if(!tagpro.spectator && aim_line && eggball){
- var player = tagpro.players[tagpro.playerId];
- try {
- player.sprites.aim.clear();
- player.sprites.aim.lineStyle(2, aim_line_color, aim_line_alpha);
- player.sprites.aim.moveTo(20,20);
- if (spec_only){
- player.sprites.aim.lineTo((e.clientX-window.innerWidth/2)*1280/$('#viewport').width()+20, (e.clientY-window.innerHeight/2)*800/$('#viewport').height()+20);
- }
- else {
- player.sprites.aim.lineTo((e.clientX-window.innerWidth/2)+20, (e.clientY-window.innerHeight/2)+20);
- }
- }
- catch (err){
- player.sprites.aim = new PIXI.Graphics();
- player.sprites.ball.addChild(player.sprites.aim);
- }
- }
- };
- if (lock_ball){
- tagpro.renderer.updateCameraPosition = function (player) {
- if (player.sprite.x !== -1000 && player.sprite.y !== -1000) {
- tagpro.renderer.centerContainerToPoint(player.sprite.x + 19, player.sprite.y + 19);
- }
- };
- }
- document.onkeydown = function(e){
- if(e.keyCode===auto_key){
- auto=true;
- }
- };
- document.onkeyup = function(e){
- if(e.keyCode===auto_key){
- auto=false;
- }
- };
- document.onmousedown = function(e){
- auto=true;
- };
- document.onmouseup = function(e){
- auto=false;
- };
- var gameState = null;
- var eggHolder = null;
- var realUpdatePlayerPowerUps = tagpro.renderer.updatePlayerPowerUps;
- if (imp_map){
- tagpro.renderer.afterDrawBackground = function() {
- if(eggball){
- const fieldSprite = new PIXI.Sprite.fromImage(field_url);
- fieldSprite.x = 40;
- fieldSprite.y = 40;
- tagpro.renderer.layers.foreground.addChildAt(fieldSprite, 0);}
- };
- }
- try{
- tagpro.renderer.updatePlayerPowerUps = function (player, context, drawPos) {
- realUpdatePlayerPowerUps(player, context, drawPos);
- if (pp_egg && eggball){
- if (!player.sprites.egg2) {
- player.sprites.egg2 = new PIXI.Sprite.fromImage(egg_url);
- player.sprites.egg2.width = 23;
- player.sprites.egg2.height = 23;
- player.sprites.egg2.x = 8;
- player.sprites.egg2.y = 8;
- player.sprite.addChildAt(player.sprites.egg2,1);
- }
- player.sprites.egg2.alpha = eggHolder === player ? 1 : 0;
- if (player.sprites.egg){
- player.sprites.egg.alpha = 0;}
- }
- };}
- catch(err){
- //Not egg mode
- }
- var eggTeam = new PIXI.Sprite.fromImage("events/easter-2016/images/egg.png");
- if (pp_egg){
- eggTeam = new PIXI.Sprite.fromImage(egg_team_url);}
- eggTeam.width = 29;
- eggTeam.height = 29;
- eggTeam.anchor.x = 0.5;
- eggTeam.anchor.y = 0.5;
- eggTeam.alpha = 0.75;
- eggTeam.visible = false;
- try{
- tagpro.renderer.layers.ui.addChildAt(eggTeam,1);
- tagpro.renderer.layers.ui.removeChildAt(0);}
- catch(err){
- //Not egg mode
- }
- var rate=true;
- function autoShoot(){
- if (!rate) return;
- rate=false;
- var clickPos = {
- x: (MousePos.x * (1 / container.scale.x)) - (container.position.x * (1 / container.scale.x)),
- y: (MousePos.y * (1 / container.scale.y)) - (container.position.y * (1 / container.scale.y))
- };
- tagpro.socket.emit("click", clickPos);
- setTimeout(function(){rate = true;}, 15);//needed to avoid kick for too many server requests
- }
- function updateTeamWithEgg() {
- if (!tagpro.ui.sprites["yellowFlagTakenByRed"]) {
- return setTimeout(updateTeamWithEgg.bind(this), 50);
- }
- if (!eggHolder) {
- eggTeam.visible = false;
- }
- else {
- eggTeam.visible = true;
- if (eggHolder.team === 1) {
- const pos = tagpro.ui.sprites["yellowFlagTakenByRed"];
- eggTeam.x = pos.x;
- eggTeam.y = pos.y;
- }
- else {
- const pos = tagpro.ui.sprites["yellowFlagTakenByBlue"];
- eggTeam.x = pos.x;
- eggTeam.y = pos.y;
- }
- }
- }
- var oldUpdateMarsball = tagpro.renderer.updateMarsBall.bind(tagpro.updateMarsBall);
- var oldDrawMarsball = tagpro.renderer.drawMarsball.bind(tagpro.renderer);
- tagpro.renderer.updateMarsBall = function(object, position) {
- if (object.type == "egg") {
- position.x = position.x + 20;
- position.y = position.y + 20;
- }
- oldUpdateMarsball(object, position);
- };
- tagpro.renderer.drawMarsball = function (object, position) {
- if (object.type == "marsball") {
- return oldDrawMarsball(object, position);
- }
- if (object.type !== "egg") {
- return;
- }
- if (tagpro.spectator) {
- object.draw = true;
- }
- if (pp_egg){
- object.sprite = new PIXI.Sprite.fromImage(egg_url);}
- else {
- object.sprite = new PIXI.Sprite.fromImage("events/easter-2016/images/egg.png");}
- object.sprite.position.x = position.x;
- object.sprite.position.y = position.y;
- object.sprite.width = 23;
- object.sprite.height = 23;
- object.sprite.pivot.set(23*0.5, 23*0.5);
- tagpro.renderer.layers.foreground.addChild(object.sprite);
- object.sprite.keep = true;
- if (!object.draw) {
- object.sprite.visible = false;
- }
- };
- var defaultUpdatePlayerSpritePosition = tagpro.renderer.updatePlayerSpritePosition;
- tagpro.renderer.updatePlayerSpritePosition = function (player) {
- // Create highlight
- if (eggball && highlight && player==tagpro.players[tagpro.playerId] && !player.sprites.highlight) {
- player.sprites.highlight = new PIXI.Sprite.fromImage(highlight_url);
- player.sprites.highlight.x = -5;
- player.sprites.highlight.y = -5;
- player.sprites.ball.addChild(player.sprites.highlight);
- }
- defaultUpdatePlayerSpritePosition(player);
- };
- function waitForId() {
- if (!tagpro.playerId) {
- return setTimeout(waitForId, 100);
- }
- if((tagpro.spectator || !spec_only) && eggball)
- {
- //Resize viewport
- resize();
- if(tagpro.spectator){
- tagpro.viewport.followPlayer=false;
- }
- //Check for resizing and update FOV and zoom accordingly
- setInterval(updateFOV, 500);
- }
- }
- waitForId();
- });
- function resize(){
- tagpro.renderer.canvas_width = window.innerWidth;
- tagpro.renderer.canvas_height = window.innerHeight;
- tagpro.renderer.resizeView();
- tagpro.renderer.centerView();
- }
- function updateFOV() {
- var h = $('#viewport').height();
- var w = $('#viewport').width();
- //Resize viewport
- if (h!=window.innerHeight||w!=window.innerWidth){
- resize();
- h = $('#viewport').height();
- w = $('#viewport').width();
- }
- //Auto-zoom to fill viewport
- if(tagpro.spectator && auto_zoom && (oldh!=h ||oldw!=w))
- {
- var yzoom=tagpro.map[0].length*40/h;
- var xzoom=tagpro.map.length*40/w;
- tagpro.zoom=Math.max(xzoom,yzoom,1);
- }
- oldh=h;
- oldw=w;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement