Jump to content

AFK list


Recommended Posts

Hello all

today i bring to you this problem, and I dont know how to fix this cuz you know im still learning

function afkList (player, command) 
    players = getPlayerFromName("player") 
    for i,thePlayer in ipairs(players) do 
    if (getElementData(thePlayer, "AFK") > 0) then 
    outputChatBox("List of AFK Players :", player, 50, 255, 50, true) 
    outputChatBox("---------------------",player, 50,255, 50, true) 
    outputChatBox("*"..getPlayerName(thePlayer).."", player, 55, 255, 55, true) 
    elseif (getElementData(thePlayer, "AFK") == 0) then 
        outputChatBox("There's no Players AFK", player, 55, 255,55, true)     
    end 
    end 
end 
addCommandHandler("afklist", afkList) 

and debug script says Error bad argument #1 ipairs (table expected, got boolean)

Link to comment

try this

function afkList (player) 
    local afkplayers = { } 
    for i,thePlayer in ipairs(getElementsByType("player")) do 
        if (getElementData(thePlayer, "AFK") > 0) then 
            table.insert(afkplayers, thePlayer)    
        end 
    end 
    if (#afkplayers > 0) then 
        outputChatBox("List of AFK Players:", player, 50, 255, 50, true) 
        outputChatBox("---------------------",player, 50,255, 50, true) 
        for i,thePlayer in ipairs(afkplayers) do 
            local name = getPlayerName(thePlayer) 
            outputChatBox("*"..name, thePlayer, 55, 255,55, true)   
        end 
        outputChatBox("---------------------",player, 50,255, 50, true) 
    else 
        outputChatBox("There's no Players AFK", player, 55, 255,55, true)   
    end 
end 
addCommandHandler("afklist", afkList) 

Link to comment
Thanks wassim, but it got error, attempt to compare number with boolean

EDIT

try this

function afkList (player) 
    local afkplayers = { } 
    for i,thePlayer in ipairs(getElementsByType("player")) do 
        if (getElementData(thePlayer, "AFK")) then 
            table.insert(afkplayers, thePlayer)    
        end 
    end 
    if (#afkplayers > 0) then 
        outputChatBox("List of AFK Players:", player, 50, 255, 50, true) 
        outputChatBox("---------------------",player, 50,255, 50, true) 
        for i,thePlayer in ipairs(afkplayers) do 
            local name = getPlayerName(thePlayer) 
            outputChatBox("*"..name, thePlayer, 55, 255,55, true)   
        end 
        outputChatBox("---------------------",player, 50,255, 50, true) 
    else 
        outputChatBox("There's no Players AFK", player, 55, 255,55, true)   
    end 
end 
addCommandHandler("afklist", afkList) 

Edited by Guest
Link to comment
Thanks wassim, but it got error, attempt to compare number with boolean

EDIT

try this

function afkList (player) 
    local afkplayers = { } 
    for i,thePlayer in ipairs(getElementsByType("player")) do 
        if (getElementData(thePlayer, "AFK")) then 
            table.insert(afkplayers, thePlayer)    
        end 
    end 
    if (#afkplayers > 0) then 
        outputChatBox("List of AFK Players:", player, 50, 255, 50, true) 
        outputChatBox("---------------------",player, 50,255, 50, true) 
        for i,thePlayer in ipairs(afkplayers) do 
            local name = getPlayerName(thePlayer) 
            outputChatBox("*"..name, thePlayer, 55, 255,55, true)   
        end 
        outputChatBox("---------------------",player, 50,255, 50, true) 
    else 
        outputChatBox("There's no Players AFK", player, 55, 255,55, true)   
    end 
end 
addCommandHandler("afklist", afkList) 

Aw Very nice, Thank you it works :D It was so fast

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