Jump to content

Player list


Recommended Posts

Posted

Hello guys!

I want to write player list based on guiCreateLabel.

This has to add players on connect and delete players on disconnect.

I'm writing to you with this, becouse i don't have any idea how to do this. Maybe table? Dunno.

Thanks for all :).

Posted
x,y = guiGetScreenSize() 
  
window = guiCreateWindow((x-200)/2, (y-400)/2, 200, 400, "Player List", false) 
guiSetVisible(window, false) 
scrollpane = guiCreateScrollPane(0, 0, 200, 400, false, window) 
  
addCommandHandler("show", function () guiSetVisible(window, true) end ) 
  
addEventHandler("onClientResourceStart", root, 
    function () 
        for k,v in ipairs(getElementsByType("player")) do 
            guiCreateLabel(0, k*15, 90, 15, tostring(getPlayerName(v)), false, scrollpane) 
        end 
    end 
) 
  
function clear () 
    for k,v in ipairs(getElementChildren(scrollpane)) do 
        destroyElement(v) 
    end 
    for k,v in ipairs(getElementsByType("player")) do 
        guiCreateLabel(0, k*15, 90, 15, tostring(getPlayerName(v)), false, scrollpane) 
    end 
end 
addEventHandler("onClientPlayerJoin", root, clear) 
addEventHandler("onClientPlayerQuit", root, clear) 
addEventHandler("onClientPlayerChangeNick", root, clear) 

I wrote sth, but it isn't showing players and scrollpane. No errors in debug.

Posted

It is showing it, but you just put it way too high:

scrollpane = guiCreateScrollPane(0, 20, 200, 400, false, window) 

with that, it works.

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

You're welcome.

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

I tested it with my friend and this script added him to da list, but didn't remove.

I'll show code 1 more:

x,y = guiGetScreenSize() 
  
window = guiCreateWindow((x-200)/2, (y-400)/2, 200, 400, "Player List", false) 
scrollpane = guiCreateScrollPane(0, 20, 200, 400, false, window) 
  
  
addEventHandler("onClientResourceStart", root, 
    function () 
        for k,v in ipairs(getElementsByType("player")) do 
            guiCreateLabel(0, k*15, 200, 15, tostring(getPlayerName(v)), false, scrollpane) 
        end 
    end 
) 
  
function clear () 
    for k,v in ipairs(getElementChildren(scrollpane)) do 
        destroyElement(v) 
    end 
    for k,v in ipairs(getElementsByType("player")) do 
        guiCreateLabel(0, k*15, 200, 15, tostring(getPlayerName(v)), false, scrollpane) 
    end 
end 
addEventHandler("onClientPlayerJoin", root, clear) 
addEventHandler("onClientPlayerQuit", root, clear) 
addEventHandler("onClientPlayerChangeNick", root, clear) 

Posted

It didn't remove on who's screen?

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
x,y = guiGetScreenSize() 
  
window = guiCreateWindow((x-200)/2, (y-400)/2, 200, 400, "Player List", false) 
scrollpane = guiCreateScrollPane(0, 20, 200, 400, false, window) 
  
  
addEventHandler("onClientResourceStart", root, 
    function () 
        for k,v in ipairs(getElementsByType("player")) do 
            guiCreateLabel(0, k*15, 200, 15, tostring(getPlayerName(v)), false, scrollpane) 
        end 
    end 
) 
  
function clear () 
    outputChatBox ( getPlayerName ( source ) .." has ".. ( eventName == "onClientPlayerQuit" and "left" or "joined" ) .." the server" ) 
    for k,v in ipairs(getElementChildren(scrollpane)) do 
        destroyElement(v) 
    end 
    for k,v in ipairs(getElementsByType("player")) do 
        guiCreateLabel(0, k*15, 200, 15, tostring(getPlayerName(v)), false, scrollpane) 
    end 
end 
addEventHandler("onClientPlayerJoin", root, clear) 
addEventHandler("onClientPlayerQuit", root, clear) 
addEventHandler("onClientPlayerChangeNick", root, clear) 

See what it outputs on chat when your friend joins/leaves.

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
x,y = guiGetScreenSize() 
  
window = guiCreateWindow((x-200)/2, (y-400)/2, 200, 400, "Player List", false) 
scrollpane = guiCreateScrollPane(0, 20, 200, 400, false, window) 
  
  
addEventHandler("onClientResourceStart", root, 
    function () 
        for k,v in ipairs(getElementsByType("player")) do 
            guiCreateLabel(0, k*15, 200, 15, tostring(getPlayerName(v)), false, scrollpane) 
        end 
    end 
) 
  
function clear () 
    for k,v in ipairs(getElementChildren(scrollpane)) do 
        destroyElement(v) 
    end 
    for k,v in ipairs(getElementsByType("player")) do 
        outputChatBox ( "Adding: ".. getPlayerName ( v ) .." to list!" ) 
        guiCreateLabel(0, k*15, 200, 15, tostring(getPlayerName(v)), false, scrollpane) 
    end 
end 
addEventHandler("onClientPlayerJoin", root, clear) 
addEventHandler("onClientPlayerQuit", root, clear) 
addEventHandler("onClientPlayerChangeNick", root, clear) 

Tell me what does it output now.

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

It shows that it is adding both of us. This is strange, really :shock:.

@EDIT: Problem resolved, thanks for all.

if v~=source then 

And 2 functions for 2 events.

Posted

Yes, that was what I though.

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.

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