Jump to content

refresh players list


Castillo

Recommended Posts

pList = guiCreateGridList(194,9,300,300,false,wn) 
column = guiGridListAddColumn( pList, "Player", 0.85 ) 
  
function refresh ( ) 
    guiGridListClear ( pList ) 
    for id, player in ipairs ( getElementsByType ( "player" ) ) do 
        local row = guiGridListAddRow ( pList ) 
        guiGridListSetItemText ( pList, row, column, getPlayerName ( player ), false, false ) 
    end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, refresh ) 
addEventHandler ( "onClientPlayerJoin", root, refresh ) 
addEventHandler ( "onClientPlayerQuit", root, refresh ) 
addEventHandler ( "onClientPlayerChangeNick", root, refresh ) 

That'll update it every time a player joins/quits/changes nick.

Link to comment
pList = guiCreateGridList(194,9,300,300,false,wn) 
column = guiGridListAddColumn( pList, "Player", 0.85 ) 
  
function refresh ( ) 
    for id, player in ipairs ( getElementsByType ( "player" ) ) do 
        guiGridListSetItemText ( pList, guiGridListAddRow ( pList ), column, getPlayerName ( player ), false, false ) 
    end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, refresh ) 
  
function update ( old, new ) 
    if ( eventName == "onClientPlayerJoin" ) then 
        guiGridListSetItemText ( pList, guiGridListAddRow ( pList ), column, getPlayerName ( source ), false, false ) 
    elseif ( eventName == "onClientPlayerQuit" ) then 
        for row = 0, guiGridListGetRowCount ( pList ) do 
            if ( guiGridListGetItemText ( pList, row, column ) == getPlayerName ( source ) ) then 
                guiGridListRemoveRow ( pList, row ) 
                break 
            end 
        end 
    elseif ( eventName == "onClientPlayerChangeNick" ) then 
        for row = 0, guiGridListGetRowCount ( pList ) do 
            if ( guiGridListGetItemText ( pList, row, column ) == old ) then 
                guiGridListSetItemText ( pList, row, column, new, false, false ) 
                break 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerJoin", root, update ) 
addEventHandler ( "onClientPlayerQuit", root, update ) 
addEventHandler ( "onClientPlayerChangeNick", root, update ) 

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