RoomObject

Room object provided by the native API.

Description

Room object provided by the native API.

RoomObject is the main interface which lets you control the room and listen to it's events.

Methods


<static> sendChat( message [, targetId ] )

Sends a chat message using the host player.

Description

Sends a chat message using the host player.

If targetId is null or undefined the message is sent to all players. If targetId is defined the message is sent only to the player with a matching id.

Parameters
Name Type Attributes Description
message string

Message to be displayed in the room.

targetId number <optional>

If given, the message will only be displayed to the player with this ID.

Details

<static> setPlayerAdmin( playerID, admin )

Changes the admin status of the specified player.

Description

Changes the admin status of the specified player.

Parameters
Name Type Description
playerID number

ID of the player to give or remove admin to/from.

admin boolean

true to give admin status, false to remove it.

Details

<static> setPlayerTeam( playerID, team )

Moves the specified player to a team.

Description

Moves the specified player to a team.

Parameters
Name Type Description
playerID number

ID of the player whose team is changed.

team number

ID of the player's new team.


<static> kickPlayer( playerID, reason, ban )

Kicks the specified player from the room.

Description

Kicks the specified player from the room.

TODO does ban still only use IP or auth as well?

Parameters
Name Type Description
playerID number

ID of the player to be kicked.

reason string

Text that will displayed to the user after they are kicked.

ban boolean

Whether to ban the player as well.

Details

<static> clearBan( playerId )

Clears the ban for a playerId that belonged to a player that was previously banned.

Description

Clears the ban for a playerId that belonged to a player that was previously banned.

Parameters
Name Type Description
playerId number

ID of a player that was banned before.

Details

<static> clearBans()

Clears the list of banned players.

Description

Clears the list of banned players.

Details

<static> setScoreLimit( limit )

Sets the score limit of the room.

Description

Sets the score limit of the room.

If a game is in progress this method does nothing.

Parameters
Name Type Description
limit number

Number indicating the number of goals necessary before a team is declared winner.

Details

<static> setTimeLimit( limitInMinutes )

Sets the time limit of the room.

Description

Sets the time limit of the room. The limit must be specified in number of minutes.

If a game is in progress this method does nothing.

Parameters
Name Type Description
limitInMinutes number

New time limit in minutes.

Details

<static> setCustomStadium( stadiumFileContents )

Parses the stadiumFileContents as a .hbs stadium file and sets it as the selected stadium.

Description

Parses the stadiumFileContents as a .hbs stadium file and sets it as the selected stadium.

There must not be a game in progress, if a game is in progress this method does nothing.

See example here.

Parameters
Name Type Description
stadiumFileContents string

.hbs file as a string.

Details

<static> setDefaultStadium( stadiumName )

Sets the selected stadium to one of the default stadiums.

Description

Sets the selected stadium to one of the default stadiums. The name must match exactly (case sensitive).

There must not be a game in progress, if a game is in progress this method does nothing.

Parameters
Name Type Description
stadiumName string

One of the default stadium names (case-sensitive).

Details

<static> setTeamsLock( locked )

Sets the teams lock.

Description

Sets the teams lock.

When teams are locked players are not able to change team unless they are moved by an admin.

Parameters
Name Type Description
locked boolean

Whether to lock unlock teams.

Details

<static> setTeamColors( team, angle, textColor, colors )

Sets the colors of a team.

Description

Sets the colors of a team.

Colors are represented as an integer, for example a pure red color is 0xFF0000.

Parameters
Name Type Description
team number

ID of the team whose color should be changed.

angle number

Angle of the color dividers.

textColor number

Text color as hex RGB value.

colors Array.<number>

Up to three different colors.

Details

<static> startGame()

Starts the game, if a game is already in progress this method does nothing.

Description

Starts the game, if a game is already in progress this method does nothing.

Details

<static> stopGame()

Stops the game, if no game is in progress this method does nothing.

Description

Stops the game, if no game is in progress this method does nothing.

Details

<static> pauseGame( pauseState )

Sets the pause state of the game.

Description

Sets the pause state of the game.

Parameters
Name Type Description
pauseState boolean

true = paused and false = unpaused.

Details

<static> getPlayer( playerId ) → {external:native-api.PlayerObject|null}

Returns the player with the specified id.

Description

Returns the player with the specified id. Returns null if the player doesn't exist.

Parameters
Name Type Description
playerId number

ID of the player to be returned.

Returns

The player with the specified id or null if the player doesn't exist.

Details

<static> getPlayerList() → {Array.<external:native-api.PlayerObject>}

Returns the current list of players.

Description

Returns the current list of players.

Returns

Array of players in the room.

Details

<static> getScores() → {external:native-api.ScoresObject|null}

If a game is in progress it returns the current score information.

Description

If a game is in progress it returns the current score information. Otherwise it returns null

Returns

Score information or null.

Details

<static> getBallPosition() → {Object.<string, number>|null}

Returns the ball's position in the field or null if no game is in progress.

Description

Returns the ball's position in the field or null if no game is in progress.

Returns

Object with x and y properties or null.

Details

<static> startRecording()

Starts recording of a haxball replay.

Description

Starts recording of a haxball replay.

Don't forget to call stopRecording or it will cause a memory leak.

Details

<static> stopRecording() → {Uint8Array|null}

Stops the recording previously started with startRecording and returns the replay file contents as a Uint8Array.

Description

Stops the recording previously started with startRecording and returns the replay file contents as a Uint8Array.

Returns null if recording was not started or had already been stopped.

Returns

Replay file as Uint8Array or null.

Details

<static> setPassword( pass )

Changes the password of the room, if pass is null the password will be cleared.

Description

Changes the password of the room, if pass is null the password will be cleared.

Parameters
Name Type Description
pass string | null

New password or null to clear the password.

Details

<static> onPlayerJoin( player )

Event called when a new player joins the room.

Description

Event called when a new player joins the room.

Parameters
Name Type Description
player external:native-api.PlayerObject

The player who joined.

Details

<static> onPlayerLeave( player )

Event called when a player leaves the room.

Description

Event called when a player leaves the room.

Parameters
Name Type Description
player external:native-api.PlayerObject

The player who left.

Details

<static> onTeamVictory( scores )

Event called when a team wins.

Description

Event called when a team wins.

Parameters
Name Type Description
scores external:native-api.ScoresObject

Score information.

Details

<static> onPlayerChat( player, message ) → {boolean}

Event called when a player sends a chat message.

Description

Event called when a player sends a chat message.

Parameters
Name Type Description
player external:native-api.PlayerObject

The player who sent the message.

message string

The chat message.

Returns

The event function can return false in order to filter the chat message. This prevents the chat message from reaching other players in the room.

Details

<static> onPlayerBallKick( player )

Event called when a player kicks the ball.

Description

Event called when a player kicks the ball.

Parameters
Name Type Description
player external:native-api.PlayerObject

The player who kicked the ball.

Details

<static> onTeamGoal( team )

Event called when a team scores a goal.

Description

Event called when a team scores a goal.

Parameters
Name Type Description
team number

ID of the team that scored.

Details

<static> onGameStart( byPlayer )

Event called when a game starts.

Description

Event called when a game starts.

Parameters
Name Type Description
byPlayer external:native-api.PlayerObject

The player which caused the event (can be null if the event wasn't caused by a player).

Details

<static> onGameStop( byPlayer )

Event called when a game stops.

Description

Event called when a game stops.

Parameters
Name Type Description
byPlayer external:native-api.PlayerObject

The player which caused the event (can be null if the event wasn't caused by a player).

Details

<static> onPlayerAdminChange( changedPlayer, byPlayer )

Event called when a player's admin rights are changed.

Description

Event called when a player's admin rights are changed.

Parameters
Name Type Description
changedPlayer external:native-api.PlayerObject

The player whose admin rights were changed.

byPlayer external:native-api.PlayerObject

The player which caused the event (can be null if the event wasn't caused by a player).

Details

<static> onPlayerTeamChange( changedPlayer, byPlayer )

Event called when a player team is changed.

Description

Event called when a player team is changed.

Parameters
Name Type Description
changedPlayer external:native-api.PlayerObject

The player whose team was changed.

byPlayer external:native-api.PlayerObject

The player which caused the event (can be null if the event wasn't caused by a player).

Details

<static> onPlayerKicked( kickedPlayer, reason, ban, byPlayer )

Event called when a player has been kicked from the room.

Description

Event called when a player has been kicked from the room. This is always called after the onPlayerLeave event.

Parameters
Name Type Description
kickedPlayer external:native-api.PlayerObject

The player that was kicked.

reason string

The reason that was displayed to the kicked player.

ban boolean

Whether the player was banned.

byPlayer external:native-api.PlayerObject

The player which caused the event (can be null if the event wasn't caused by a player).

Details

<static> onGameTick()

Event called once for every game tick (happens 60 times per second).

Description

Event called once for every game tick (happens 60 times per second).

This is useful if you want to monitor the player and ball positions without missing any ticks.

This event is not called if the game is paused or stopped.

Details

<static> onGamePause( byPlayer )

Event called when the game is paused.

Description

Event called when the game is paused.

Parameters
Name Type Description
byPlayer external:native-api.PlayerObject

The player which caused the event (can be null if the event wasn't caused by a player).

Details

<static> onGameUnpause( byPlayer )

Event called when the game is unpaused.

Description

Event called when the game is unpaused.

After this event there's a timer before the game is fully unpaused, to detect when the game has really resumed you can listen for the first onGameTick event after this event is called.

Parameters
Name Type Description
byPlayer external:native-api.PlayerObject

The player which caused the event (can be null if the event wasn't caused by a player).

Details

<static> onPositionsReset()

Event called when the players and ball positions are reset after a goal happens.

Description

Event called when the players and ball positions are reset after a goal happens.

Details

<static> onPlayerActivity( player )

Event called when a player gives signs of activity, such as pressing a key.

Description

Event called when a player gives signs of activity, such as pressing a key.

This is useful for detecting inactive players.

Parameters
Name Type Description
player external:native-api.PlayerObject

The player for whom activity has been detected.

Details

<static> onStadiumChange( newStadiumName, byPlayer )

Event called when the stadium is changed.

Description

Event called when the stadium is changed.

Parameters
Name Type Description
newStadiumName string

Name of the new stadium.

byPlayer external:native-api.PlayerObject

The player which caused the event (can be null if the event wasn't caused by a player).

Details

Event called when the room link is obtained.

Description

Event called when the room link is obtained.

Parameters
Name Type Description
url string

The full URL of the room.

Details