CanPlayerUseFunction

From Multi Theft Auto: Wiki
Revision as of 09:50, 31 August 2006 by EAi (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function can be used to check if the player can use a function, based on their current access level. Access levels for functions are stored in the server's config file. Use this if you want to prevent a player using a function unless they are logged in with enough rights.

Syntax

bool canPlayerUseFunction ( player thePlayer, string functionName )

Required Arguments

  • thePlayer: The player who you consider is running the function.
  • functionName The name of the function which you want to check.

Returns

Returns true if the player specified can use the function specified, false otherwise.

Example

This example adds a console function called kill_player that can only be used by players with enough access rights. These access rights can be specified in the server's config file.

addCommandHandler ( "kill_player", "adminKillPlayer" )
function adminKillPlayer ( source, commandName, killPlayerName )
    if ( canPlayerUseFunction ( source, "kill_player" ) ) then
        playerToKill = getPlayerFromNick ( killPlayerName )
        if ( playerToKill != false ) then
            killPlayer ( playerToKill )
            outputConsole ( killPlayerName .. " has been killed!", source )
        else
            outputConsole ( "Couldn't find a player called '" .. killPlayerName .. "'", source )
        end
    else
        outputConsole ( "You do not have access to this function!", source )
    end
end

See Also