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.
If set to false, players will not spawn in the game.
Readonly
playersAn array of all currently in-game (and authenticated) players.
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.
Readonly
serverThe main server TCP socket.
A direct pointer to the server start settings (usually start.js)
If set to false server join messages, etc will not be sent to players.
Readonly
versionThe package.json "version" of the node-hill library. *
An object containing players, teams, environment settings, etc.
Static
Readonly
captureStatic
captureSets or gets the default captureRejection value for all emitters.
Static
defaultStatic
Readonly
errorThis 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.
Static
Readonly
chatIf 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
.
[Player]Player
Message
Game.on("chat", (player, message) => {
Game.messageAll(player.username + " screams loudly: " + message)
})
Static
Readonly
chattedFires whenever any player chats in the game.
[Player]Player
Message
Game.on("chatted", (player, message) => {
console.log(message)
})
Static
Readonly
initialIdentical to player.on("initialSpawn").
Game.on("initialSpawn", (player) => {
// "player" is now fully loaded.
* })
* ```
Static
Readonly
playerFires immediately whenever a player joins the game. (Before player downloads bricks, players, assets, etc).
[Player]Player
Game.on("playerJoin", (player) => {
console.log("Hello: " + player.username)
})
Static
Readonly
playerFires whenever a player leaves the game.
[Player]Player
Game.on("playerLeave", (player) => {
console.log("Goodbye: " + player.username)
})
Static
Readonly
scriptsFires whenever the scripts finish loading.
Game.on("scriptsLoaded", () => {
// Do something
})
Static
Readonly
setFires when Game.setData is populated after the initial server post. You should use Game.setDataLoaded() instead of using a listener.
Game.setDataLoaded().then(() => {
console.log(Game.setData)
})
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
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!")
}
}
})
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.
Game.commands(["msg", "message"], (p, args) => {
Game.messageAll(args)
})
Returns player stats in JSON from this API:
https://sandpile.xyz/api/getUserInfoById/{userId}
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.
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)
Takes an array of sound emitters and loads them to all clients.
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.
Sets the environment for every player in the game.
Patches the world.environment with keys containing new properties.
Game.setEnvironment({ baseSize: 500 })
Exits the server process, and terminates any running scripts.
https://nodejs.org/api/process.html#process_process_exit_code for more information.
Static
listenerStatic
onStatic
once
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.