Jump to content

show to text when clicking on gridlist item


Reezmi

Recommended Posts

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 :roll:

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

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

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
http://www.bildites.lv/images/u6z71v6xp5x9tykjh.jpg

this is what i want, damn Im so bad at explaing :D 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

I know how to change an image ;D. I just want to know how do i check what row have i clicked on :D

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

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 by Guest
Link to comment

??? 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

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...