A common way of conveying information to players is through the chat box - specifically, broadcasting messages sent by the server (or sent only to a single player), where you can choose the cosmetics of the player.
See Chat Commands for examples on how to respond to chat commands
You can use the sendChat method for various
@EventListener("player.syncsettings")
onSettingsUpdate(ev: PlayerSyncSettingsEvent<Room>) {
ev.room.sendChat("Updated settings!");
}
The appearance of the chat message, by default, is determined by the server's config.
However, you can pass in values for the sendChat
to set cosmetics:
@EventListener("player.murder")
onPlayerMurder(ev: PlayerMurderEvent<Room>) {
if (!ev.player.playerInfo || !ev.victim.playerInfo)
return;
const message = ev.player.playerInfo.defaultOutfit.name + " killed " + ev.victim.playerInfo.defaultOutfit.name;
ev.room.sendChat(message, {
color: Color.Red,
hatId: Hat.WizardHat
});
}
Aligning your message to either the left or the right of the chat box can be done with side: MessageSide.*
in your sendChat
options:
room.sendChat(message, {
side: MessageSide.Left
});
or
room.sendChat(message, {
side: MessageSide.Right
});
Because of technical limitations, you can only send messages on the left if there is more than one player in the room.
You don't have to use Player Perspectives to only show chat commands for certain players from the server, just pass an array of recipients in the targets: []
array in your sendChat
options, for example:
room.sendChat("experiencing life through he postmodern lens", {
targets: [ room.host ]
})
Generated using TypeDoc