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 / NetEvent

Function: NetEvent()

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

A decorator that subscribes a method to a network event.

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

Usage:

Example:

class NetworkHandler {
    @NetEvent('playerJoined')
    onPlayerJoined(playerId: number, playerName: string) {
        console.log(`Player joined: ${playerName} (ID: ${playerId})`);
    }
}

Parameters:

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

Parameters

eventName: string

The name of the network event to subscribe to.

Returns

Function

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

Parameters

target: object

propertyKey: string

descriptor: PropertyDescriptor

Returns

void

Defined in

shared/decorators/events/netEvent.ts:29