Jump to content

AFK list


Recommended Posts

Posted

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)

You gone learn today.

I work my ass off, but I still can't pay tho.

Posted

That's because getPlayerFromName obtains a player userdata from it's name.

You must use getElementsByType instead.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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) 

Omerta Roleplay

Posted (edited)

Thanks wassim, but it got error, line 4 attempt to compare number with boolean

Edited by Guest

You gone learn today.

I work my ass off, but I still can't pay tho.

Posted (edited)
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

Omerta Roleplay

Posted
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

You gone learn today.

I work my ass off, but I still can't pay tho.

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