Difference between revisions of "Events::add"

From RAGE Multiplayer Wiki
Jump to navigation Jump to search
m
 
Line 1: Line 1:
 +
__TOC__
 +
 +
{{SharedFunctionJS}}
 +
 
This function registers event handlers.
 
This function registers event handlers.
  
 
Returning true will destroy automatically the event handler.
 
Returning true will destroy automatically the event handler.
  
 +
{{JSContainer|
 
==Syntax==
 
==Syntax==
{{Shared}}
+
<pre>
<syntaxhighlight lang="javascript">
 
 
events.add(name, ...arguments);
 
events.add(name, ...arguments);
 
events.add( associativeArray );
 
events.add( associativeArray );
</syntaxhighlight>  
+
</pre>  
  
 
==Example==
 
==Example==
<syntaxhighlight lang="javascript">
+
{{SharedCode|
 +
<pre>
 
function onPlayerDeath(player, reason, killer)
 
function onPlayerDeath(player, reason, killer)
 
{
 
{
Line 31: Line 36:
 
     "playerDeath" : onPlayerDeath
 
     "playerDeath" : onPlayerDeath
 
});
 
});
</syntaxhighlight>
+
</pre>
 
+
}}
 +
}}
 
==See Also==
 
==See Also==
 
{{Event_functions}}
 
{{Event_functions}}

Latest revision as of 11:41, 3 December 2019

Shared
Function

Js.png JavaScript


This function registers event handlers.

Returning true will destroy automatically the event handler.

JavaScript Syntax
Jslogo.png

Syntax

events.add(name, ...arguments);
events.add( associativeArray );

Example

Shared
function onPlayerDeath(player, reason, killer)
{
    console.log(player.name + " died.");
}

mp.events.add(
{
    "playerJoin" : player =>
    {
         console.log("New player: " + player.name);
    },

    "playerQuit" : (player, reason) =>
    {
         console.log(player.name + " quit");
    },

    "playerDeath" : onPlayerDeath
});


See Also