Skip to main content

Player

Accessing Player Information with myPlayer

The MooMoo.js API provides a property called myPlayer, which represents the current player in the game. This property is only defined when the player is actually in a game, and is undefined if the player has not yet joined.

The myPlayer property contains various information about the player, such as their name, position, and more. To access the myPlayer property, simply assign it to a variable like this:

let player = MooMoo.myPlayer;

NOTE: The myPlayer property is only defined when the player is actually in a game, and is undefined if the player has not yet joined.

To check if the game has loaded or not, you can use the isLoaded property of the MooMoo API vars. For example:

function doSomething() {
let myPlayer = MooMoo.myPlayer;
// Do something with myPlayer
}

setInterval(() => {
if (MooMoo.vars.isLoaded) { // Check if the game has loaded
doSomething();
}
}, 1000);

or, you can use the onload event:

MooMoo.onGameLoad = () => {
let myPlayer = MooMoo.myPlayer;
// Do something with myPlayer
}

This is just an example to prevent errors.

Accessing Player Data and Information

Once you have access to the myPlayer property, you can access various data and information about the player, such as:

  • x: the player's x-coordinate on the map
  • y: the player's y-coordinate on the map
  • name: the player's name
  • dir: the direction the player is facing
  • health: the player's current health
  • buildIndex: the index of the player's current building
  • weaponIndex: the index of the player's current weapon
  • weaponVariant: the variant of the player's current weapon
  • team: the player's current team
  • isLeader: a boolean indicating whether the player is the leader of their team
  • skinIndex: the index of the player's current hat (skin)
  • tailIndex: the index of the player's current accessory (tail)
  • iconIndex: the index of the player's current icon state
  • zIndex: the player's z-index
  • isVisible: a boolean indicating whether the player is currently visible

Player Positions

There is one special event for position updates, called onPositionUpdate.

When the coordinates of ANY player in your view range change, this event will be triggered. The one parameter of this event is the player object, which contains the player's name, x, y, and more.

MooMoo.onPositionUpdate = (player) => {
// Player is a Player object, which includes name, x, y and others
console.log(player.x);
console.log(player.y);
}

You can use this data and information to create scripts or perform other actions.

Player Inventory and Items

The myPlayer property also includes the player's inventory, which contains the player's items such as:

  • primary: the player's primary weapon
  • secondary: the player's secondary weapon food: the player's food
  • wall: the player's wall
  • spike: the player's spike
  • mill: the player's mill
  • mine: the player's mine
  • boostPad: the player's boost pad
  • trap: the player's trap -turret: the player's turret
  • spawnPad: the player's spawn pad You can use these items to create macros or place items on the map.

Player Methods

The myPlayer property also includes several methods that you can use to work with the player.

Placing Items

You can use the place method to place items on the map. For example:

let spike = MooMoo.myPlayer.inventory.spike;
let place = MooMoo.myPlayer.place;
place(spike);

The place method can take an optional second argument, which represents the angle in radians relative to the player at which the item will be placed.

Resources

You can get your current points(gold), wood, food, stone, and kills with the resources property. For example:

let resources = MooMoo.myPlayer.resources;
console.log(resources.points);
console.log(resources.wood);

Working with Hats and Accessories

You can use the following methods to work with hats and accessories:

  • equipHat: equips a hat. This method can take either a number representing the hat ID or the name of the hat as an argument.
  • equipAccessory: equips an accessory. This method can take either a number representing the accessory ID or the name of the accessory as an argument.
  • unequipHat: removes a hat.
  • unequipAccessory: removes an accessory.
  • buyHat: buys a hat. This method can take either a number representing the hat ID or the name of the hat as an argument.
  • buyAccessory: buys an accessory. This method can take either a number representing the accessory ID or the name of the accessory as an argument.

To buy a hat or accessory using the API, you can use the buyHat and buyAccessory methods. These methods work in the same way as the equipHat and equipAccessory methods, and can take either a number representing the item ID or the name of the item as an argument.

Chatting

You can use the chat method to send a message to the chat. For example:

let chat = MooMoo.myPlayer.chat;
chat("Hello world!");