Advertisement
Guest User

Script for Agar.io bots

a guest
Oct 26th, 2015
5,119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. runBots = function(ip, token) {
  2.     if (jQuery('#token').val().length > 8) {
  3.         alert('You must to create a Party first or connect to a private server.');
  4.         return false;
  5.     } else if (jQuery('#token').val().length > 0) {
  6.         mAB = 4;
  7.     } else {
  8.         mAB = 10;
  9.     }
  10.  
  11.     bots = [];
  12.     currentServer = ip;
  13.  
  14.     for (i = 0; i < mAB; i++) {
  15.         bots.push(new WebSocket(ip));
  16.         bots[i].binaryType = "arraybuffer";
  17.         bots[i].bot = i;
  18.         bots[i].id = null;
  19.  
  20.         bots[i].onopen = function() {
  21.             a = new DataView(new ArrayBuffer(5));
  22.             a.setUint8(0, 254);
  23.             a.setUint32(1,
  24.                 5, !0);
  25.             this.send(a.buffer);
  26.             a = new DataView(new ArrayBuffer(5));
  27.             a.setUint8(0, 255);
  28.             a.setUint32(1, 154669603, !0);
  29.             this.send(a.buffer);
  30.             a = new DataView(new ArrayBuffer(1 + token.length));
  31.             a.setUint8(0, 80);
  32.             for (var c = 0; c < token.length; ++c) a.setUint8(c + 1, token.charCodeAt(c));
  33.             this.send(a.buffer);
  34.  
  35.             console.log("Bot " + this.bot + " connected.");
  36.         };
  37.         bots[i].onmessage = function() {
  38.             if (playing()) {
  39.                 this.setNick(jQuery("#botsNick").val());
  40.                 xx = jQuery("[name='botsFollow']:checked").val() == "mouse" ? ra : localStorage["x"]; // ra: target x
  41.                 yy = jQuery("[name='botsFollow']:checked").val() == "mouse" ? sa : localStorage["y"]; // sa: target y
  42.                 this.setDirection(xx, yy);
  43.             }
  44.         };
  45.         bots[i].onclose = function() {
  46.             bots.splice(this.bot, 1);
  47.             console.log("Bot " + this.bot + " closed.");
  48.         };
  49.         bots[i].onerror = function() {
  50.             bots.splice(this.bot, 1);
  51.             console.log("Bot " + this.bot + " got an error.");
  52.         };
  53.         bots[i].setNick = function(nick) {
  54.             if (typeof bots[this.bot] == "undefined") {
  55.                 return false;
  56.             }
  57.  
  58.             var a = new DataView(new ArrayBuffer(1 + 2 * nick.length));
  59.             a.setUint8(0, 0);
  60.             for (var b = 0; b < nick.length; ++b) a.setUint16(1 + 2 * b, nick.charCodeAt(b), !0);
  61.             bots[this.bot].send(a.buffer);
  62.         };
  63.         bots[i].setDirection = function(x, y) {
  64.             if (typeof bots[this.bot] == "undefined") {
  65.                 return false;
  66.             }
  67.  
  68.             a = new DataView(new ArrayBuffer(13));
  69.             a.setUint8(0, 16);
  70.             a.setInt32(1, x, !0);
  71.             a.setInt32(5, y, !0);
  72.             a.setUint32(9, 0, !0);
  73.             bots[this.bot].send(a.buffer);
  74.         }
  75.     }
  76. };
  77. stopBots = function() {
  78.     if (typeof bots != "undefined") for (i = 0; i < bots.length; i++) { bots[i].close(); }
  79.  
  80.     bots = [];
  81. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement