Events::Event: Difference between revisions

From RAGE Multiplayer Wiki
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
__TOC__
{{SharedFunctionJS}}
{{SharedFunctionJS}}


===Description===
OOP constructor of [[Events::add|Events' add]] function
OOP constructor of [[Events::add|Events' add]] function


{{JSContainer|
===Syntax===
===Syntax===
 
<pre>
<syntaxhighlight lang="javascript">
let ev = new mp.Event(name, functionHandler);
let ev = new mp.Event(name, functionHandler);
</syntaxhighlight>
</pre>
===Required arguments===
===Required arguments===
*'''name''': {{RageType|String}}
*'''name''': {{RageType|String}}
*'''functionHandler''': '''<span style="color:#008017">(...args: any) => void</span>'''
*'''functionHandler''': {{RageType|Void}}


===Returned value===
===Returned value===
Line 17: Line 18:


===Example===
===Example===
<syntaxhighlight lang="javascript">
<pre>
let ev = new mp.Event("playerDeath", (player, reason, killer) =>
let ev = new mp.Event("playerDeath", (player, reason, killer) =>
{
{
Line 24: 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
</syntaxhighlight>
</pre>
}}
 
==See Also==
{{Event_functions}}

Latest revision as of 11:38, 3 December 2019

Shared
Function

 JavaScript


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