Class Bot

Bots are fake players that player's can interact with.

You can do many things with them, and they even have very primitive AI capabilities.

An example of a zombie that can chase and kill players:

const zombie = new Bot("Zombie")

const outfit = new Outfit()
.body("#0d9436")
.torso("#694813")
.rightLeg("#694813")
.leftLeg("#694813")

zombie.setOutfit(outfit)

Game.newBot(zombie)

// We use bot.setinterval so that when the zombie is destroyed, the loop clears.
// It's good practice to do this to avoid memory leaks.
zombie.setInterval(() => {
let target = zombie.findClosestPlayer(20)

if (!target) return zombie.setSpeech("")

zombie.setSpeech("BRAAINNNSSS!")

zombie.moveTowardsPlayer(target, 8)
}, 10)

let touchEvent = zombie.touching((p) => {
Game.messageAll(`[#ff0000]${p.username} was eaten by a zombie!`)
p.kill()
})

Hierarchy

  • EventEmitter
    • Bot

Constructors

  • Parameters

    • name: string

    Returns Bot

Properties

_hitMonitor: Timer
_steps: Timeout[]
assets: Assets

An object containing the current assets worn by the bot.

colors: BodyColors

An object containing the body colors of the bot.

destroyed: boolean

If .destroy() has been called on the bot.

name: string
netId: number
position: Vector3 = ...
rotation: Vector3 = ...
scale: Vector3 = ...
speech: string = ""

The speech bubble of the bot. ("" = empty).

botId: number = 0
captureRejectionSymbol: typeof captureRejectionSymbol
captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

defaultMaxListeners: number
errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

  • Returns void

  • Parameters

    • event: string | symbol
    • listener: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Bot

  • Remove the bot from Game.world,
    clear all event listeners,
    stop hit detection,
    and tell clients to delete the bot.

    Returns Promise<never>

  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

  • Returns (string | symbol)[]

  • Returns the closest player to the bot, or null.

    Parameters

    • minDist: number

    Returns Player

  • Returns number

  • Parameters

    • type: string | symbol

    Returns number

  • Parameters

    • event: string | symbol

    Returns Function[]

  • Turns the bot to face the player provided.

    Parameters

    Returns Promise<number>

  • Sets the bot's z rotation to the point provided.

    Parameters

    Returns Promise<number>

  • Moves the bot towards the player.

    Parameters

    Returns Promise<boolean>

  • Moves the bot to the point provided.

    Parameters

    Returns Promise<boolean>

  • Parameters

    • event: string | symbol
    • listener: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Bot

  • Parameters

    • event: string | symbol
    • listener: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Bot

  • Parameters

    • event: string | symbol
    • listener: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Bot

  • Parameters

    • event: string | symbol
    • listener: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Bot

  • Parameters

    • event: string | symbol
    • listener: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Bot

  • Parameters

    • event: string | symbol

    Returns Function[]

  • Parameters

    • Optional event: string | symbol

    Returns Bot

  • Parameters

    • event: string | symbol
    • listener: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Bot

  • Sets the bots avatar to a provided userId.

    Parameters

    • userId: number

    Returns Promise<boolean>

  • Identical to setInterval, but will be cleared after the bot is destroyed. Use this if you want to attach loops to bots, but don't want to worry about clearing them after they're destroyed.

    Parameters

    • callback: (() => void)

      The callback function.

        • (): void
        • Returns void

    • delay: number

      The delay in milliseconds.

    Returns Timeout

  • Parameters

    • n: number

    Returns Bot

  • Parameters

    Returns Promise<any[]>

  • Set the position of the bot.

    Parameters

    Returns Promise<boolean>

  • Set the rotation of the bot.

    Parameters

    Returns Promise<boolean>

  • Set the scale of the bot.

    Parameters

    Returns Promise<boolean>

  • Set the speech of the bot.

    Parameters

    • speech: string

    Returns Promise<boolean>

  • Starts hit detection for the bot.

    Parameters

    • callback: ((player: Player) => void)
        • (player: Player): void
        • Parameters

          Returns void

    Returns Disconnectable

  • Deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

  • Parameters

    • emitter: EventEmitter
    • event: string

    Returns AsyncIterableIterator<any>

  • Parameters

    • emitter: NodeEventTarget
    • event: string | symbol

    Returns Promise<any[]>

  • Parameters

    • emitter: DOMEventTarget
    • event: string

    Returns Promise<any[]>