banPlayer | Multi Theft Auto: Wiki Skip to content

banPlayer

Client-side
Server-side
Shared

This function will ban the specified player by either IP, serial or username.

OOP Syntax Help! I don't understand this!

Syntax

ban|false banPlayer ( player bannedPlayer, [ bool IP = true, bool username = false, bool serial = false, player/string responsibleElement = "Console", string reason = "", int seconds = 0 ] )
Required Arguments
  • bannedPlayer: The player that will be banned from the server.
Optional Arguments

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

  • IP (default: true): Will player be banned by IP?
  • username (default: false): Will player be banned by username? (Preferred false).
  • serial (default: false): Will player be banned by serial?
  • responsibleElement (default: "Console"): The element that is responsible for banning the player. This can be a player or the root. This also can be a string - max 30 characters.
  • reason (default: ""): The reason the player will be banned from the server.
  • 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 a ban object if banned successfully, or false if unsuccessful.

Code Examples

server

This example lets a player ban anyone if he has ACL rights.

--Add the "ban" command handler
-- Example with the player
local function banPlayerCommand(theClient, commandName, bannedName, reason)
-- Give the player a nice error if he doesn't have rights
if (hasObjectPermissionTo(theClient, "function.banPlayer")) then
--Get player element from the name
local bannedPlayer = getPlayerFromName(bannedName)
-- Check if player exists
if (not bannedPlayer) then
outputChatBox("Player "..bannedName.." not found.", theClient)
return
end
--Ban the player
banPlayer(bannedPlayer, false, false, true, theClient, reason)
outputChatBox("ban: "..bannedName.." successfully banned", theClient)
else
outputChatBox("ban: You don't have enough permissions", theClient)
end
end
addCommandHandler("ban", banPlayerCommand)