CanPlayerUseFunction: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(updated)
Line 1: Line 1:
{{Needs_Checking|Should the function still be string? --[[User:Talidan2|Talidan2]] 15:44, 15 July 2007 (CDT)}}
__NOTOC__  
__NOTOC__  
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.
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.
Line 16: Line 17:
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.
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.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler ( "kill_player", "adminKillPlayer" )
function adminKillPlayer ( source, commandName, killPlayerName )
function adminKillPlayer ( source, commandName, killPlayerName )
     if ( canPlayerUseFunction ( source, "kill_player" ) ) then
     if ( canPlayerUseFunction ( source, "kill_player" ) ) then --if the player can use the "kill_player" function.
         playerToKill = getPlayerFromNick ( killPlayerName )
         playerToKill = getPlayerFromNick ( killPlayerName )
         if ( playerToKill != false ) then
         if ( playerToKill ~= false ) then --if the player exists from the name
             killPlayer ( playerToKill )
             killPlayer ( playerToKill ) --kill him
             outputConsole ( killPlayerName .. " has been killed!", source )
             outputConsole ( killPlayerName .. " has been killed!", source )--and notify the admin
         else
         else
             outputConsole ( "Couldn't find a player called '" .. killPlayerName .. "'", source )
             outputConsole ( "Couldn't find a player called '" .. killPlayerName .. "'", source ) --otherwise tell him the player was not found
         end
         end
     else
     else
         outputConsole ( "You do not have access to this function!", source )
         outputConsole ( "You do not have access to this function!", source ) --if he cant use the function, tell him he has no access
     end
     end
end
end
addCommandHandler ( "kill_player", adminKillPlayer )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Player_functions}}
{{Player_functions}}

Revision as of 20:44, 15 July 2007

Dialog-information.png This article needs checking.

Reason(s): Should the function still be string? --Talidan2 15:44, 15 July 2007 (CDT)

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.

function adminKillPlayer ( source, commandName, killPlayerName )
    if ( canPlayerUseFunction ( source, "kill_player" ) ) then  --if the player can use the "kill_player" function.
        playerToKill = getPlayerFromNick ( killPlayerName )
        if ( playerToKill ~= false ) then --if the player exists from the name
            killPlayer ( playerToKill ) --kill him
            outputConsole ( killPlayerName .. " has been killed!", source )--and notify the admin
        else
            outputConsole ( "Couldn't find a player called '" .. killPlayerName .. "'", source ) --otherwise tell him the player was not found
        end
    else
        outputConsole ( "You do not have access to this function!", source ) --if he cant use the function, tell him he has no access
    end
end
addCommandHandler ( "kill_player", adminKillPlayer )

See Also