alt.on

Used to listen to built-in events when a player joins, leaves, enters a vehicle, dies, etc.

See the server event list for additional examples.

Can also be used to create custom events that can be called when an emit is invoked. See alt.emit for more information.

Declaration

alt.on<K extends keyof IServerEvent>(eventName: K, listener: IServerEvent[K]): void

Usage

alt.on('someEventName', someCallbackFunction);

Real World Example

alt.on('playerConnect', (player) => {
    console.log(`${player.name} has joined the server.`);
});

alt.on('playerDamage', (victim, attacker, damage, weaponHash) => {
    console.log(`${victim.name} has been damaged by ${attacker.name}!`);
});

alt.on('someEventName', (someArgument) => {
    console.log('Got custom event!');
});

These examples assume you have imported alt from alt-server.

results matching ""

    No results matching ""