Skip to main content

Event handlers

Register callbacks with server.on(eventName, handler) during resource initialization. A handler may be synchronous or return a Promise. Events are delivered only after the server validates the underlying session or entity.

Events

EventArgumentsDescription
readynoneResource host is ready.
playerJoinPlayerAuthenticated player received a numeric slot.
playerLeavePlayerSession ended and the slot can be reused.
playerStatePlayer, PlayerStateValidated state snapshot.
chatPlayer, stringMessage before relay; return "relay" or "suppress".
npcSpawn{ id }Controlled Server NPC became available.
npcDeath{ id }Controlled Server NPC died.
npcFinishPath{ id }Controlled Server NPC completed a path.
actorPlayerAim{ id }, playerIdA player aimed at a static Actor.

Examples

server.on("playerJoin", (player) => {
console.log(`Player ${player.id} joined`);
});

server.on("npcDeath", ({ id }) => {
console.log(`Server NPC ${id} died`);
});

server.on("actorPlayerAim", ({ id }, playerId) => {
console.log(`Player ${playerId} aimed at Actor ${id}`);
});

server.on("chat", (player, message) => {
if (message.startsWith("/")) return "suppress";
return "relay";
});

Notes

  • playerJoin never exposes a launcher ticket or credential.
  • Numeric player IDs are session-scoped; pair them with accountId for persistent data.
  • A host timeout or malformed chat result fails open as "relay".