Reezmi Posted April 2, 2016 Share Posted April 2, 2016 Hello. What functions should I use if i want a text to be sent on chatbox when an item is clicked on gridlist. How do I make it know what item is being clicked on list? Hope you get what I mean Here's what I tried but thats not it function clickingClothesShop () if(source == ClothesShopGuiGridlist) then -- Rick if(guiGridListGetItemText ( ClothesShopGuiGridlist, guiGridListGetSelectedItem ( ClothesShopGuiGridlist ), 1 )) then outputChatBox("rick click") elseif(guiGridListGetItemText ( ClothesShopGuiGridlist, guiGridListGetSelectedItem ( ClothesShopGuiGridlist ), 2 )) then outputChatBox("daryl click") end end end addEventHandler ( "onClientGUIClick", root, clickingClothesShop ) edit: and here is the code from gui ClothesShopGuiGridlist = guiCreateGridList(34, 77, 257, 295, false, ClothesShopGuiWindow) guiGridListAddColumn(ClothesShopGuiGridlist, "Clothes", 0.9) guiGridListAddRow(ClothesShopGuiGridlist) guiGridListAddRow(ClothesShopGuiGridlist) guiGridListSetItemText(ClothesShopGuiGridlist, 0, 1, "Rick ", false, false) guiGridListSetItemColor(ClothesShopGuiGridlist, 0, 1, 9, 139, 0, 255) guiGridListSetItemText(ClothesShopGuiGridlist, 1, 1, "Daryl", false, false) Link to comment
Walid Posted April 2, 2016 Share Posted April 2, 2016 try this function clickingClothesShop(button,state) if button == "left" and state == "up" then if(source == ClothesShopGuiGridlist) then local row, col = guiGridListGetSelectedItem(ClothesShopGuiGridlist) if ( row and col and row ~= -1 and col ~= -1 ) then local itemName = guiGridListGetItemText(ClothesShopGuiGridlist, row, col ) outputChatBox("Item name: "..itemName,255,255,0) end end end end Link to comment
Reezmi Posted April 2, 2016 Author Share Posted April 2, 2016 This does the trick. But what i want is how do i make it with if's? for seperate rows. Like for example if 'rick' row is pressed when the picture will change, but if 'daryl' when the picture will change to other again. Each row has its own func.. tried this but doesnt work if(guiGridListGetItemText(ClothesShopGuiGridlist, 0, col )) then outputChatBox("rick") --outputChatBox("Item name: "..itemName,255,255,0) elseif(guiGridListGetItemText(ClothesShopGuiGridlist, 1, col )) then outputChatBox("daryl") Link to comment
Walid Posted April 2, 2016 Share Posted April 2, 2016 what are talking about , try to explain your problem better or post some SS. Link to comment
Reezmi Posted April 2, 2016 Author Share Posted April 2, 2016 http://www.bildites.lv/images/u6z71v6xp5x9tykjh.jpg this is what i want, damn Im so bad at explaing I want to do it with "if's" Link to comment
Walid Posted April 2, 2016 Share Posted April 2, 2016 http://www.bildites.lv/images/u6z71v6xp5x9tykjh.jpgthis is what i want, damn Im so bad at explaing I want to do it with "if's" all what you need is : guiStaticImageLoadImage() so it must be like this : function clickingClothesShop(button,state) if button == "left" and state == "up" then if(source == ClothesShopGuiGridlist) then local row, col = guiGridListGetSelectedItem(ClothesShopGuiGridlist) if ( row and col and row ~= -1 and col ~= -1 ) then local itemName = guiGridListGetItemText(ClothesShopGuiGridlist, row, col ) guiStaticImageLoadImage(pictureGui,"path/"..itemName..".png") end end end end Link to comment
Reezmi Posted April 2, 2016 Author Share Posted April 2, 2016 I know how to change an image ;D. I just want to know how do i check what row have i clicked on example: if source == 'daryl text' / or 'daryl row' then function here.. elseif source == 'rick text' / or 'daryl row' then function here.. end Link to comment
Miika Posted April 2, 2016 Share Posted April 2, 2016 (edited) This is example, havent tested, post errors here I would do it with table, easier than adding else if every time: table { --text, img src --Just add row like this for more {"rick click", "img/rick.png"}; {"daryl click", "img/daryl.png"}; } function clickingClothesShop () if(source == ClothesShopGuiGridlist) then -- Rick local row, col = guiGridListGetSelectedItem(ClothesShopGuiGridlist) guiCreateStaticImage(20, 200, 100, 100, table[row+1][2], false) --Uses file location from table outputChatBox(table[row+1][1]) --Outputs "rick click" end end addEventHandler ( "onClientGUIClick", root, clickingClothesShop ) GUI: ClothesShopGuiGridlist = guiCreateGridList(34, 77, 257, 295, false, ClothesShopGuiWindow) guiGridListAddColumn(ClothesShopGuiGridlist, "Clothes", 0.9) for i=1,#table do guiGridListAddRow(ClothesShopGuiGridlist) guiGridListAddRow(ClothesShopGuiGridlist) guiGridListSetItemText(ClothesShopGuiGridlist, 0, 1, table[i][1], false, false) guiGridListSetItemColor(ClothesShopGuiGridlist, 0, 1, 9, 139, 0, 255) end Edited April 2, 2016 by Guest Link to comment
Walid Posted April 2, 2016 Share Posted April 2, 2016 ??? i already gave you the solution function clickingClothesShop(button,state) if button == "left" and state == "up" then if(source == ClothesShopGuiGridlist) then local row, col = guiGridListGetSelectedItem(ClothesShopGuiGridlist) if ( row and col and row ~= -1 and col ~= -1 ) then local itemName = guiGridListGetItemText(ClothesShopGuiGridlist, row, col ) if itemName == "bla bla" then -- put your code here elseif itemName == "bla bla2" then -- put your code here end end end end end Link to comment
Miika Posted April 2, 2016 Share Posted April 2, 2016 ??? i already gave you the solution I just gave faster method how i do all my gridlist things Link to comment
Reezmi Posted April 2, 2016 Author Share Posted April 2, 2016 @Walid strange i tried that before but it didnt work. Tried now and it works. I think I mistyped names. Thanks for your trouble 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