Jump to content

Get Selected GridList Item and compare it to a table


harryh

Recommended Posts

Well I need it to get the selected item from the gridlist then look at a table and get the certain ID. It must then add use that ID as addVehicleUpgrade ID for the vehicle the player is it. I need some guidance on how I am to do this.

GUI:

nMCgfaQ.png

Vehicle Mods Table:

0irqpJs.png

Here is what I have so far. However, it doesn't work. :lol:

function buymod() 
    local bSelect = guiGridListGetSelectedItem(bodygrid)  
    outputChatBox(bSelect) 
    local iData = guiGridListGetItemData(bodygrid, bSelect, bSelect) 
    outputChatBox(iData) 
end 

Link to comment
function buymod ( ) 
    local row, col = guiGridListGetSelectedItem ( bodygrid ) -- Get the selected item. 
    if ( row and col and row ~= -1 and col ~= -1 ) then -- If there is a selected item.. 
        local iData = guiGridListGetItemText ( bodygrid, row, 1 ) -- Get the text from the first column. 
        outputChatBox ( iData ) 
        for _, upg in ipairs ( vehicleupgrades ) do -- Loop the "vehicleupgrades" table. 
            if ( upg [ 1 ] == iData ) then -- If the upgrade name matches the one selected.. 
                outputChatBox ( "Cost: ".. tostring ( upg [ 2 ] ) ..": UPG ID: ".. tostring ( upg [ 3 ] ) ) -- Output the cost and upgrade ID. 
                break -- Stop the loop. 
            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...