Class Player

Hierarchy

  • EventEmitter
    • Player

Constructors

Properties

_avatarLoaded: boolean = false

Used by the avatarLoaded() method to determine if the avatar already loaded.

_positionDeltaTime: number
_steps: Timeout[]
admin: boolean

If the player is a Brick Hill admin (Does not work if local is set to true.)

alive: boolean

If the player is alive or not.

assets: Assets

An object containing all of the assets the player is currently wearing.

authenticated: boolean
blockedUsers: number[]

An array containing userIds of players the player has blocked. Do NOT store player references in here. *

cameraDistance: number

The distance of how far the camera is away from the player.

cameraFOV: number

The camera field of view of the player.

cameraObject: Player

The player the camera is currently attached to.

cameraPosition: Vector3

The current camera position of the player.

cameraRotation: Vector3

The current camera rotation of the player.

cameraType: CameraType

The current camera type of the player.

chatColor: string

If set, the player's nametag color (in chat) will be set to the hex value you put.

client: Client

The player's client type

colors: BodyColors

An object containing all of the body colors the player has.

destroyTool: ((tool: Tool) => Promise<boolean>) = ...

Type declaration

    • (tool: Tool): Promise<boolean>
    • Deprecated

      Same as player.removeTool

      Parameters

      Returns Promise<boolean>

destroyed: boolean = false

True if the player has left the game.

gravity: number = 3

Gravity for player's physics.

health: number

The current health of the player.

inventory: Tool[]

An array of tools the player has in their inventory.

jumpPower: number = 5

How high the player can jump.

loadAvatar: boolean = true

If set to false, the player will not automatically load their avatar.

loadTool: boolean = true

If set to false, the player will not spawn with their tool equipped.
loadAvatar MUST be enabled for this to work.

localBricks?: Brick[]

An array containing all local bricks on the player's client.

maxHealth: number = 100

The value the player's health will be set to when they respawn. *

membershipType: number

The membershipType of the player.

muted: boolean = false

If set to true, the server will reject any chat attempts from the player. *

netId: number
position: Vector3

The current position of the player.

rotation: Vector3

The current rotation of the player.

scale: Vector3 = ...

The current scale of the player.

score: number = 0

The current score of the player.

socket: ClientSocket
spawnHandler: ((player: Player) => Vector3)

Type declaration

    • (player: Player): Vector3
    • A function that will be called whenever player.respawn() is called.

      Parameters

      Returns Vector3

spawnPosition?: Vector3

If set, player.respawn() will spawn the player in the value provided instead of a random location. This property overrides spawnHandler.

See

respawn

speech: string = ""

The current speech bubble of the player. ("" = empty).

speed: number = 4

The current speed of the player.

team: Team

The current team the player is on.

toolEquipped: Tool

The current tool the player has equipped.

userId: number

The Brick Hill userId of the player.

username: string

The username of the player.

validationToken: string

The validation token of the player

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.

playerId: number = 0

Events

avatarLoaded: AvatarLoaded = PlayerEvents.AvatarLoaded

Fires whenever a player's outfit loads.

Example

Game.on("playerJoin", (player) => {
player.on("avatarLoaded", () => {
// The outfit is now loaded.
})
})
chatted: Chatted = PlayerEvents.Chatted

Fires whenever the player chats. Functionality-wise this behaves like Game.on("chatted").

Param

Message

Example

Game.on("playerJoin", (player) => {
player.on("chatted", (message) => {
// The player chatted.
})
})
died: Died = PlayerEvents.Died

Fires whenever a player dies (health set to 0).

Example

Game.on("playerJoin", (player) => {
* player.on("died", () => {
* player.kick("This is a hardcore server.")
* })
* })
* ```
initialSpawn: InitialSpawn = PlayerEvents.InitialSpawn

Fires once when the player fully loads. (camera settings, map loads, players downloaded, etc).

Example

Game.on("playerJoin", (player) => {
* player.on("initialSpawn", () => {
* player.prompt("Hello there!")
* })
* })
* ```
moved: Moved = PlayerEvents.Moved

Fires whenever this player moves.

Param

The new position of the player

Param

The new rotation of the player

player.on("moved", (newPosition, newRotation)=>{
console.log(`${player.username} moved to ${newPosition.x}, ${newPosition.y}, ${newPosition.z}`)
})
respawn: Respawn = PlayerEvents.Respawn

Fires whenever a player spawns (respawn() is called.)

Example

Game.on("playerJoin", (player) => {
player.on("respawn", () => {
player.setHealth(1000)
})
})

Methods

  • Parameters

    • message: string
    • broadcast: boolean = false

    Returns Promise<boolean>

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Player

  • Adds the tool to the user's inventory.

    Parameters

    Returns Promise<boolean>

  • Parameters

    • message: string
    • seconds: number

    Returns Promise<boolean>

  • Parameters

    • message: string
    • seconds: number

    Returns Promise<boolean>

  • Clears all of the bricks for the player. This is a LOCAL change.
    world.bricks will not be updated!

    Returns Promise<boolean>

  • Takes an array of bricks, and deletes them all from this client.

    Parameters

    Returns Promise<boolean>

  • Parameters

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

    Returns boolean

  • Equips the tool, if It's not already in the user's inventory it will be added first.
    If you call this on a tool that is already equipped, it will be unequipped.

    Parameters

    Returns Promise<boolean>

  • Returns (string | symbol)[]

  • Returns an arary of all the players currently blocking this user.

    Returns any[]

  • Returns number

  • Calls back whenever the player presses a key.

    Deprecated

    New player.keyPressed and player.keyReleased api allows more functionality

    Example

    Game.on("initialSpawn", (player) => {
    player.speedCooldown = false

    player.keypress(async(key) => {
    if (player.speedCooldown) return
    if (key === "shift") {
    player.speedCooldown = true

    player.bottomPrint("Boost activated!", 3)

    player.setSpeed(8)

    await sleep(3000)

    player.setSpeed(4)

    player.bottomPrint("Boost cooldown...", 6)

    setTimeout(() => {
    player.speedCooldown = false
    }, 6000)
    }
    })
    })

    Parameters

    Returns Disconnectable

  • Kicks the player from the game.

    Parameters

    • message: string

      The kick message

    Returns Promise<void>

  • Parameters

    • type: string | symbol

    Returns number

  • Parameters

    • event: string | symbol

    Returns Function[]

  • Takes an array of bricks and loads them to the client locally.

    Parameters

    Returns Promise<boolean>

  • Sends a local message to the player.

    Parameters

    • message: string

      The message

    Returns Promise<boolean>

  • Sends a chat message to everyone, conforming to rate-limit / mute checks, etc.

    Parameters

    • message: string
    • generateTitle: boolean = true

    Returns Promise<boolean>

  • Calls back whenever the player clicks.

    Example

    player.mouseclick(() => {
    // The player clicked.
    })

    Parameters

    • callback: (() => void)
        • (): void
        • Returns void

    Returns Disconnectable

  • Clones an array of bricks locally to the player's client, returns an array containing the cloned bricks.

    Parameters

    Returns Promise<any[]>

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Player

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Player

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Player

  • Returns true or false if the player owns a specified assetId.

    Example

    Game.on("initialSpawn", async(p) => {
    let ownsAsset = await p.ownsAsset(106530)
    console.log("Player owns asset: ", ownsAsset)
    })

    Parameters

    • assetId: number

    Returns Promise<boolean>

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Player

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Player

  • Prompts a confirm window on the player's client.

    Parameters

    • message: string

    Returns Promise<boolean>

  • Parameters

    • event: string | symbol

    Returns Function[]

  • Parameters

    • Optional event: string | symbol

    Returns Player

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Player

  • Unequips the tool (if equipped), and removes it from player's inventory.

    Parameters

    Returns Promise<boolean>

  • Sets the appearance of the player.
    If a userId isn't specified, it will default to the player's userId.

    Error handling is highly recommended as this function makes a HTTP request.

    Parameters

    • userId: number

    Returns Promise<any[]>

  • Parameters

    • distance: number

    Returns Promise<boolean>

  • Parameters

    • fov: number

    Returns Promise<boolean>

  • Functionally the same to Game.setEnvironment, but sets the environment only for one player.

    Example

    Game.on("playerJoin", (p) => {
    p.setEnvironment( {skyColor: "6ff542"} )
    })

    Parameters

    Returns Promise<boolean[]>

  • Parameters

    • gravityValue: number

    Returns Promise<boolean>

  • Sets the players health. If the health provided is larger than maxHealth, maxHealth will automatically be
    set to the new health value.

    Parameters

    • health: number

    Returns Promise<boolean | any[]>

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

    Parameters

    • callback: (() => void)

      The callback function.

        • (): void
        • Returns void

    • delay: number

      The delay in milliseconds.

    Returns Timeout

  • Parameters

    • power: number

    Returns Promise<boolean>

  • Parameters

    • n: number

    Returns Player

  • Parameters

    • score: number

    Returns Promise<boolean>

  • Parameters

    • speech: string = ""

    Returns Promise<boolean>

  • Parameters

    • speedValue: number

    Returns Promise<boolean>

  • Parameters

    • message: string
    • seconds: number

    Returns Promise<boolean>

  • Unequips the tool from the player, but does not remove it from their inventory.

    Parameters

    Returns Promise<boolean>

  • 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[]>