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].
Events can be cancelled to prevent something from happening.
For example, you might want to prevent a system from being sabotaged.
client.on("system.sabotage", ev => {
if (system.systemType === SystemType.O2) {
ev.cancel();
}
})
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");
});
player.checkcolor
player.checkmurder
player.checkname
player.checkprotect
player.climbladder
player.completetask
player.die
player.entervent
player.exitvent
player.join
player.leave
player.move
player.murder
player.protect
player.ready
player.removeprotection
player.reportbody
player.revertshapeshift
player.scenechange
player.chat
player.quickchat
player.setcolor
player.sethat
player.sethost
player.setname
player.setnameplate
player.setpet
player.setrole
player.setskin
player.setstartcounter
player.setvisor
player.shapeshift
player.snapto
player.spawn
player.startmeeting
player.syncsettings
player.usemovingplatform
Generated using TypeDoc