GetBans: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(This has a lot more chance to work)
m (fix oop)
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}
{{Server function}}
This function will return a table over all the [[ban]] values in the server.
This function will return a table containing all the [[ban]]s present in the server's banlist.xml.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table getBans ()
table getBans ( )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[Ban]].getList}}


===Returns===
===Returns===
Returns a [[table]] over all the [[ban]] pointers.
Returns a [[table]] containing all the [[ban]]s.


==Example==
==Example==
<section name="Example 1: Server" class="server" show="true">
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.
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 ()
function listBans ( playerSource )
local bansList = getBans() -- Return a table of all the bans.
local banList = getBans() -- Return a table of all the bans.
--
for banID, ban in ipairs ( banList ) do -- For every ban do the following...
for banID, ban in ipairs ( banList ) do -- For every ban do the following...
--
local nick = getBanNick ( ban ) -- Get the IP of the ban
local nick = getBanNick ( ban ) -- Get the IP of the ban
--
if nick then
if nick then
outputChatBox ( "Ban #" .. banID .. ": " .. nick, source, 255, 0, 0 ) -- Output the ban.
outputChatBox ( "Ban #" .. banID .. ": " .. nick, playerSource , 255, 0, 0, true ) -- Output the ban.
end
end
--
end
end
--
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>
</syntaxhighlight>
 
</section>
==See Also==
==See Also==
{{Admin functions}}
{{Admin functions}}
[[ru:getBans]]
[[ru:getBans]]

Latest revision as of 14:39, 7 August 2016

This function will return a table containing all the bans present in the server's banlist.xml.

Syntax

table getBans ( )


OOP Syntax Help! I don't understand this!

Method: Ban.getList(...)


Returns

Returns a table containing all the bans.

Example

Click to collapse [-]
Example 1: Server

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, true ) -- Output the ban.
		end
		--
	end
	--
end
addCommandHandler ( "bans", listBans ) -- Add "/bans" as the trigger for the function.

See Also