Xeno Posted January 30, 2012 Posted January 30, 2012 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.
Castillo Posted January 30, 2012 Posted January 30, 2012 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
Xeno Posted January 30, 2012 Author Posted January 30, 2012 Thank you, Could I replace outputChatBox("Hi ".. playerName) with setPlayerTeam(playerName, team1) -- I know I would have to do a triggerServerEvent ?
Castillo Posted January 30, 2012 Posted January 30, 2012 You'll need to use getPlayerFromName to get the player element from the name.
Xeno Posted January 30, 2012 Author Posted January 30, 2012 so in the client I would use local name = getPlayerFromName(playerName)
Castillo Posted January 30, 2012 Posted January 30, 2012 You can do: triggerServerEvent("setTeam",localPlayer,getPlayerFromName(playerName))
Xeno Posted January 31, 2012 Author Posted January 31, 2012 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)
Castillo Posted January 31, 2012 Posted January 31, 2012 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
Xeno Posted January 31, 2012 Author Posted January 31, 2012 Error at local row,col = guiGridListGetSelectedItem(playerList) -- Expected GUI element.
Castillo Posted January 31, 2012 Posted January 31, 2012 Copy it again, I forgot to remove the "local" in front of "playerList".
Xeno Posted January 31, 2012 Author Posted January 31, 2012 Ah sorry, i should of known of to fix that. Thanks for all your help.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now