Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Tagpro Zoom With Specbot GUI
- // @version 1.0
- // @description Automate spectating with buttons, zoom out during a game
- // @match http://koalabeast.com
- // @include http://tagpro-*.koalabeast.com:*
- // @include http://tangent.jukejuice.com:*
- // @include http://maptest.newcompte.fr:*
- // @copyright 2014+, Lej, Despair, happy
- // ==/UserScript==
- //settings
- showMapName = true;
- powerupMode = 1;// 0-Dont show all of game 1-Dont show first 15 sec of game 2-show all of game
- numZoom1 = 2.5;//only certain zoom levels display the tiles uniformly. [1, 4/3, 5/3, 2, 5/2, 10/3, 4, 5]
- numZoom2 = 4.0;
- numZoom3 = 5.0;
- //variables
- zoomLevel = numZoom1;
- buttonLock = false;
- canShowPower = false;
- gotState = false;
- specBotState = 0;// 0-Off 1-On 2-Center view
- playerBotState = 0;// 0-Off 1-Follow player 2-Center view
- activeBot = 0;// 0-Player 1-Spec
- buttonCameraDelay = 250 // Time in milliseconds to wait before changing camera after button press
- defaultCameraDelay = 1000 // Time in milliseconds to wait before changing camera
- //specbot variables
- CAMERA_DELAY = defaultCameraDelay;
- key=0;
- collumnCount=0;
- rowCount=0;
- tileCount=0;
- centerX=0;
- centerY=0;
- followingRed = false;
- followingBlue = false;
- isCentered = false;
- redFC = 0;
- blueFC = 0;
- //images
- specBotOffImage = "http://i.imgur.com/OFBPXfz.png";
- specBotFCImage = "http://i.imgur.com/ma5z0Tz.png";
- specBotCenter = "http://i.imgur.com/cOKKvWc.png";
- playerBotOff = "http://i.imgur.com/GoS2ouY.png";
- playerBotSelf = "http://i.imgur.com/ysdakIA.png";
- playerBotCenter = "http://i.imgur.com/kLgjbYc.png";
- zoomBar1 = "http://i.imgur.com/PtDpGJ5.png";
- zoomBar2 = "http://i.imgur.com/Qc9nW4V.png";
- zoomBar3 = "http://i.imgur.com/tFakLrz.png";
- zoomBar4 = "http://i.imgur.com/ZKYRsaA.png";
- centerBar = "http://i.imgur.com/F4ByiCP.png";
- modeBar = "http://i.imgur.com/SJM5Wal.png";
- zoomBar = zoomBar2
- mainImage = playerBotOff;
- // Build the Main icon
- var main_icon = document.createElement("img");
- main_icon.src = mainImage;
- main_icon.onclick=mainButton;
- main_icon.onmouseover= function(){main_icon.style.cursor="pointer";}
- main_icon.onmouseout = function(){;}
- main_icon.style.opacity="1.0";
- document.body.appendChild(main_icon);
- main_icon.style.position="absolute";
- main_icon.style.right = "10px";
- main_icon.style.bottom = "110px";
- // Build the Zoom icon
- var zoom_icon = document.createElement("img");
- zoom_icon.src = zoomBar;
- zoom_icon.onclick=zoomButton;
- zoom_icon.onmouseover= function(){zoom_icon.style.cursor="pointer";}
- zoom_icon.onmouseout = function(){;}
- zoom_icon.style.opacity="1.0";
- document.body.appendChild(zoom_icon);
- zoom_icon.style.position="absolute";
- zoom_icon.style.right = "50px";
- zoom_icon.style.bottom = "90px";
- // Build the Center icon
- var center_icon = document.createElement("img");
- center_icon.src = centerBar;
- center_icon.onclick=centerButton;
- center_icon.onmouseover= function(){center_icon.style.cursor="pointer";}
- center_icon.onmouseout = function(){;}
- center_icon.style.opacity="1.0";
- document.body.appendChild(center_icon);
- center_icon.style.position="absolute";
- center_icon.style.right = "10px";
- center_icon.style.bottom = "150px";
- // Build the Mode icon
- var mode_icon = document.createElement("img");
- mode_icon.src = modeBar;
- mode_icon.onclick=modeButton;
- mode_icon.onmouseover= function(){mode_icon.style.cursor="pointer";}
- mode_icon.onmouseout = function(){;}
- mode_icon.style.opacity="1.0";
- document.body.appendChild(mode_icon);
- mode_icon.style.position="absolute";
- mode_icon.style.right = "10px";
- mode_icon.style.bottom = "90px";
- function mainButton() {
- if (activeBot == 1 && buttonLock == false) {
- CAMERA_DELAY = buttonCameraDelay
- resetDelay()
- if (specBotState == 0) {
- specBotState = 1
- calculateCenter()
- mainImage = specBotFCImage
- main_icon.src = mainImage;
- }
- else if (specBotState == 1) {
- specBotState = 2
- mainImage = specBotCenter
- main_icon.src = mainImage;
- }
- else {
- specBotState = 0
- mainImage = specBotOffImage
- main_icon.src = mainImage;
- }
- }
- else if (activeBot == 0 && buttonLock == false) {
- if (playerBotState == 0) {
- playerBotState = 1
- mainImage = playerBotSelf
- main_icon.src = mainImage;
- tagpro.zoom = zoomLevel;
- }
- else if (playerBotState == 1) {
- playerBotState = 2
- mainImage = playerBotCenter
- main_icon.src = mainImage;
- calculateCenter()
- goToCenter()
- }
- else {
- resetPlayerBot()
- }
- }
- powerupReplacer()
- }
- function zoomButton() {
- toggleZoom()
- if (activeBot == 1 && buttonLock == false) {
- if (isCentered == true) {
- tagpro.zoom = zoomLevel;
- }
- else if (specBotState == 0) {
- tagpro.zoom = zoomLevel;
- }
- }
- else if (activeBot == 0 && buttonLock == false) {
- if (playerBotState != 0) {
- tagpro.zoom = zoomLevel;
- }
- }
- powerupReplacer()
- }
- function centerButton() {
- calculateCenter()
- if (activeBot == 1 && buttonLock == false) {
- if (specBotState == 0) {
- specBotState = 2
- mainImage = specBotCenter
- main_icon.src = mainImage;
- resetDelay()
- calculateCenter()
- setTimeout(function(){
- goToCenter()
- }, buttonCameraDelay)
- }
- else {
- CAMERA_DELAY = buttonCameraDelay
- resetDelay()
- specBotState = 0
- mainImage = specBotOffImage
- main_icon.src = mainImage;
- setTimeout(function(){
- goToCenter()
- }, buttonCameraDelay)
- }
- }
- else if (activeBot == 0 && buttonLock == false) {
- if (playerBotState == 0) {
- playerBotState = 2
- mainImage = playerBotCenter
- main_icon.src = mainImage;
- tagpro.zoom = zoomLevel;
- calculateCenter()
- goToCenter()
- }
- else {
- resetPlayerBot()
- }
- }
- powerupReplacer()
- }
- function modeButton() {
- if (buttonLock == false) {
- specBotState = 0
- playerBotState = 0
- if (activeBot == 0) {
- activeBot = 1
- mainImage = specBotOffImage
- main_icon.src = mainImage;
- }
- else {
- activeBot = 0
- CAMERA_DELAY = buttonCameraDelay
- resetDelay()
- setTimeout(function(){
- resetPlayerBot()
- }, buttonCameraDelay)
- }
- }
- powerupReplacer()
- }
- function resetPlayerBot() {
- playerBotState = 0
- mainImage = playerBotOff
- main_icon.src = mainImage;
- tagpro.viewPort.followPlayer = true
- tagpro.zoom = 1.0
- }
- function toggleZoom() {
- if (zoomLevel == 1.0) {
- zoomLevel = numZoom1
- zoomBar = zoomBar2
- zoom_icon.src = zoomBar;
- }
- else if (zoomLevel == numZoom1) {
- zoomLevel = numZoom2
- zoomBar = zoomBar3
- zoom_icon.src = zoomBar;
- }
- else if (zoomLevel == numZoom2) {
- zoomLevel = numZoom3
- zoomBar = zoomBar4
- zoom_icon.src = zoomBar;
- }
- else {
- zoomLevel = 1.0
- zoomBar = zoomBar1
- zoom_icon.src = zoomBar;
- }
- }
- function resetDelay() {
- resetTime = buttonCameraDelay + 100
- setTimeout(function() {
- CAMERA_DELAY = defaultCameraDelay;
- }, resetTime);
- }
- setInterval(function(){
- specBot();
- }, 100);
- function calculateCenter() {
- collumnCount=0;
- rowCount=0;
- tileCount=0;
- centerX=0;
- centerY=0;
- for(collumn in tagpro.map){
- for(tile in tagpro.map[collumn]){
- tileCount++;
- }
- collumnCount++;
- }
- rowCount = tileCount/collumnCount;
- fakecenterX = collumnCount/2*40;
- fakecenterY = rowCount/2*40;
- centerX = fakecenterX - 20
- centerY = fakecenterY - 20
- }
- function specBot() {
- if (activeBot == 1) {
- if (specBotState == 1) {
- if (tagpro.ui) {
- if ( (!tagpro.ui.blueFlagTaken && !tagpro.ui.redFlagTaken) || (tagpro.ui.blueFlagTaken && tagpro.ui.redFlagTaken) ) {
- if (tagpro.ui.yellowFlagTakenByRed) {
- goToRed()
- }
- else if (tagpro.ui.yellowFlagTakenByBlue) {
- goToBlue()
- }
- else {
- centerView()
- }
- }
- else if (tagpro.ui.redFlagTaken && !tagpro.ui.blueFlagTaken) {
- followBlue()
- }
- else if (tagpro.ui.blueFlagTaken && !tagpro.ui.redFlagTaken) {
- followRed()
- }
- }
- }
- else if (specBotState == 2) {
- setTimeout(function() {
- if (specBotState == 2) {
- goToCenter()
- }
- }, CAMERA_DELAY);
- }
- }
- }
- function pressKey(myKey) {
- var press = $.Event("keydown");
- press.which = myKey;
- $("#viewPort").trigger(press);
- press = $.Event("keyup");
- $("#viewPort").trigger(press);
- }
- function followBlue() {
- if (!followingBlue || tagpro.players[blueFC].flag === null) setTimeout(function() {
- if ( (tagpro.ui.redFlagTaken && !tagpro.ui.blueFlagTaken) && (specBotState == 1) ) {
- goToBlue()
- }
- }, CAMERA_DELAY);
- }
- function followRed() {
- if (!followingRed || tagpro.players[redFC].flag === null) setTimeout(function() {
- if ( (!tagpro.ui.redFlagTaken && tagpro.ui.blueFlagTaken) && (specBotState == 1) ) {
- goToRed()
- }
- }, CAMERA_DELAY);
- }
- function centerView() {
- if (!isCentered) setTimeout(function() {
- if ( (tagpro.ui.redFlagTaken && tagpro.ui.blueFlagTaken) || (!tagpro.ui.redFlagTaken && !tagpro.ui.blueFlagTaken) ) {
- goToCenter()
- }
- }, CAMERA_DELAY);
- }
- function goToCenter() {
- tagpro.viewPort.followPlayer = false;
- tagpro.viewPort.source = {};
- tagpro.viewPort.source.x = centerX;
- tagpro.viewPort.source.y = centerY;
- tagpro.zoom = zoomLevel;
- isCentered = true;
- followingRed = false;
- followingBlue = false;
- }
- function goToBlue() {
- tagpro.zoom = 1;
- tagpro.viewPort.followPlayer = true;
- pressKey(83);
- blueFC = tagpro.playerId;
- followingBlue = true;
- followingRed = false;
- isCentered = false;
- }
- function goToRed() {
- tagpro.zoom = 1;
- tagpro.viewPort.followPlayer = true;
- pressKey(65);
- redFC = tagpro.playerId;
- followingRed = true;
- followingBlue = false;
- isCentered = false;
- }
- //store power up tiles
- jukeJuice = tagpro.tiles[6.1]
- rollingBomb = tagpro.tiles[6.2]
- tagPro = tagpro.tiles[6.3]
- generic = tagpro.tiles[6.4]
- //Show or Hide powerups
- function hidePower() {
- tagpro.tiles[6.1] = generic
- tagpro.tiles[6.2] = generic
- tagpro.tiles[6.3] = generic
- tagpro.api.redrawBackground()
- }
- function showPower() {
- tagpro.tiles[6.1] = jukeJuice
- tagpro.tiles[6.2] = rollingBomb
- tagpro.tiles[6.3] = tagPro
- tagpro.api.redrawBackground()
- }
- function powerupReplacer() {
- if (!tagpro.spectator) {
- if (tagpro.zoom != 1) {
- if ( (powerupMode == 2) || (powerupMode == 1 && canShowPower) ) {
- showPower()
- }
- else {
- hidePower()
- }
- }
- else {
- showPower()
- }
- }
- }
- gameStartTimer = setInterval(function(){
- showPowerupAfterDelay();
- }, 250);
- function showPowerupAfterDelay() {
- if (powerupMode != 1) {
- clearInterval(gameStartTimer);
- }
- else if (tagpro.state == 1 && gotState == false) {
- gotState = true
- clearInterval(gameStartTimer);
- setTimeout(function(){
- canShowPower = true
- showPower()
- }, 15000)
- }
- }
- //get map name
- setTimeout(function(){
- mapInfo = $("#mapInfo").text()
- end = mapInfo.indexOf(" by ")
- mapName = mapInfo.substr(5,end-5)
- console.log(mapName)
- },200)
- //hide 'game starting soon...' alert so that you can see the map
- setTimeout(function(){
- original = tagpro.ui.largeAlert
- tagpro.ui.largeAlert = function (e,t,n,r,i){
- console.log(i)
- if (r == "Match Begins Soon...") {
- if (showMapName) {
- r=mapName
- } else {
- r=""
- }
- }
- return original(e,t,n,r,i)
- }
- },400)
Advertisement
Add Comment
Please, Sign In to add comment