addBan | Multi Theft Auto: Wiki Skip to content

addBan

Client-side
Server-side
Shared

This function will add a ban for the specified IP/username/serial to the server.

Note

One of the three: IP, Username or Serial have to be specified.

Caution
  • Banning based on username is not recommended, because the player can change their nickname at any time and thus bypass the ban. This feature is a leftover from the times when MTA used MTA Community accounts for gameplay - today it's an outdated option, kept only for backward compatibility.
  • Banning based solely on IP is not recommended, as a player can change their IP, for example by using a VPN. The safest option is to ban the serial.

OOP Syntax Help! I don't understand this!

Syntax

ban|false addBan ( ​string IP, ​string username, ​string serial, [ ​player/string responsibleElement = "Console", ​string reason = "", ​int seconds = 0 ] )
Required arguments
  • IP: The IP to be banned. If you don't want to ban by IP, set this to nil.
  • username: The username (nick) to be banned. If you don't want to ban by username, set this to nil.
  • serial: The serial to be banned. If you don't want to ban by serial, set this to nil.
Optional arguments

Note: when using optional arguments, you might need to supply all arguments before the one you wish to use.

  • responsibleElement (default: "Console"): The element that is responsible for banning the IP/username/serial. This can be a player or the root. This also can be a string - max 30 characters.
  • reason (default: ""): The reason the IP/username/serial will be banned from the server. Max 125 characters.
  • seconds (default: 0): The amount of seconds the player will be banned from the server for. This can be 0 for an infinite amount of time.

Returns

Returns the new ban if the IP/username/serial was banned successfully, false if invalid arguments are specified.

  • ban|false: ban

Code Examples

server

This example add command to ban player serial.

local function banSerial(source, command, noob, reason)
if (noob) then
local theNoob = getPlayerFromName(noob)
if (theNoob) then
local theNoobSerial = getPlayerSerial(theNoob)
addBan(nil, nil, theNoobSerial, source, reason)
else
outputChatBox("Player "..noob.." not found.", source)
end
end
end
addCommandHandler("ban-serial", banSerial)