Subscribes a function to a game event. You can add several handlers to the same event; they run in the order you registered them.
| Name | Type | Description |
|---|---|---|
eventName | string | Core events fired by this build: ready, disable, pluginLoaded, pluginUnloaded, login, join, quit, chat, command, break, interact, place and move. Plugins may also listen for custom events sent with emit(). |
handler | function | Called as function(e). Cancellable events may be cancelled with e:cancel([reason]). |
on('join', function(e)
e.player:send('Welcome, ' .. e.player.name .. '!')
end)
on('chat', function(e)
if e.message == 'spam' then
e.player:send('No spam.')
e:cancel()
end
end)
Use color.* or color.translate() inside the chat event. This changes the message body while leaving the default player-name prefix unchanged.
on('chat', function(e)
e.message = color.green .. e.message
end)
For a custom name and full-line format, translate a plugin-generated prefix, cancel the original chat, and send a replacement with server.broadcast(). See Chat colors.
login, chat, command, break, interact, place, and move use cancellation to affect the operation. join and quit are informational. The core event dispatcher does not stop later listeners after cancellation.