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
| Event | Arguments | Description |
|---|---|---|
ready | none | Resource host is ready. |
playerJoin | Player | Authenticated player received a numeric slot. |
playerLeave | Player | Session ended and the slot can be reused. |
playerState | Player, PlayerState | Validated state snapshot. |
chat | Player, string | Message 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 }, playerId | A 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
playerJoinnever exposes a launcher ticket or credential.- Numeric player IDs are session-scoped; pair them with
accountIdfor persistent data. - A host timeout or malformed chat result fails open as
"relay".