SkeldJS allows you to imperatively create the intent for a game to end, that is, you're telling SkeldJS that you want the game to end.
You can hook into them and cancel them, preventing them from actually causing a game ending.
You can use the Hostable.registerEndGameIntent method to register an intent, and will be checked and ended on the next fixed update cycle.
Note that end game intents don't guarantee that the game has ended or that it will end.
SkeldJS uses end game intents internally (which also means you can cancel typical end game behaviours).
if (aliveImpostors <= 0) {
client.registerEndGameIntent(
new EndGameIntent<PlayersVoteOutEndgameMetadata>(
AmongUsEndGames.PlayersVoteOut,
GameOverReason.HumansByVote,
{
exiled,
aliveCrewmates,
aliveImpostors
}
)
);
}
This end-game intent is registered immediately after a meeting if there are 0 impostors remaining.
Notice how you can pass in metadata to make a more informed decision about whether or not to cancel it when it comes to listening for it in an event.
client.on("room.endgameintent", ev => {
if (ev.intentName === AmongUsEndGames.PlayerVoteOut) {
if (ev.metadata.aliveImpostors === 0) { // the intent was registered when the last impostor was voted out.
ev.cancel();
}
}
});
You can access all built-in intent names via the AmongUsEndGames enum.
Generated using TypeDoc