Events::Event: Difference between revisions
(Created page with "__NOTOC__ ===Description=== OOP constructor of Events' add function ===Syntax=== {{Shared}} <syntaxhighlight lang="javascript"> let ev = new mp.Event(name, fu...") |
No edit summary |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__TOC__ | |||
{{SharedFunctionJS}} | |||
OOP constructor of [[Events::add|Events' add]] function | OOP constructor of [[Events::add|Events' add]] function | ||
{{JSContainer| | |||
===Syntax=== | ===Syntax=== | ||
<pre> | |||
< | let ev = new mp.Event(name, functionHandler); | ||
let ev = new mp.Event(name, | </pre> | ||
</ | |||
===Required arguments=== | ===Required arguments=== | ||
*'''name''': {{RageType|String}} | *'''name''': {{RageType|String}} | ||
*''' | *'''functionHandler''': {{RageType|Void}} | ||
===Returned value=== | ===Returned value=== | ||
| Line 16: | Line 18: | ||
===Example=== | ===Example=== | ||
< | <pre> | ||
let ev = new mp.Event("playerDeath", (player, reason, killer) => | let ev = new mp.Event("playerDeath", (player, reason, killer) => | ||
{ | { | ||
| Line 23: | Line 25: | ||
}); | }); | ||
ev.destroy(); // due to this line the event is never going to be executed if we call this before it | ev.destroy(); // due to this line the event is never going to be executed if we call this before it | ||
</ | </pre> | ||
}} | |||
==See Also== | |||
{{Event_functions}} | |||
Latest revision as of 11:38, 3 December 2019
OOP constructor of Events' add function
JavaScript Syntax
Syntax
let ev = new mp.Event(name, functionHandler);
Required arguments
- name: String
- functionHandler: Void
Returned value
- Event Handler
Example
let ev = new mp.Event("playerDeath", (player, reason, killer) =>
{
mp.players.broadcast('First blood!');
ev.destroy(); // this event handler will be not called anymore since it's destroyed
});
ev.destroy(); // due to this line the event is never going to be executed if we call this before it
See Also
- Functions
- Properties