Difference between revisions of "GetBans"

From Multi Theft Auto: Wiki
(Example)
(Example)
Line 12: Line 12:
  
 
==Example==
 
==Example==
This example lists every ban when somebody types "/bans". WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.
 
 
<section name="Server" class="server" show="true">
 
<section name="Server" class="server" show="true">
 +
'''Example 1:''' This example lists every ban when somebody types "/bans". WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
function listBans ( playerSource )
 
function listBans ( playerSource )
Line 30: Line 30:
 
end
 
end
 
addCommandHandler ( "bans", listBans ) -- Add "/bans" as the trigger for the function.
 
addCommandHandler ( "bans", listBans ) -- Add "/bans" as the trigger for the function.
 +
</syntaxhighlight>
 +
</section>
 +
 +
<section name="Server" class="server" show="false">
 +
'''Example 2:''' <br>
 +
This example shows you how you can make a commandHandler that can return data about bans on record.<br>
 +
In this example there are several ways to get the info you want.<br>
 +
You can find the ban you are looking for by providing one or more of the following arguments: <br>
 +
- IP (The IP that has been banned)<br>
 +
- Serial (The Serial that has been banned)<br>
 +
- Nick (The Nick that has been banned)<br>
 +
'''*You only have to provide ONE argument to find what you are looking for.*'''<br><br>
 +
 +
In this example there is also TWO ways of returning the info you want to see.<br>
 +
Notice in the example that the ''' FORTH ''' argument is called ''' showOutput ''' .<br>
 +
If ''' showOutput ''' is ' 1 ' then the server will return all the data on ONE line.<br>
 +
If ''' showOutput ''' is anything else than ' 1 ' the server will return all data on seperate lines.<br><br>
 +
 +
An example of what the command could look like:<br>
 +
''' /bans 192.168.0.10 0 0 1 ''' This example would look for the IP.<br>
 +
''' /bans 0 NAME 0 1 ''' This example would look for the NAME.<br>
 +
''' /bans 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1 ''' This example would look for the Serial.<br>
 +
'''*' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ' is not a serial. Replace it with the serial you want to find. (Amazing if you know one)*'''<br><br>
 +
 +
<syntaxhighlight lang="lua">
 +
function findBanOnRecord( playerSource, cmd, iIp, iNick, iSerial, showOutput )
 +
local allBans = getBans() -- Returns a table of all bans on record.
 +
--
 +
for banID, ban in ipairs ( allBans ) do -- Loop through all the bans to find our target.
 +
--
 +
local nick = getBanNick ( ban )
 +
local ip = getBanIP ( ban )
 +
local serial = getBanSerial( ban )
 +
local banTime = getBanTime( ban )
 +
local banReason = getBanReason ( ban )
 +
 +
if not nick then -- if ' nick ' doesn't exist, we will use "N/A"
 +
nick = "N/A"
 +
end
 +
 +
if not ip then -- if ' ip ' doesn't exist, we will use "N/A"
 +
ip = "N/A"
 +
end
 +
 +
if not serial then -- if ' serial ' doesn't exist, we will use "N/A"
 +
serial = "N/A"
 +
end
 +
 +
if not banReason then -- if ' banReason ' doesn't exist, we will use "N/A"
 +
banReason = "N/A"
 +
end
 +
 +
if nick == iNick or ip == iIp or serial == iSerial then -- If any of our input arguments match any bans.
 +
if tonumber(showOutput) == 1 then -- If we use ' 1 ' in the forth argument, all the data will be output on ONE line.
 +
outputChatBox ( "Ban #" .. banID .. " | Nick: " .. nick .. " | IP: " .. ip .. " | Serial: " .. serial .. " | BanTime: " .. banTime .. " | BanReason: " .. banReason, playerSource, 0, 153, 0, true )
 +
else -- If nothing or anything other than ' 1 ' is used in the forth argument, all the data will be output on seperate lines.
 +
outputChatBox ( "Ban #" .. banID, playerSource, 0, 153, 0, true )
 +
outputChatBox ( "Nick: " .. nick, playerSource, 0, 153, 0, true )
 +
outputChatBox ( "IP: " .. ip, playerSource, 0, 153, 0, true )
 +
outputChatBox ( "Serial: " .. serial, playerSource, 0, 153, 0, true )
 +
outputChatBox ( "BanTime: " .. banTime, playerSource, 0, 153, 0, true )
 +
outputChatBox ( "BanReason: " .. banReason, playerSource, 0, 153, 0, true )
 +
end
 +
break -- Break the loop when we have found our target.
 +
end
 +
end
 +
end
 +
addCommandHandler ( "bans", listBans )
 
</syntaxhighlight>
 
</syntaxhighlight>
 
</section>
 
</section>

Revision as of 14:58, 3 December 2011

This function will return a table over all the ban values in the server.

Syntax

table getBans ()

Returns

Returns a table of all the bans.

Example

Click to collapse [-]
Server

Example 1: This example lists every ban when somebody types "/bans". WARNING: This will spam chat (for the player that executed the command) if the server has a lot of bans.

function listBans ( playerSource )
local banList = getBans() -- Return a table of all the bans.
	--
	for banID, ban in ipairs ( banList ) do -- For every ban do the following...	
		--
		local nick = getBanNick ( ban ) -- Get the IP of the ban
		--
		if nick then
			outputChatBox ( "Ban #" .. banID .. ": " .. nick, playerSource , 255, 0, 0 ) -- Output the ban.
		end
		--
	end
	--
end
addCommandHandler ( "bans", listBans ) -- Add "/bans" as the trigger for the function.
Click to expand [+]
Server

See Also