Jump to content

[Question] Gridlists


kieran

Recommended Posts

I noticed guiGridListGetItemText on wiki, I put it on my server and gave it a go but it doesn't really output to chat like it says it will :/ 

Example 2 on wiki

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", resourceRoot, createPlayerList )

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

Basically I am trying to use this as an example to teach myself how to use a similar system, the end result I am aiming for is using functions in that simple script to create a skin shop...  Once I get it to actually do something I will try that, but for now I am trying simple stuff. :D 

Link to comment

Here is what I thought you meant...

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, "Online Players", 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", resourceRoot, createPlayerList )

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

It should of worked in the first place, it was taken straight from wiki...

Link to comment

You said that you took it directly from the wiki, but I don't see such an example there, there are similar ones, but none exactly like what you have. Anyway, the problem is that onClientGUIClick only supports 'up' state (says so on the wiki). So in the second version (the one with the 'gui == true' removed, cause that's nonsense as well) change "down" to "up" and it should work then.

  • Like 1
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...