// ==UserScript== // @name MooMoo.io Auto Heal // @namespace https://greasyfork.org/users/1064285-vcrazy-gaming // @version 0.2 // @description Simple auto-healing script for MooMoo.io. // @match *://moomoo.io/* // @match *://*.moomoo.io/* // @author _VcrazY_ // @require https://greasyfork.org/scripts/423602-msgpack/code/msgpack.js // @grant none // @icon https://moomoo.io/img/favicon.png?v=1 // @license MIT // @downloadURL none // ==/UserScript== (function () { // Variables let items = []; let weapons = []; let inGame = false; let tmpHealth = 100; let sTime = 0; let sCount = 0; let msgpack = window.msgpack; let ws; // WebSocket setup ws = new Promise(function (resolve) { let { send } = WebSocket.prototype; WebSocket.prototype.send = function (...x) { send.apply(this, x); this.send = send; this.io = function (...datas) { const [packet, ...data] = datas; this.send(new Uint8Array(Array.from(msgpack.encode([packet, data])))); }; this.addEventListener("message", function (e) { const [packet, data] = msgpack.decode(new Uint8Array(e.data)); let sid = data[0]; let health = data[1]; // INVENTORY let inventory = { "food": items[0], "walls": items[1], "spikes": items[2], "mill": items[3], "mine": items[4], "trap": items[5], "booster": items[6], "turret": items[7], "watchtower": items[8], "buff": items[9], "spawn": items[10], "sapling": items[11], "blocker": items[12], "teleporter": items[13] }; // ADD EVENT LISTENER let addEventListener = { "setupGame": "C", "updateHealth": "O", "killPlayer": "P", "updateItems": "V" }; switch (packet) { // SETUP GAME case addEventListener.setupGame: inGame = true; items = [0, 3, 6, 10]; weapons = [0]; break; // UPDATE HEALTH case addEventListener.updateHealth: if (sid) { if (health < 100 && inGame) { if (sCount < 4) { place(inventory.food); } setTimeout(function () { place(inventory.food); }, 120); } if (tmpHealth - health < 0) { if (sTime) { let timeHit = Date.now() - sTime; sTime = 0; sCount = timeHit <= 120 ? sCount + 1 : Math.max(0, sCount - 2); } } else { sTime = Date.now(); } tmpHealth = health; } break; // KILL PLAYER case addEventListener.killPlayer: inGame = false; break; // UPDATE ITEMS case addEventListener.updateItems: if (sid) { if (health) { weapons = sid; } else { items = sid; } } break; } }); resolve(this); }; }); // Functions const sendPacket = function (...datas) { const [type, ...data] = datas; var binary = msgpack.encode([type, data]); ws.then(function (wsInstance) { wsInstance.send(new Uint8Array(Array.from(binary))); }); }; // PLACE const place = function (id, ang) { if (inGame) { sendPacket("G", id, false); hit(ang); selectWeapon(); } }; // SELECT WEAPON const selectWeapon = function () { if (inGame) { sendPacket("G", weapons[0], true); } }; // HIT const hit = function (id, ang) { if (inGame) { sendPacket("d", 1, ang); sendPacket("d", 0, ang); } }; })();