Events::remove: Difference between revisions
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
Removes the specified event from events tree. | Removes the specified event from events tree. | ||
{{JSContainer| | |||
== Syntax == | == Syntax == | ||
< | <syntaxhighlight lang="javascript"> | ||
mp.events.remove("eventName"); // Removes all eventName instances | mp.events.remove("eventName"); // Removes all eventName instances | ||
mp.events.remove("eventName", functionInstance); // Removes specified event instance. | mp.events.remove("eventName", functionInstance); // Removes specified event instance. | ||
| Line 14: | Line 16: | ||
event.destroy() | event.destroy() | ||
</ | </syntaxhighlight > | ||
==Example== | ==Example== | ||
{{ | {{SharedCode| | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
function onPlayerDeath(player, reason, killer){ | function onPlayerDeath(player, reason, killer){ | ||
| Line 34: | Line 36: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | }} | ||
}} | |||
==See Also== | ==See Also== | ||
{{Event_functions}} | {{Event_functions}} | ||
Latest revision as of 08:58, 23 April 2024
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