class Events
package fivem.shared.core
FiveM's event bus, with the two-step registration collapsed into one call.
Raw FiveM requires RegisterNetEvent(name) and AddEventHandler(name,
fn) to receive an event from the network; forgetting the first silently
drops every incoming event, which is one of the most common bugs in FiveM
resources. Events.onNet does both.
Events.onNet("shop:opened", (shopId:String) -> openShop(shopId));
Events.emit("shop:opened", "ammunation"); // local only
Cross-network sending lives in the environment-specific classes, since
the direction differs: fivem.client.core.Net.emitServer and
fivem.server.core.Net.emitClient / emitAll.
Static methods
staticinlinecancel():Void
Cancels the event currently being handled, stopping handlers in other
resources from running and — for cancellable game events like
playerConnecting or entityCreating — telling the game not to
proceed.
staticinlineemit(eventName:String, args:Rest<Dynamic>):Void
Raises an event locally, in this and every other resource listening for it.
staticon(eventName:String, handler:Function):EventSubscription
Handles a purely local event — one raised by emit, or by the game
itself (gameEventTriggered, entityCreated, playerConnecting, ...).
Deliberately does not register a net event, so a handler added this way can't be triggered by a malicious client.
staticonNet(eventName:String, handler:Function):EventSubscription
Handles an event that may arrive over the network, registering it as a net event first.
On the server, the triggering player's ID is available inside the
handler as the source global rather than as an argument — read it via
Events.source(). Always validate it: a client can trigger any
registered net event with any arguments it likes.
staticonce(eventName:String, handler:Function):EventSubscription
Handles an event once, then detaches.
staticinlinesource():Int
The player who triggered the currently executing net event, on the server. Returns 0 when the event didn't come from a player.
source is a Lua global the runtime sets around each event handler
rather than an argument, which is why it needs reading like this.
staticinlinewasCancelled():Bool
Whether the event currently being handled has already been cancelled by someone.