AddBan: Difference between revisions
Jump to navigation
Jump to search
Milkshake333 (talk | contribs) |
Milkshake333 (talk | contribs) |
||
Line 28: | Line 28: | ||
==Example== | ==Example== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | function banPlayer( thePlayer, theCommand, theTarget, theReason, theSeconds ) | ||
if theTarget and theReason then | |||
local target = getPlayerFromName(theTarget) | |||
if target == false then --Check if there is someone online with that name | |||
outputChatbox("There isn't someone online with that name.", thePlayer) | |||
return | |||
end | |||
if hasObjectPermissionTo( thePlayer, "function.addBan", false) then | |||
--Check if the player has the permission to ban someone | |||
if hasObjectPermissionTo( getThisResource(), "function.addBan", true) then | |||
--Check if this resource has the permission to ban a player | |||
if theSeconds then | |||
--If there is a time specified we use it | |||
addBan(theTarget, thePlayer, theReason, tonumber(theSeconds)) | |||
--We ban the target by it's name. | |||
else | |||
--If there wasn't a time specified | |||
addBan(theTarget, thePlayer, theReason) | |||
--Ban him permanent | |||
end | |||
else | |||
--If the resource doesn't have the permission to use addBan | |||
outputChatBox("This resource has not acces to use the addBan function.", thePlayer) | |||
end | |||
else | |||
--If the user doesn't have the permission to use addBan | |||
outputChatBox("You do not have the acces to use the addBan function.", thePlayer) | |||
end | |||
else | |||
--Tell the syntax to the player | |||
outputChatBox("Syntax: /ban targetname reason (seconds)", thePlayer) | |||
end | |||
end | |||
addCommandHandler("ban", banPlayer) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 13:03, 1 January 2010
This function will add a ban for the specified IP/username/serial to the server.
Syntax
ban addBan ( [ string IP, string Username, string Serial, player responsibleElement, string reason, int seconds = 0 ] )
Note: One of the three: IP, Username or Serial have to be specified.
Required Arguments
- IP: The IP to be banned. If you don't want to ban by IP, set this to nil.
or
- Username: The username to be banned. If you don't want to ban by username, set this to nil.
or
- Serial: The serial to be banned. If you don't want to ban by serial, set this to nil.
or any combination.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- responsibleElement: The element that is responsible for banning the IP/username/serial. This can be a player or the root (getRootElement()).
- reason: The reason the IP/username/serial will be banned from the server.
- seconds: 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 true if the IP/username/serial was banned succesfully, false if invalid arguments are specified.
Example
function banPlayer( thePlayer, theCommand, theTarget, theReason, theSeconds ) if theTarget and theReason then local target = getPlayerFromName(theTarget) if target == false then --Check if there is someone online with that name outputChatbox("There isn't someone online with that name.", thePlayer) return end if hasObjectPermissionTo( thePlayer, "function.addBan", false) then --Check if the player has the permission to ban someone if hasObjectPermissionTo( getThisResource(), "function.addBan", true) then --Check if this resource has the permission to ban a player if theSeconds then --If there is a time specified we use it addBan(theTarget, thePlayer, theReason, tonumber(theSeconds)) --We ban the target by it's name. else --If there wasn't a time specified addBan(theTarget, thePlayer, theReason) --Ban him permanent end else --If the resource doesn't have the permission to use addBan outputChatBox("This resource has not acces to use the addBan function.", thePlayer) end else --If the user doesn't have the permission to use addBan outputChatBox("You do not have the acces to use the addBan function.", thePlayer) end else --Tell the syntax to the player outputChatBox("Syntax: /ban targetname reason (seconds)", thePlayer) end end addCommandHandler("ban", banPlayer)