fivem-ts

a library to speed up the development of Fivem scripts and frameworks


Project maintained by Purpose-Dev Hosted on GitHub Pages — Theme by mattgraham

fivem-ts - Documentation v0.7.5Docs


fivem-ts - Documentation v0.7.5 / Shared / Event

Function: Event()

Event(eventName): (target, propertyKey, descriptor) => void

A decorator that subscribes a method to a specified local event.

The @Event decorator is used to associate a method with a named event. When the specified event is triggered, the decorated method will be automatically called with the event’s arguments.

Usage:

Example:

class EventHandler {
    @Event('userLoggedIn')
    onUserLoggedIn(userId: number, userName: string) {
        console.log(`User logged in: ${userName} (ID: ${userId})`);
    }
}

Parameters:

Note: Ensure that the event name matches the one used in the event system, and the method should match the expected signature of the event arguments.

Parameters

eventName: string

The name of the event to subscribe to.

Returns

Function

A method decorator that subscribes the decorated method to the specified event.

Parameters

target: object

propertyKey: string

descriptor: PropertyDescriptor

Returns

void

Defined in

shared/decorators/events/Event.ts:29