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.


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


alt.on('someEventName', someCallbackFunction);

Real World Example

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

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

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

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

results matching ""

    No results matching ""