Jump to content

Simple guigridlist not working


aintaro

Recommended Posts

Hello guys,

I'm having a problem with my gridlist, I first load players in the list and whenever I want to click them it does not print their name in the outputchat box, Why does this code not work?

--Create the gridlist with players in 
  
function createPlayerList () 
        -- Create the grid list 
        playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
        -- Create a players column in the list 
        local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
        if ( column ) then         -- If the column has been created, fill it with players 
                for id, playeritem in ipairs(getElementsByType("player")) do 
                        local row = guiGridListAddRow ( playerList ) 
                        guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) 
                end 
                addEventHandler ( "onClientGUIClick", playerList, click ) 
        end 
end 
--addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) 
  
 --handle the player click when he clicks on a gridlist item 
function click ( button, state, sx, sy, x, y, z, elem, gui ) 
        -- if state is down ( not to trigger the function twice on mouse button up/down), clicked gui and the element is our player list 
        if ( ( state == "down" ) and ( gui == true ) and ( source == playerList ) ) then 
                -- get the player name from the selected row, first column  
                local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) 
                outputChatBox ( playerName )     -- output it to chat box 
        end 
end 
  
--This function is called when we start the client 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),  
    function () 
        -- create the log in window and its components 
            createPlayerList () 
  
        -- enable the players cursor (so they can select and click on the components) 
            showCursor(true) 
        -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening 
            guiSetInputEnabled(true) 
    end 
) 

Thanks in advance,

Greetz Aintaro

Link to comment

Check this

function createPlayerList () 
        -- Create the grid list 
        playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
        -- Create a players column in the list 
        local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
        if ( column ) then         -- If the column has been created, fill it with players 
                for id, playeritem in ipairs(getElementsByType("player")) do 
                        local row = guiGridListAddRow ( playerList ) 
                        guiGridListSetItemText ( playerList, row, column, getPlayerName ( playeritem ), false, false ) 
                end 
        end 
end 
  
--addEventHandler ( "onClientResourceStart", getRootElement(), createPlayerList ) 
  
 --handle the player click when he clicks on a gridlist item 
function click ( button, state, sx, sy, x, y, z, elem, gui ) 
        -- if state is down ( not to trigger the function twice on mouse button up/down), clicked gui and the element is our player list 
        if ( ( state == "down" ) and ( gui == true ) and ( source == playerList ) ) then 
                -- get the player name from the selected row, first column 
                local playerName = guiGridListGetItemText ( playerList, guiGridListGetSelectedItem ( playerList ), 1 ) 
                outputChatBox ( playerName )     -- output it to chat box 
        end 
end 
addEventHandler ( "onClientGUIClick", playerList, click ) 
  
--This function is called when we start the client 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function () 
        -- create the log in window and its components 
            createPlayerList () 
  
        -- enable the players cursor (so they can select and click on the components) 
            showCursor(true) 
        -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening 
            guiSetInputEnabled(true) 
    end 
) 

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