addBan
This function will add a ban for the specified IP/username/serial to the server.
One of the three: IP, Username or Serial have to be specified.
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!
- Constructor: Ban(...)
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
- ban|false: ban
Returns the new ban if the IP/username/serial was banned successfully, false if invalid arguments are specified.
Code Examples
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 endendaddCommandHandler("ban-serial", banSerial)