Events::remove: Difference between revisions
(Created page with "{{ServersideJsFunction}} __TOC__ Removes the specified event from events tree. == Syntax == <pre> mp.events.remove("eventName"); // Removes all eventName instances mp.event...") |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| 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. | ||
mp.events.remove(["eventName1", "eventName2"]); // Removes all specified events instances. | 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() | |||
</syntaxhighlight > | |||
==Example== | ==Example== | ||
{{ | {{SharedCode| | ||
< | <syntaxhighlight lang="javascript"> | ||
function onPlayerDeath(player, reason, killer){ | function onPlayerDeath(player, reason, killer){ | ||
console.log(player.name + " died."); | console.log(player.name + " died."); | ||
| Line 20: | Line 26: | ||
} | } | ||
mp.events.add("playerDeath", onPlayerDeath); | 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 | |||
</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