Jump to content

Updated list players


Sasu

Recommended Posts

How can I do to create a one a row for player and no create much row of the same player :S? And also How can I do to uptade the list?

function actualizarLista() 
    if ( columnPlayers ) then 
        for id, player in ipairs(getElementsByType("player")) do 
            row = guiGridListAddRow ( playerLista ) 
            guiGridListSetItemText ( playerLista, row, columnPlayers, getPlayerName ( player ), false, false ) 
        end 
        end 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), actualizarLista) 
addEventHandler("onClientPlayerChangeNick", getRootElement(), actualizarLista) 
addEventHandler("onClientResourceStart", getRootElement(), actualizarLista) 

Link to comment
function update ( old, new ) 
    if ( eventName == "onClientPlayerJoin" ) then 
        guiGridListSetItemText ( playerlist, guiGridListAddRow ( playerlist ), pcolumn, getPlayerName ( source ), false, false ) 
    elseif ( eventName == "onClientPlayerQuit" ) then 
        for row = 0, guiGridListGetRowCount ( playerlist ) do 
            if ( guiGridListGetItemText ( playerlist, row, pcolumn ) == getPlayerName ( source ) ) then 
                guiGridListRemoveRow ( playerlist, row ) 
                break 
            end 
        end 
    elseif ( eventName == "onClientPlayerChangeNick" ) then 
        for row = 0, guiGridListGetRowCount ( playerlist ) do 
            if ( guiGridListGetItemText ( playerlist, row, pcolumn ) == old ) then 
                guiGridListSetItemText ( playerlist, row, pcolumn, new, false, false ) 
                break 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerJoin", root, update ) 
addEventHandler ( "onClientPlayerQuit", root, update ) 
addEventHandler ( "onClientPlayerChangeNick", root, update ) 
  

Link to comment
function update ( old, new ) 
    if ( eventName == "onClientPlayerJoin" ) then 
        guiGridListSetItemText ( playerLista, guiGridListAddRow ( playerLista), columnPlayers, getPlayerName ( source ), false, false ) 
    elseif ( eventName == "onClientPlayerQuit" ) then 
        for row = 0, guiGridListGetRowCount ( playerLista) do 
            if ( guiGridListGetItemText ( playerLista, row, columnPlayers) == getPlayerName ( source ) ) then 
                guiGridListRemoveRow ( playerLista, row ) 
                break 
            end 
        end 
    elseif ( eventName == "onClientPlayerChangeNick" ) then 
        for row = 0, guiGridListGetRowCount ( playerLista) do 
            if ( guiGridListGetItemText ( playerLista, row, columnPlayers) == old ) then 
                guiGridListSetItemText ( playerLista, row, columnPlayers, new, false, false ) 
                break 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerJoin", root, update ) 
addEventHandler ( "onClientPlayerQuit", root, update ) 
addEventHandler ( "onClientPlayerChangeNick", root, update ) 

Try now I replaced all the variables with yours.

Link to comment
for i,v in ipairs( getElementsByType( "player" ) ) do 
    local row = guiGridListAddRow( playerList ) 
    guiGridListSetItemText( playerList, row, columnPlayers, getPlayerName( v )[1], false, false ) 
end  

If it didn't work, try this :

function getAllPlayers (  ) 
    guiGridListClear( playerList ) 
    for i,v in ipairs( getElementsByType( "player" ) ) do 
        local row = guiGridListAddRow( playerList ) 
        guiGridListSetItemText( playerList, row, 1, getPlayerName( v ), false, false ) 
    end 
end 

Edited by Guest
Link to comment
for i,v in ipairs( getElementsByType( "player" ) ) do 
    local row = guiGridListAddRow( playerList ) 
    guiGridListSetItemText( playerList, row, columnPlayers, getPlayerName( v )[1], false, false ) 
end  

function update ( old, new ) 
    if ( eventName == "onClientPlayerJoin" ) then 
    for i,v in ipairs(getElementsByType("player")) do 
        guiGridListSetItemText ( playerLista, guiGridListAddRow (playerLista), columnPlayers, v, false, false ) 
        end 
    elseif ( eventName == "onClientPlayerQuit" ) then 
        for row = 0, guiGridListGetRowCount ( playerLista) do 
        for i,v in ipairs(getElementsByType("player")) do 
            if ( guiGridListGetItemText ( playerLista, row, columnPlayers) == v ) then 
            end 
                guiGridListRemoveRow ( playerLista, row ) 
                break 
            end 
        end 
    elseif ( eventName == "onClientPlayerChangeNick" ) then 
        for row = 0, guiGridListGetRowCount ( playerLista) do 
            if ( guiGridListGetItemText ( playerLista, row, columnPlayers) == old ) then 
                guiGridListSetItemText ( playerLista, row, columnPlayers, new, false, false ) 
                break 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerJoin", root, update ) 
addEventHandler ( "onClientPlayerQuit", root, update ) 
addEventHandler ( "onClientPlayerChangeNick", root, update ) 

Correctly? But doesnt work and any error on debug 3 U.U

Link to comment

Use my code :

function getAllPlayers (  ) 
    guiGridListClear( playerList ) 
    for i,v in ipairs( getElementsByType( "player" ) ) do 
        local row = guiGridListAddRow( playerList ) 
        guiGridListSetItemText( playerList, row, 1, getPlayerName( v ), false, false ) 
    end 
end 

and add the function to the open function, Like this :

    function ( ) 
        if guiGetVisible( window ) then 
            guiSetVisible( window, false ) 
            showCursor( false ) 
            guiSetInputEnabled( false ) 
        else 
            guiSetVisible( window, true ) 
            showCursor( true ) 
            guiSetInputEnabled( true ) 
            getAllPlayers( ) 
        end 
    end 
) 

Link to comment

Try this:

function actualizarLista() 
    if ( columnPlayers ) then 
for id, playeritem in ipairs(getElementsByType("player")) do  
              local row = guiGridListAddRow ( playerLista ) 
              guiGridListSetItemText ( playerLista, row, columnPlayers, getPlayerName( playeritem ), false, false ) 
    end 
end 
addEventHandler("onClientPlayerJoin", getRootElement(), actualizarLista) 
addEventHandler("onClientPlayerChangeNick", getRootElement(), actualizarLista) 
addEventHandler("onClientResourceStart", getRootElement(), actualizarLista) 

Link to comment
Use my code :
function getAllPlayers (  ) 
    guiGridListClear( playerList ) 
    for i,v in ipairs( getElementsByType( "player" ) ) do 
        local row = guiGridListAddRow( playerList ) 
        guiGridListSetItemText( playerList, row, 1, getPlayerName( v ), false, false ) 
    end 
end 

and add the function to the open function, Like this :

    function ( ) 
        if guiGetVisible( window ) then 
            guiSetVisible( window, false ) 
            showCursor( false ) 
            guiSetInputEnabled( false ) 
        else 
            guiSetVisible( window, true ) 
            showCursor( true ) 
            guiSetInputEnabled( true ) 
            getAllPlayers( ) 
        end 
    end 
) 

Its works. Thanks All.

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