Player::ban: Difference between revisions

From RAGE Multiplayer Wiki
(Added an example, parameters and better description.)
m (category)
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:


== Syntax ==
== Syntax ==
<syntaxhighlight lang="javascript">
<pre>
player.ban(reason)
player.ban(reason)
</syntaxhighlight>
</pre>


=== Parameters ===
=== Parameters ===
Line 13: Line 13:
== Example ==
== Example ==
Creates a ban command.
Creates a ban command.
<div class="header" style="background-color: #408DAE; color: #FFFFFF; border: 2px solid #408DAE;">
{{ServersideCode|
<div style="margin: 10px 10px 10px 10px;"><b>Server-Side</b></div>
<pre>
<pre>
mp.events.addCommand('ban', (player, target) => {
mp.events.addCommand('ban', (player, target) => {
Line 24: Line 23:
});
});
</pre>
</pre>
</div>
}}




==See Also==
==See Also==
{{Player_block}}
{{Player_block}}
[[Category:Player API]]
[[Category:Server-side Function]]

Latest revision as of 16:57, 17 May 2019

This function bans the player from your server.

Note: The ban reason doesn't display for the player, you need to use something else to display it for the player. Also, all bans that use this function are cleared once the server restarts. You need to save the bans yourself if you want them to stay after restarting your server.

Syntax

player.ban(reason)

Parameters

  • reason: String

Example

Creates a ban command.

Server-Side
mp.events.addCommand('ban', (player, target) => {
	let newTarget = mp.players.at(target);
	if(!target || isNaN(target)) return player.outputChatBox("Syntax: /ban [playerID]");
	if(newTarget === null) return player.outputChatBox("There is no player online with the ID given.")
	newTarget.outputChatBox("You have been banned from the server.");
	newTarget.ban('Banned.');
});


See Also