kieran Posted July 15, 2017 Share Posted July 15, 2017 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. Link to comment
Gordon_G Posted July 15, 2017 Share Posted July 15, 2017 (edited) Hello. Here, function click ( button, state, sx, sy, x, y, z, elem, gui ) gui will always return false, because the event onClientGUIClick return only 4 values string button, string state, int absoluteX, int absoluteY Just remove the gui arg in the 'if' check. Edited July 15, 2017 by Gordon_G 1 Link to comment
kieran Posted July 15, 2017 Author Share Posted July 15, 2017 Still doesn't work @Gordon_G Link to comment
Gordon_G Posted July 15, 2017 Share Posted July 15, 2017 (edited) Paste your actually code. Edited July 15, 2017 by Gordon_G Link to comment
kieran Posted July 15, 2017 Author Share Posted July 15, 2017 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
MIKI785 Posted July 15, 2017 Share Posted July 15, 2017 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. 1 Link to comment
kieran Posted July 15, 2017 Author Share Posted July 15, 2017 Thank you @MIKI785... And that is straight from wiki, here is the link, look at example 2 and the code I started the topic here with... Apparently it needs changed. Link to comment
MIKI785 Posted July 15, 2017 Share Posted July 15, 2017 The code on the wiki is fine actually, you added some extra bits that stopped it from working, you added conditions that could never pass. 1 Link to comment
kieran Posted July 15, 2017 Author Share Posted July 15, 2017 @MIKI785 I can assure you I copied and pasted it with 0 edits last night, my only explanation is they updated that page today... Anyway thanks, it works great now! Link to comment
MIKI785 Posted July 15, 2017 Share Posted July 15, 2017 Nope, the last edit was back in 2015 It doesn't matter, what matters is that it works now. 2 Link to comment
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