Skip to main content

Packets

Handling Packets with the "packet" event

The "packet" event in MooMoo.js allows you to easily handle packets sent from the server. Every time the client receives a packet, this event is triggered and the packet's data is passed to the callback function as an object with two properties: packet and data.

To use the "packet" event, define a callback function and pass it to the on method of the MooMoo object like this:

MooMoo.on("packet", (obj) => {
let packet = obj.packet;
let data = obj.data;

// do something with the packet and data
});

The packet property contains the name of the packet, and the data property contains the data associated with the packet, which will be an array. If there is no data, the data property will be an empty array. You can then use this information to perform actions based on the packet and its data.

Working with packets in a better way

You can easily add a new event listener to MooMoo with either the name of the packet function OR the packet name.

If you don't know the packet names, you can look into my MooMoo-in-depth documentation:

https://github.com/NuroC/moomoo-in-depth/tree/main/protocol/server

For example, if you want to check for players joining the game, you can either use addPlayer or 2.


MooMoo.on("addPlayer", (data) => {
// do something with the data
});

MooMoo.on("2", (data) => {
// do something with the data
});

This should work for every incoming packet that exists, if there's a packet that doesn't work, please open an issue on GitHub.

You can view an example script for a simple autoheal script here:

[link-to-file](