Guest User

Tagpro Zoom With Specbot GUI

a guest
Jul 26th, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.50 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Tagpro Zoom With Specbot GUI
  3. // @version 1.0
  4. // @description Automate spectating with buttons, zoom out during a game
  5. // @match http://koalabeast.com
  6. // @include http://tagpro-*.koalabeast.com:*
  7. // @include http://tangent.jukejuice.com:*
  8. // @include http://maptest.newcompte.fr:*
  9. // @copyright 2014+, Lej, Despair, happy
  10. // ==/UserScript==
  11.  
  12. //settings
  13. showMapName = true;
  14. powerupMode = 1;// 0-Dont show all of game 1-Dont show first 15 sec of game 2-show all of game
  15. numZoom1 = 2.5;//only certain zoom levels display the tiles uniformly. [1, 4/3, 5/3, 2, 5/2, 10/3, 4, 5]
  16. numZoom2 = 4.0;
  17. numZoom3 = 5.0;
  18.  
  19. //variables
  20. zoomLevel = numZoom1;
  21. buttonLock = false;
  22. canShowPower = false;
  23. gotState = false;
  24. specBotState = 0;// 0-Off 1-On 2-Center view
  25. playerBotState = 0;// 0-Off 1-Follow player 2-Center view
  26. activeBot = 0;// 0-Player 1-Spec
  27. buttonCameraDelay = 250 // Time in milliseconds to wait before changing camera after button press
  28. defaultCameraDelay = 1000 // Time in milliseconds to wait before changing camera
  29.  
  30. //specbot variables
  31. CAMERA_DELAY = defaultCameraDelay;
  32. key=0;
  33. collumnCount=0;
  34. rowCount=0;
  35. tileCount=0;
  36. centerX=0;
  37. centerY=0;
  38. followingRed = false;
  39. followingBlue = false;
  40. isCentered = false;
  41. redFC = 0;
  42. blueFC = 0;
  43.  
  44. //images
  45. specBotOffImage = "http://i.imgur.com/OFBPXfz.png";
  46. specBotFCImage = "http://i.imgur.com/ma5z0Tz.png";
  47. specBotCenter = "http://i.imgur.com/cOKKvWc.png";
  48. playerBotOff = "http://i.imgur.com/GoS2ouY.png";
  49. playerBotSelf = "http://i.imgur.com/ysdakIA.png";
  50. playerBotCenter = "http://i.imgur.com/kLgjbYc.png";
  51.  
  52. zoomBar1 = "http://i.imgur.com/PtDpGJ5.png";
  53. zoomBar2 = "http://i.imgur.com/Qc9nW4V.png";
  54. zoomBar3 = "http://i.imgur.com/tFakLrz.png";
  55. zoomBar4 = "http://i.imgur.com/ZKYRsaA.png";
  56.  
  57. centerBar = "http://i.imgur.com/F4ByiCP.png";
  58. modeBar = "http://i.imgur.com/SJM5Wal.png";
  59.  
  60. zoomBar = zoomBar2
  61. mainImage = playerBotOff;
  62.  
  63. // Build the Main icon
  64. var main_icon = document.createElement("img");
  65. main_icon.src = mainImage;
  66. main_icon.onclick=mainButton;
  67. main_icon.onmouseover= function(){main_icon.style.cursor="pointer";}
  68. main_icon.onmouseout = function(){;}
  69. main_icon.style.opacity="1.0";
  70. document.body.appendChild(main_icon);
  71. main_icon.style.position="absolute";
  72. main_icon.style.right = "10px";
  73. main_icon.style.bottom = "110px";
  74.  
  75. // Build the Zoom icon
  76. var zoom_icon = document.createElement("img");
  77. zoom_icon.src = zoomBar;
  78. zoom_icon.onclick=zoomButton;
  79. zoom_icon.onmouseover= function(){zoom_icon.style.cursor="pointer";}
  80. zoom_icon.onmouseout = function(){;}
  81. zoom_icon.style.opacity="1.0";
  82. document.body.appendChild(zoom_icon);
  83. zoom_icon.style.position="absolute";
  84. zoom_icon.style.right = "50px";
  85. zoom_icon.style.bottom = "90px";
  86.  
  87. // Build the Center icon
  88. var center_icon = document.createElement("img");
  89. center_icon.src = centerBar;
  90. center_icon.onclick=centerButton;
  91. center_icon.onmouseover= function(){center_icon.style.cursor="pointer";}
  92. center_icon.onmouseout = function(){;}
  93. center_icon.style.opacity="1.0";
  94. document.body.appendChild(center_icon);
  95. center_icon.style.position="absolute";
  96. center_icon.style.right = "10px";
  97. center_icon.style.bottom = "150px";
  98.  
  99. // Build the Mode icon
  100. var mode_icon = document.createElement("img");
  101. mode_icon.src = modeBar;
  102. mode_icon.onclick=modeButton;
  103. mode_icon.onmouseover= function(){mode_icon.style.cursor="pointer";}
  104. mode_icon.onmouseout = function(){;}
  105. mode_icon.style.opacity="1.0";
  106. document.body.appendChild(mode_icon);
  107. mode_icon.style.position="absolute";
  108. mode_icon.style.right = "10px";
  109. mode_icon.style.bottom = "90px";
  110.  
  111. function mainButton() {
  112. if (activeBot == 1 && buttonLock == false) {
  113. CAMERA_DELAY = buttonCameraDelay
  114. resetDelay()
  115. if (specBotState == 0) {
  116. specBotState = 1
  117. calculateCenter()
  118. mainImage = specBotFCImage
  119. main_icon.src = mainImage;
  120. }
  121. else if (specBotState == 1) {
  122. specBotState = 2
  123. mainImage = specBotCenter
  124. main_icon.src = mainImage;
  125. }
  126. else {
  127. specBotState = 0
  128. mainImage = specBotOffImage
  129. main_icon.src = mainImage;
  130. }
  131. }
  132. else if (activeBot == 0 && buttonLock == false) {
  133. if (playerBotState == 0) {
  134. playerBotState = 1
  135. mainImage = playerBotSelf
  136. main_icon.src = mainImage;
  137. tagpro.zoom = zoomLevel;
  138. }
  139. else if (playerBotState == 1) {
  140. playerBotState = 2
  141. mainImage = playerBotCenter
  142. main_icon.src = mainImage;
  143. calculateCenter()
  144. goToCenter()
  145. }
  146. else {
  147. resetPlayerBot()
  148. }
  149. }
  150. powerupReplacer()
  151. }
  152.  
  153. function zoomButton() {
  154. toggleZoom()
  155. if (activeBot == 1 && buttonLock == false) {
  156. if (isCentered == true) {
  157. tagpro.zoom = zoomLevel;
  158. }
  159. else if (specBotState == 0) {
  160. tagpro.zoom = zoomLevel;
  161. }
  162. }
  163. else if (activeBot == 0 && buttonLock == false) {
  164. if (playerBotState != 0) {
  165. tagpro.zoom = zoomLevel;
  166. }
  167. }
  168. powerupReplacer()
  169. }
  170.  
  171. function centerButton() {
  172. calculateCenter()
  173. if (activeBot == 1 && buttonLock == false) {
  174. if (specBotState == 0) {
  175. specBotState = 2
  176. mainImage = specBotCenter
  177. main_icon.src = mainImage;
  178. resetDelay()
  179. calculateCenter()
  180. setTimeout(function(){
  181. goToCenter()
  182. }, buttonCameraDelay)
  183. }
  184. else {
  185. CAMERA_DELAY = buttonCameraDelay
  186. resetDelay()
  187. specBotState = 0
  188. mainImage = specBotOffImage
  189. main_icon.src = mainImage;
  190. setTimeout(function(){
  191. goToCenter()
  192. }, buttonCameraDelay)
  193. }
  194. }
  195. else if (activeBot == 0 && buttonLock == false) {
  196. if (playerBotState == 0) {
  197. playerBotState = 2
  198. mainImage = playerBotCenter
  199. main_icon.src = mainImage;
  200. tagpro.zoom = zoomLevel;
  201. calculateCenter()
  202. goToCenter()
  203. }
  204. else {
  205. resetPlayerBot()
  206. }
  207. }
  208. powerupReplacer()
  209. }
  210.  
  211. function modeButton() {
  212. if (buttonLock == false) {
  213. specBotState = 0
  214. playerBotState = 0
  215. if (activeBot == 0) {
  216. activeBot = 1
  217. mainImage = specBotOffImage
  218. main_icon.src = mainImage;
  219. }
  220. else {
  221. activeBot = 0
  222. CAMERA_DELAY = buttonCameraDelay
  223. resetDelay()
  224. setTimeout(function(){
  225. resetPlayerBot()
  226. }, buttonCameraDelay)
  227. }
  228. }
  229. powerupReplacer()
  230. }
  231.  
  232. function resetPlayerBot() {
  233. playerBotState = 0
  234. mainImage = playerBotOff
  235. main_icon.src = mainImage;
  236. tagpro.viewPort.followPlayer = true
  237. tagpro.zoom = 1.0
  238. }
  239.  
  240. function toggleZoom() {
  241. if (zoomLevel == 1.0) {
  242. zoomLevel = numZoom1
  243. zoomBar = zoomBar2
  244. zoom_icon.src = zoomBar;
  245. }
  246. else if (zoomLevel == numZoom1) {
  247. zoomLevel = numZoom2
  248. zoomBar = zoomBar3
  249. zoom_icon.src = zoomBar;
  250. }
  251. else if (zoomLevel == numZoom2) {
  252. zoomLevel = numZoom3
  253. zoomBar = zoomBar4
  254. zoom_icon.src = zoomBar;
  255. }
  256. else {
  257. zoomLevel = 1.0
  258. zoomBar = zoomBar1
  259. zoom_icon.src = zoomBar;
  260. }
  261. }
  262.  
  263. function resetDelay() {
  264. resetTime = buttonCameraDelay + 100
  265. setTimeout(function() {
  266. CAMERA_DELAY = defaultCameraDelay;
  267. }, resetTime);
  268. }
  269.  
  270. setInterval(function(){
  271. specBot();
  272. }, 100);
  273.  
  274. function calculateCenter() {
  275. collumnCount=0;
  276. rowCount=0;
  277. tileCount=0;
  278. centerX=0;
  279. centerY=0;
  280. for(collumn in tagpro.map){
  281. for(tile in tagpro.map[collumn]){
  282. tileCount++;
  283. }
  284. collumnCount++;
  285. }
  286. rowCount = tileCount/collumnCount;
  287. fakecenterX = collumnCount/2*40;
  288. fakecenterY = rowCount/2*40;
  289. centerX = fakecenterX - 20
  290. centerY = fakecenterY - 20
  291. }
  292.  
  293. function specBot() {
  294. if (activeBot == 1) {
  295. if (specBotState == 1) {
  296. if (tagpro.ui) {
  297. if ( (!tagpro.ui.blueFlagTaken && !tagpro.ui.redFlagTaken) || (tagpro.ui.blueFlagTaken && tagpro.ui.redFlagTaken) ) {
  298. if (tagpro.ui.yellowFlagTakenByRed) {
  299. goToRed()
  300. }
  301. else if (tagpro.ui.yellowFlagTakenByBlue) {
  302. goToBlue()
  303. }
  304. else {
  305. centerView()
  306. }
  307. }
  308. else if (tagpro.ui.redFlagTaken && !tagpro.ui.blueFlagTaken) {
  309. followBlue()
  310. }
  311. else if (tagpro.ui.blueFlagTaken && !tagpro.ui.redFlagTaken) {
  312. followRed()
  313. }
  314. }
  315. }
  316. else if (specBotState == 2) {
  317. setTimeout(function() {
  318. if (specBotState == 2) {
  319. goToCenter()
  320. }
  321. }, CAMERA_DELAY);
  322. }
  323. }
  324. }
  325.  
  326. function pressKey(myKey) {
  327. var press = $.Event("keydown");
  328. press.which = myKey;
  329. $("#viewPort").trigger(press);
  330. press = $.Event("keyup");
  331. $("#viewPort").trigger(press);
  332. }
  333.  
  334. function followBlue() {
  335. if (!followingBlue || tagpro.players[blueFC].flag === null) setTimeout(function() {
  336. if ( (tagpro.ui.redFlagTaken && !tagpro.ui.blueFlagTaken) && (specBotState == 1) ) {
  337. goToBlue()
  338. }
  339. }, CAMERA_DELAY);
  340. }
  341.  
  342. function followRed() {
  343. if (!followingRed || tagpro.players[redFC].flag === null) setTimeout(function() {
  344. if ( (!tagpro.ui.redFlagTaken && tagpro.ui.blueFlagTaken) && (specBotState == 1) ) {
  345. goToRed()
  346. }
  347. }, CAMERA_DELAY);
  348. }
  349.  
  350. function centerView() {
  351. if (!isCentered) setTimeout(function() {
  352. if ( (tagpro.ui.redFlagTaken && tagpro.ui.blueFlagTaken) || (!tagpro.ui.redFlagTaken && !tagpro.ui.blueFlagTaken) ) {
  353. goToCenter()
  354. }
  355. }, CAMERA_DELAY);
  356. }
  357.  
  358. function goToCenter() {
  359. tagpro.viewPort.followPlayer = false;
  360. tagpro.viewPort.source = {};
  361. tagpro.viewPort.source.x = centerX;
  362. tagpro.viewPort.source.y = centerY;
  363. tagpro.zoom = zoomLevel;
  364. isCentered = true;
  365. followingRed = false;
  366. followingBlue = false;
  367. }
  368.  
  369. function goToBlue() {
  370. tagpro.zoom = 1;
  371. tagpro.viewPort.followPlayer = true;
  372. pressKey(83);
  373. blueFC = tagpro.playerId;
  374. followingBlue = true;
  375. followingRed = false;
  376. isCentered = false;
  377. }
  378.  
  379. function goToRed() {
  380. tagpro.zoom = 1;
  381. tagpro.viewPort.followPlayer = true;
  382. pressKey(65);
  383. redFC = tagpro.playerId;
  384. followingRed = true;
  385. followingBlue = false;
  386. isCentered = false;
  387. }
  388.  
  389. //store power up tiles
  390. jukeJuice = tagpro.tiles[6.1]
  391. rollingBomb = tagpro.tiles[6.2]
  392. tagPro = tagpro.tiles[6.3]
  393. generic = tagpro.tiles[6.4]
  394.  
  395. //Show or Hide powerups
  396. function hidePower() {
  397. tagpro.tiles[6.1] = generic
  398. tagpro.tiles[6.2] = generic
  399. tagpro.tiles[6.3] = generic
  400. tagpro.api.redrawBackground()
  401. }
  402.  
  403. function showPower() {
  404. tagpro.tiles[6.1] = jukeJuice
  405. tagpro.tiles[6.2] = rollingBomb
  406. tagpro.tiles[6.3] = tagPro
  407. tagpro.api.redrawBackground()
  408. }
  409.  
  410. function powerupReplacer() {
  411. if (!tagpro.spectator) {
  412. if (tagpro.zoom != 1) {
  413. if ( (powerupMode == 2) || (powerupMode == 1 && canShowPower) ) {
  414. showPower()
  415. }
  416. else {
  417. hidePower()
  418. }
  419. }
  420. else {
  421. showPower()
  422. }
  423. }
  424. }
  425.  
  426. gameStartTimer = setInterval(function(){
  427. showPowerupAfterDelay();
  428. }, 250);
  429.  
  430. function showPowerupAfterDelay() {
  431. if (powerupMode != 1) {
  432. clearInterval(gameStartTimer);
  433. }
  434. else if (tagpro.state == 1 && gotState == false) {
  435. gotState = true
  436. clearInterval(gameStartTimer);
  437. setTimeout(function(){
  438. canShowPower = true
  439. showPower()
  440. }, 15000)
  441. }
  442. }
  443.  
  444. //get map name
  445. setTimeout(function(){
  446. mapInfo = $("#mapInfo").text()
  447. end = mapInfo.indexOf(" by ")
  448. mapName = mapInfo.substr(5,end-5)
  449. console.log(mapName)
  450. },200)
  451.  
  452. //hide 'game starting soon...' alert so that you can see the map
  453. setTimeout(function(){
  454. original = tagpro.ui.largeAlert
  455. tagpro.ui.largeAlert = function (e,t,n,r,i){
  456. console.log(i)
  457. if (r == "Match Begins Soon...") {
  458. if (showMapName) {
  459. r=mapName
  460. } else {
  461. r=""
  462. }
  463. }
  464. return original(e,t,n,r,i)
  465. }
  466. },400)
Advertisement
Add Comment
Please, Sign In to add comment