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