Jump to content

Ad restriction for admin


Bean666

Recommended Posts

i need help with the /ad command because all players can use it , i tried to use isObjectinACLGroup but i'd some problem with it . Code:

function Announcement(thePlayer, commandName, ...) 
        local players = getElementsByType("player") 
        local playerName = getPlayerName ( thePlayer ) 
        local chatContent = {...} 
        for index, player in ipairs ( players ) do 
            outputChatBox( "Announcement from " .. playerName.. ": " ..table.concat ( chatContent, " "), player, 255, 190, 105) 
        end 
    end 
addCommandHandler( "ad", Announcement ) 

Link to comment

You can use this function :D

  
  
local acls = { "Owner", "Developers", "Administators", "Moderators" , "Console" } 
  
  
function isAllownedPlayer(player) 
    local account = getPlayerAccount(player) 
    if (not account or isGuestAccount(account)) then return false end 
    local accountName = getAccountName(account) 
    for i, v in pairs ( acls ) do 
        if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( v ) ) ) then 
            return true 
        end 
    end 
  
    outputChatBox("#FFF000[sERVER]#FFFFFF You aren't an admin.", player, 255,255,255, true) 
    return false 
end 

Link to comment

"isObjectInACLGroup" requires many steps if used in a function called by a command handler, first argument is a player element which must be converted into an account object and then converted into a string. Try this:

local accName = getAccountName ( getPlayerAccount ( client ))  
if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" )) then 
    -- Executed only for ACL group "Admin" 
end 

And make sure you replace "client" with the variable name of your player element and that the player is in the ACL group "Admin".

Link to comment
  
local allowedGroups = { "Admin" } 
  
function isAllowed( player ) 
    local acc = getPlayerAccount( player ) -- Check player's account 
    if isGuestAccount( acc ) or not acc then -- See if it's a guest account or it's returning false 
        return false -- Then return false 
    end -- End the if statment 
    local acc = getAccountName( acc ) -- Check player's account name 
    for i, v in ipairs( allowedGroups ) do -- Loop through table 
        if isObjectInACLGroup( "user."..acc, aclGetGroup( v ) ) then -- Check if he is in the group 
            return true  
        end 
    end 
    return false  
end 
  
function Announcement(thePlayer, commandName, ...) 
    local players = getElementsByType("player") 
    local playerName = getPlayerName ( thePlayer ) 
    local chatContent = {...} 
    if isAllowed( thePlayer ) ~= true then 
        return  
    end 
    for index, player in ipairs ( players ) do 
        outputChatBox( "Announcement from " .. playerName.. ": " ..table.concat ( chatContent, " "), player, 255, 190, 105) 
    end 
end 
addCommandHandler( "ad", Announcement ) 
  

Explained ^

Link to comment

addCommandHandler( "ad", function ( player, commandName, ... ) 
    local pAccount = getPlayerAccount ( player )  
    if ( pAccount ) and ( not isGuestAccount ( pAccount ) ) then 
      if ( isObjectInACLGroup ( "user."..getAccountName ( pAccount ), aclGetGroup ( "Admin" ) ) ) then 
        -- your code 
    end 
  end 
end ) 
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...