UNPKG

moomooio-client

Version:

MooMooIO-Client is a client-side wrapper API designed for the game MooMoo.io. This package aims to provide a simple yet powerful API for creating clones, mods, or plugins for MooMoo.io.

25 lines (19 loc) 1.14 kB
// Import the package and HookWebSocket utility import MooMooIOClient, { HookWebSocket } from "../dist"; // Create a MooMooIOClient instance const client = new MooMooIOClient(); // Define the clientWindow variable, which will hold a reference to the window object // This ensures that clientWindow will reference the appropriate window object based on the environment const clientWindow = document.defaultView || window || globalThis; // Use the HookWebSocket utility to hook websockets and observe any connections (this is used for browser-based client) HookWebSocket(clientWindow, (socket) => { // Tell MooMooIOClient to use this socket as the connection line between the client and server client.connection.use(socket); }); // Listen to any change in myPlayer's health. This can be used to achieve autoheal. client.myPlayer.on("healthChange", () => { // Check if the player's health is already above 95. If so, don't heal. if (client.myPlayer.health > 95) return; // This line of code will place/use food and then switch back to the "primary" weapon client.myPlayer.place("foodType", "primary"); });