OnBan: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Reverted edits by Violence (talk) to last revision by Botder)
Tag: Rollback
 
(17 intermediate revisions by 8 users not shown)
Line 5: Line 5:
==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string theIPOrSerial
ban theBan
</syntaxhighlight>  
</syntaxhighlight>  


*'''theIPOrSerial''': The IP address or serial that was banned from the server.
*'''theBan''': the [[ban]] which was added.


==Source==
==Source==
Line 14: Line 14:


==Cancel effect==
==Cancel effect==
If this event is [[Event system#Canceling|canceled]], the requested ban is not performed.
This event cannot be canceled.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example outputs a simple message to all players when a player added a ban.
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
root = getRootElement()
function announceBan( theBan )
 
  if ( isElement( source ) ) and ( getElementType( source ) == "player" ) then -- Check if the element responsible for the ban is a player element
function announceBan( sz )
outputChatBox( getPlayerName( source ) .. " banned " .. ( getBanSerial( theBan ) or getBanIP( theBan ) ) ) -- Output to the chatbox saying the player has banned the IP/Serial
if getElementType( source ) then --Check if a player banned the IP/Serial
  end
outputChatBox( getClientName( source ) .. " banned " .. sz ) --Output to the chatbox saying the player has banned the IP/Serial
end
end
end
 
addEventHandler( "onBan", root, announceBan ) -- Adds the event handler for "onBan" and must be bound to root
addEventHandler( "onBan", root, announceBan ) --Adds the event handler for 'onBan'
</syntaxhighlight>
</syntaxhighlight>


==See Also==
{{See also/Server event|Server events}}
{{Event_functions}}

Latest revision as of 14:11, 22 August 2020

This event is triggered when an IP address or serial is banned from the server.

Parameters

ban theBan
  • theBan: the ban which was added.

Source

The source of this event is the element that was responsible for the banning. If no responsible was specified, the source is the global root element.

Cancel effect

This event cannot be canceled.

Example

This example outputs a simple message to all players when a player added a ban.

function announceBan( theBan )
   if ( isElement( source ) ) and ( getElementType( source ) == "player" ) then -- Check if the element responsible for the ban is a player element
	outputChatBox( getPlayerName( source ) .. " banned " .. ( getBanSerial( theBan ) or getBanIP( theBan ) ) ) -- Output to the chatbox saying the player has banned the IP/Serial
   end
end
addEventHandler( "onBan", root, announceBan ) -- Adds the event handler for "onBan" and must be bound to root

See Also

Server events


Event functions