Skip to content

events

Subscribes functions to server events.

Source: src/Moongate.Scripting/Modules/EventsModule.cs

events.off(handle) -> boolean

Removes a subscription by handle. Returns false when no such subscription exists.

ParameterTypeDefault
handlestring

Returns boolean.

events.on(name, fn) -> string

Runs fn with the event's table every time the event happens. Returns a handle for off.

EventName is one of the names listed under Available events; another name raises an error.

Load this from your bootstrap or a required module, then create a new character in the client. The listener remains registered and logs the new character’s name.

local handle = events.on("character_created", function(e)
log.info("New character {Name}", e.name)
end)

Keep handle in the scope that will perform cleanup later. Unsubscribe only when you no longer want notifications:

events.off(handle) -- returns false when the handle is unknown
ParameterTypeDefault
nameEventName
fnfunction

Returns string.

Made with ❤️ by Tom

Buy me a coffee