Jump to content

Gridlists.


Xeno

Recommended Posts

So yeah, I've never done GUI gridlists, so I would like some help...

Here is a wiki example of a guiGridList with a table of players on it (Edited abit)

function createPlayerList () 
    --Create the grid list element 
    local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Do", 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, player in ipairs(getElementsByType("player")) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
    end 
end 

What I'm trying to achieve is, when the player presses "button" it outputs into the chat box "hi"

I'm guessing you gotta use GuiGridListGetSelectedItems but i have no idea where to use it..

I would appreciate if you guys could help me,

Xeno.

Link to comment
function createPlayerList () 
    --Create the grid list element 
    playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Do", true ) 
    addEventHandler("onClientGUIClick",button,onButtonClick,false) 
    --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, player in ipairs(getElementsByType("player")) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
    end 
end 
  
function onButtonClick() 
    local row,col = guiGridListGetSelectedItem(playerList) 
    if (row and col and row ~= -1 and col ~= -1) then 
        local playerName = guiGridListGetItemText(playerList, row, 1) 
        outputChatBox("Hi ".. playerName) 
    end 
end 

Link to comment

Sorry to bring back an old topic, but this does not work... It won't output "hi" into the chat box when I select my name, here is the code:

function createPlayerList (player) 
    --Create the grid list element 
    local playerList = guiCreateGridList ( 0.60, 0.10, 0.15, 0.60, true ) 
    button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Do", 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, player in ipairs(getElementsByType("player")) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
    end 
end 
addCommandHandler("show",createPlayerList) 
  
addEventHandler("onClientGUIClick",button, 
function () 
    local row,col = guiGridListGetSelectedItem(playerList) 
    if (row and col and row ~= -1 and col ~= -1) then 
        local playerName = guiGridListGetItemText(playerList, row, 1) 
        outputChatBox("Hi ") 
    end 
end, false) 

Link to comment
function createPlayerList (player) 
    --Create the grid list element 
    playerList = guiCreateGridList ( 0.60, 0.10, 0.15, 0.60, true ) 
    button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Do", true ) 
    addEventHandler("onClientGUIClick",button,onButtonClick,false) 
    --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, player in ipairs(getElementsByType("player")) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
    end 
end 
addCommandHandler("show",createPlayerList) 
  
  
function onButtonClick() 
    local row,col = guiGridListGetSelectedItem(playerList) 
    if (row and col and row ~= -1 and col ~= -1) then 
        local playerName = guiGridListGetItemText(playerList, row, 1) 
        outputChatBox("Hi ") 
    end 
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...