Options
All
  • Public
  • Public/Protected
  • All
Menu

How to Use Events in SkeldJS

Events in SkeldJS are emitted by individual objects and components, but propagate throughout the tree, meaning you can attach listeners to the client to listen to events from all objects, and know where they are coming from.

For example, you can attach a listener to a specific player to know when their name has been updated.

player.on("player.setname", ev => {
    console.log(player.id, "set their name to", ev.name);
});

Or, you can attach a listener to the client to know when any player has their name updated.

client.on("player.setname", ev => {
    console.log(ev.player.id, "set their name to", ev.name);
});

Notice how the player is attached to the data of the event, so you know where the event came from and act accordingly.

For a list of events that you can listen to globally and what data they provide, see SkeldjsClientEvents. You can see a list of events for each object in their class description in the docs.

For a list of events to listen to, see [below].

Advanced Usage

Events can be cancelled to prevent something from happening.

Cancelling

For example, you might want to prevent a system from being sabotaged.

client.on("system.sabotage", ev => {
    if (system.systemType === SystemType.O2) {
        ev.cancel();
    }
})

Hooking

Some events let you modify the data as a way to "hook" into a procedure. You will probably also have to cancel the event too, in order to prevent what would normally happen.

For example, you could change the name of a player before it's set.

client.on("player.checkname", ev => {
    ev.setName(ev.name);
});

Some events have special functions that you can find out on the documentation for them.

For example, the check name event lets you revert the altered name back to the original name.

client.on("player.checkname", ev => {
    ev.revert();
});

Due to limitations in the Among us protocol, not every event can be "hooked" in any meaningful way. For example, modifying the data in the player.setname event won't have any effect on the player's name in question. So instead, you would have to change their name manually if you wanted to updated it.

client.on("player.setname", ev => {
    ev.player.control.setName("chimpanzee");
});

Event List

Client

Room

Security Cameras

Decontamination

Doors

Electrical

Game Data

Heli Sabotage

Mira HQ Comms

Med Scan

Meetings

Moving Platform

Components

Oxygen

Players

Reactor

Room

Systems

Generated using TypeDoc