Events::remove
Server-Side Function
Removes the specified event from events tree.
JavaScript Syntax
Syntax
mp.events.remove("eventName"); // Removes all eventName instances
mp.events.remove("eventName", functionInstance); // Removes specified event instance.
mp.events.remove(["eventName1", "eventName2"]); // Removes all specified events instances.
//alternatively you can use '.destroy' if event was created as a class (example below)
event.destroy()
Example
Shared
function onPlayerDeath(player, reason, killer){
console.log(player.name + " died.");
mp.events.remove("playerDeath", onPlayerDeath); // Once someone died, remove the event.
}
mp.events.add("playerDeath", onPlayerDeath);
//Using class
const myEvent = new mp.Event("playerDeath", (player, reason, killer) => {
console.log(`${player.name} ${killer ? `was killed by ${killer.name}` : `died`}`);
});
myEvent.destroy(); //destroy the event
See Also
- Functions
- Properties