chat.onPlayerMessage
Runs your handler for every chat line a player sends. Unless a handler returns false, the server broadcasts the line to everyone, as normal.
Renamed in 0.28 from chat.onMessage; see renamed names.
Signature
Section titled “Signature”chat.onPlayerMessage(handler: (player: PlayerSnapshot, text: string, context: HandlerContext) => unknown): voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
handler |
(player: PlayerSnapshot, text: string, context: HandlerContext) => unknown |
Runs for each line on the independent policy path. Return false to suppress broadcast. Existing two-argument handlers remain valid; context.signal supports cooperative cancellation. |
Returns
Section titled “Returns”Nothing.
Example
Section titled “Example”Local chat: only players within 30 metres see a line.
import { chat } from "nativemp";
chat.onPlayerMessage((player, text) => { if (!player.position) return; chat.sendServerMessageNearby(player.position, 30, `${player.name} says: ${text}`); return false;});Related
Section titled “Related”chat.sendServerMessageNearby: send to nearby playerscommands.register: handle/commands