Class Game

Hierarchy

  • EventEmitter
    • Game

Constructors

Properties

MOTD: string

The message that will be sent to players (locally) who join the game.

Default

[#14d8ff][NOTICE]: This server is proudly hosted with node-hill-s version.

afterAuth: ((player: Player) => Promise<void>)

Type declaration

    • (player: Player): Promise<void>
    • Parameters

      Returns Promise<void>

assignRandomTeam: boolean = true

This property is to compensate for a client bug. If the player team is not set automatically, the user's name won't appear on their client's leaderboard.

Only disable this if you are going to set the player's team when they join.

banNonClientTraffic: boolean
chatSettings: Record<"rateLimit", number>
newBricks: ((bricks: Brick[]) => Promise<boolean>) = ...

Type declaration

    • (bricks: Brick[]): Promise<boolean>
    • Takes an array of bricks and loads them to all clients.

      Parameters

      Returns Promise<boolean>

playerSpawning: boolean = true

If set to false, players will not spawn in the game.

players: Player[]

An array of all currently in-game (and authenticated) players.

sendBricks: boolean = true

If set to false, the bricks of the map will not be sent to the player when they join. But they will still be loaded into memory.

server: Server

The main server TCP socket.

serverSettings: GameSettings

A direct pointer to the server start settings (usually start.js)

setData: Record<string, never> | SetData
systemMessages: boolean = true

If set to false server join messages, etc will not be sent to players.

version: string

The package.json "version" of the node-hill library. *

world: World

An object containing players, teams, environment settings, etc.

Global

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.

Events

chat: Chat = GameEvents.Chat

If a Game.on("chat") listener is added, any time the game recieves a chat message, it will be emitted data to this listener, and the actual packet for sending the chat will not be sent.

You can use this to intercept chat messages, and then transform them to whatever, and then call Game.messageAll.

Param

[Player]Player

Param

Message

Example

Game.on("chat", (player, message) => {
Game.messageAll(player.username + " screams loudly: " + message)
})
chatted: Chatted = GameEvents.Chatted

Fires whenever any player chats in the game.

Param

[Player]Player

Param

Message

Example

Game.on("chatted", (player, message) => {
console.log(message)
})
initialSpawn: InitialSpawn = GameEvents.InitialSpawn

Identical to player.on("initialSpawn").

Example

Game.on("initialSpawn", (player) => {
// "player" is now fully loaded.
* })
* ```
playerJoin: PlayerJoin = GameEvents.PlayerJoin

Fires immediately whenever a player joins the game. (Before player downloads bricks, players, assets, etc).

Param

[Player]Player

Example

Game.on("playerJoin", (player) => {
console.log("Hello: " + player.username)
})
playerLeave: PlayerLeave = GameEvents.PlayerLeave

Fires whenever a player leaves the game.

Param

[Player]Player

Example

Game.on("playerLeave", (player) => {
console.log("Goodbye: " + player.username)
})
scriptsLoaded: ScriptsLoaded = GameEvents.ScriptsLoaded

Fires whenever the scripts finish loading.

Example

Game.on("scriptsLoaded", () => {
// Do something
})
setDataLoaded: SetDataLoaded = GameEvents.SetDataLoaded

Fires when Game.setData is populated after the initial server post. You should use Game.setDataLoaded() instead of using a listener.

Example

Game.setDataLoaded().then(() => {
console.log(Game.setData)
})

Methods

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Game

  • Parameters

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

    Returns void

  • Parameters

    • message: string
    • seconds: number

    Returns Promise<boolean>

  • Parameters

    • message: string
    • seconds: number

    Returns Promise<boolean>

  • Clears all of the bricks for every player connected. This wipes world.bricks, any new players who join after this is ran will download no bricks from the server.

    Returns Promise<boolean>

  • Commands are sent from the client when a user prefixes their message with / followed by any string.
    In the example below, "kick" would be the command, and "user" the argument:
    Example: /kick user

    Example

    Game.command("kick", (caller, args) => {
    if (caller.userId !== 2760) return // You're not dragonian!
    for (let player of Game.players) {
    if (player.username.startsWith(args)) {
    return player.kick("Kicked by Dragonian!")
    }
    }
    })

    Parameters

    • gameCommand: string
    • validator: ((p: Player, args: string, next: (() => void)) => void)
        • (p: Player, args: string, next: (() => void)): void
        • Parameters

          • p: Player
          • args: string
          • next: (() => void)
              • (): void
              • Returns void

          Returns void

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

    Returns Disconnectable

  • Identical to Game.command, but instead of a string it takes an array of commands.

    This will assign them all to the same callback, this is very useful for creating alias commands.

    See

    command

    Example

    Game.commands(["msg", "message"], (p, args) => {
    Game.messageAll(args)
    })

    Parameters

    • gameCommand: string[]
    • validator: ((p: Player, args: string, next: (() => void)) => void)
        • (p: Player, args: string, next: (() => void)): void
        • Parameters

          • p: Player
          • args: string
          • next: (() => void)
              • (): void
              • Returns void

          Returns void

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

    Returns Disconnectable

  • Takes an array of bricks, and deletes them all from every client. This will modify world.bricks.

    Parameters

    Returns Promise<boolean>

  • Parameters

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

    Returns boolean

  • Returns (string | symbol)[]

  • Returns number

  • Returns the data for provided setId. *

    Parameters

    • setId: number

    Returns Promise<any>

  • Parameters

    • type: string | symbol

    Returns number

  • Parameters

    • event: string | symbol

    Returns Function[]

  • Takes an array of bricks and loads them to all clients.

    Parameters

    Returns Promise<boolean>

  • Clears the map, and then calls loadBrk with the provided brk name. Then it sets all the bricks in the game, spawns, and Game.map.

    MapData: bricks, spawns, environment, tools, teams, etc is returned.

    Example

    setTimeout(async() => {
    // Load all bricks + spawns in the game
    let data = await Game.loadBrk("headquarters2.brk")

    // Set the environment details (loadBrk does not do this).
    Game.setEnvironment(data.environment)

    // This brk added spawns, let's respawn players so they aren't trapped in a brick.
    Game.players.forEach((player) => {
    player.respawn()
    })

    console.log(data)
    }, 60000)

    Parameters

    • location: string

    Returns Promise<MapData>

  • Sends a chat message to every player in the game.

    Parameters

    • message: string

    Returns Promise<boolean>

  • "Parents" a bot class to the game. *

    Parameters

    Returns Promise<boolean>

  • "Parents" a brick class to the game. You should do this after setting all the brick properties.

    Parameters

    Returns Promise<boolean>

  • Takes an array of teams and loads them to all clients.

    Example

    let teams = {
    redTeam: new Team("Red Team", "#f54242"),
    blueTeam: new Team("Blue Team", "#0051ff")
    }

    Game.newTeams(Object.values(teams))

    Parameters

    Returns void

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Game

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Game

  • Parameters

    Returns Promise<{
        disconnect: (() => Game);
    }>

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Game

  • Loads the brk file like Game.loadBrk, but returns the data rather than setting / modifying anything.

    This is useful if you want to grab teams, bricks, etc from a brk, but don't want to modify the game yet.

    Parameters

    • location: string

    Returns Promise<MapData>

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Game

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Game

  • Parameters

    • event: string | symbol

    Returns Function[]

  • Parameters

    • Optional event: string | symbol

    Returns Game

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns Game

  • Sets the environment for every player in the game.

    Patches the world.environment with keys containing new properties.

    Example

    Game.setEnvironment({ baseSize: 500 })
    

    Parameters

    Returns Promise<boolean[]>

  • Parameters

    • n: number

    Returns Game

  • Parameters

    • message: string
    • seconds: number

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