Jump to content

Unban all


pejczi

Recommended Posts

function unBanAll ( source, command ) 
if ( hasObjectPermissionTo ( source , "function.removeBan", false ) ) then 
    local bans = getBans() 
    for i,d in ipairs ( bans ) do 
    local nick = getBanNick (d) 
    if (removeBan(d) ) then 
    outputChatBox ("All players has been successfully unbanned using Pejczi's script !" , source) 
    else 
    outPutChatBox ( " You have no permission to unban all" , source ) 
    end 
    end 
    table.getn ( bans ) 
    if #bans == 0 then 
    outputChatBox ("No players to unban!") 
end 
end 
end 
addCommandHandler ("unbanall", unBanAll) 

It shows as many "All players has been successfully unbanned using Pejczi's script " outputs, as there are bans , cause it's in the loop - the problem is i have no idea how to put it out of the loop.

Second problem is it doesn't show "You have no permission to unban all" - it shows correctly "No players to unban" when table is empty.

Any ideas ?

Link to comment
function unBanAll ( source, command ) 
    if ( hasObjectPermissionTo ( source , "function.removeBan", true ) ) then 
        local bans = getBans() 
        for i,d in ipairs ( bans ) do 
            removeBan(d) 
            if (removeBan(d) ) then 
                outputChatBox ("All players has been successfully unbanned using Pejczi's script !" , source) 
            else 
                outputChatBox ( " You have no permission to unban all" , source ) 
            end 
        end 
    else 
        outputChatBox ("No players to unban!" , source) 
    end 
end 
addCommandHandler ("unbanall", unBanAll) 

Link to comment

Doesn't output any message when i'm logged in and table is clear, when i'm not logged in ,it outputs "No players to unban!".

And still " outputChatBox ("All players has been successfully unbanned using Pejczi's script !" , source)" is in loop.

bans = {} 
function unBanAll ( source, command ) 
    if ( hasObjectPermissionTo ( source , "function.removeBan", true ) ) then 
        local bans = getBans() 
        for i,d in ipairs ( bans ) do 
            removeBan(d) 
            if (removeBan(d) ) then 
                outputChatBox ("All players has been successfully unbanned using Pejczi's script !" , source) 
            else 
                outputChatBox ( " You have no permission to unban all" , source ) 
            end 
        end 
    else 
     table.getn ( bans ) 
    if #bans == 0 then 
        outputChatBox ("No players to unban!" , source) 
        end 
    end 
end 
addCommandHandler ("unbanall", unBanAll) 
  

Added table, but still ain't work.

Link to comment
  • Moderators
    function unBanAll ( source, command ) 
        if ( hasObjectPermissionTo ( source , "function.removeBan", true ) ) then 
            local bans = getBans() 
            if #bans == 0 then 
                outputChatBox ("No players to unban!" , source) 
            else 
                local failedUnbans = 0 
                for i,ban in pairs ( bans ) do 
                    if not removeBan(ban) then 
                        failedUnbans = failedUnbans+1 
                    end 
                end 
                if failedUnbans == 0 then 
                    outputChatBox ("All players has been successfully unbanned using Pejczi's script !" , source) 
                else 
                    outputChatBox ("Failed to unban: " .. failedUnbans .. " bans.", source) 
                end 
            end 
        else 
            outputChatBox ( "You have no permission to unban all." , source ) 
        end 
    end 
    addCommandHandler ("unbanall", unBanAll) 
      

Learn lua.... ftw

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...