Node.js-inspired event emitter class. Also typesafe.
npm i @rbxts/eventemitter
First make an interface with eventName: listenerFunction
pairs, for example
interface GameEvents {
playerGotItem: (player: Player, item: Item) => void;
playerDied: (player: Player) => void;
}
Then create the emitter like so:
const Emitter = new EventEmitter<GameEvents>();
where GameEvents is your event interface.
import EventEmitter from "@rbxts/eventemitter";
interface Events {
playerDead: (playerName: string) => void;
}
const Emitter = new EventEmitter<Events>();
Emitter.on("playerDead", (player) => print(`${player} died!`));
Emitter.emit("playerDead", "Mixu_78");