BanPlayer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Replace to predefined variables.)
 
(10 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{note| Don't forget to give admin rights to the resource, in which you are using banPlayer function or it won't work.}}
__NOTOC__  
__NOTOC__  
{{Server function}}
{{Server function}}
Line 12: Line 13:
{{New feature|3|1.0|
{{New feature|3|1.0|
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ban banPlayer ( player bannedPlayer, [ bool IP = true, bool Username = false, bool Serial = false,  
ban banPlayer ( player bannedPlayer, [ bool IP = true, bool Username = false, bool Serial = false, player/string responsiblePlayer = nil, string reason = nil, int seconds = 0 ] )
player responsiblePlayer = nil, string reason = nil, int seconds = 0 ] )
</syntaxhighlight>
</syntaxhighlight>
}}
}}
Line 22: Line 22:
</syntaxhighlight>
</syntaxhighlight>
}}
}}
 
{{OOP||[[player]]:ban||}}
===Required Arguments===  
===Required Arguments===  
*'''bannedPlayer:''' The player that will be banned from the server.
*'''bannedPlayer:''' The player that will be banned from the server.
Line 30: Line 30:
{{New feature|3|1.0|
{{New feature|3|1.0|
*'''IP:''' Will player be banned by IP?
*'''IP:''' Will player be banned by IP?
*'''Username:''' Will player be banned by username?
*'''Username:''' Will player be banned by [http://community.mtasa.com/ MTA Community] username (obsolete, set to ''false'')?
*'''Serial:''' Will player be banned by serial?
*'''Serial:''' Will player be banned by serial?
:'''Note:''' to ban by username or serial, ''verifyserials'' must be enabled in the server configuration file.
}}
}}
*'''responsibleElement:''' The element that is responsible for banning the player. This can be a player or the root ([[getRootElement]]()) (Maximum 30 characters if using a string).
*'''responsibleElement:''' The element that is responsible for banning the player. This can be a player or the root ([[getRootElement]]()) (Maximum 30 characters if using a string).
Line 41: Line 38:


===Returns===
===Returns===
{{Deprecated_feature|3|1.0|
Returns ''true'' if the player was banned succesfully, ''false'' if invalid arguments are specified.
}}
{{New feature|3|1.0|
Returns a [[ban]] object if banned successfully, or ''false'' if unsuccessful.
Returns a [[ban]] object if banned successfully, or ''false'' if unsuccessful.
}}


==Example==
==Example==
Line 74: Line 65:
-- Example function with the root element. Here you would pass a player element to the function.
-- Example function with the root element. Here you would pass a player element to the function.
function banCheater(theCheater)
function banCheater(theCheater)
banPlayer(theCheater, getRootElement(), "You are banned because of cheating.")
banPlayer(theCheater, root, "You are banned because of cheating.")
end
end
</syntaxhighlight>
</syntaxhighlight>


<section name="Example 3" class="server" show="true">
 
This example is Firewall Account Player by serial on Login
This example is Firewall Account Player by serial on Login
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 88: Line 79:
}
}
   
   
addEventHandler ( 'onPlayerLogin', getRootElement ( ),
addEventHandler ( 'onPlayerLogin', root,
     function ( _, theCurrentAccount )
     function ( _, theCurrentAccount )
     local Serial = Firewall[getAccountName(theCurrentAccount)]
     local Serial = Firewall[getAccountName(theCurrentAccount)]
         if ( Serial ) then
         if ( Serial ) then
             if Serial ~= getPlayerSerial ( source ) then
             if Serial ~= getPlayerSerial ( source ) then
                 banPlayer ( source, false, false, true, getRootElement ( ), 'reason ban' )
                 banPlayer ( source, false, false, true, root, 'reason ban' )
             end
             end
         end
         end
Line 99: Line 90:
)
)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==

Latest revision as of 09:37, 4 June 2023

[[{{{image}}}|link=|]] Note: Don't forget to give admin rights to the resource, in which you are using banPlayer function or it won't work.

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

Syntax

ban banPlayer ( player bannedPlayer, [ bool IP = true, bool Username = false, bool Serial = false, player/string responsiblePlayer = nil, string reason = nil, int seconds = 0 ] )

OOP Syntax Help! I don't understand this!

Method: player:ban(...)


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. For more information on optional arguments, see optional arguments.

  • IP: Will player be banned by IP?
  • Username: Will player be banned by MTA Community username (obsolete, set to false)?
  • Serial: Will player be banned by serial?
  • responsibleElement: The element that is responsible for banning the player. This can be a player or the root (getRootElement()) (Maximum 30 characters if using a string).
  • reason: The reason the player 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 a ban object if banned successfully, or false if unsuccessful.

Example

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

--Add the "ban" command handler
-- Example with the player
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 )

		--Ban the player
		banPlayer ( bannedPlayer, theClient, reason )
		outputChatBox ( "ban: " .. bannedName .. " successfully banned", theClient )

	else
		outputChatBox ( "ban: You don't have enough permissions", theClient )
	end

end
addCommandHandler ( "ban", banPlayerCommand )

-- Example function with the root element. Here you would pass a player element to the function.
function banCheater(theCheater)
	banPlayer(theCheater, root, "You are banned because of cheating.")
end


This example is Firewall Account Player by serial on Login

Firewall = 
{
    [ 'AccountName' ] = 'SerialPlayer',
    [ '3ash8' ] = '9C9F3B55D9D7BB7135FF274D3BF444E4',
    [ 'test5' ] = '1D6F76CF8D7193792D13789849498452',
}
 
addEventHandler ( 'onPlayerLogin', root,
    function ( _, theCurrentAccount )
    local Serial = Firewall[getAccountName(theCurrentAccount)]
        if ( Serial ) then
            if Serial ~= getPlayerSerial ( source ) then
                banPlayer ( source, false, false, true, root, 'reason ban' )
            end
        end
    end
)

See Also