Jump to content

Checking if vehicle upgrades are compatiable


harryh

Recommended Posts

Well, I would like for the script to get compatible vehicle upgrades from a list. Which I have typed up and see if they fit the vehicle. If they fit the vehicle they will show up in the GUI Box. If not they will not show up. What happens is that the mods show up in the list but it shows all of the mods in the list not just the compatible ones like it suppose to.

GUI:

vL3X4fJ.png

Script:

WoypyMf.png

Vehicle mods list is in the meta file as g_vehmods and works.

Section of Vehicle Mods List:

0irqpJs.png

Link to comment
  • Moderators

Please paste the code between [­­­code=lua][/code] tags next time, because I had to rewrite it, so you are wasting the time of guys who want to help you.

That being said, here is the code you were looking for, please take time to read and understand the comments:

bodymodstab = guiCreateTab("Body Mods", tabpan) 
bodygrid = guiCreateGridList(11, 15, 422, 213, false, bodymodstab) 
local bname = guiGridListAddColumn(bodygrid, "Body Mod Name", 0.5) 
local bprice = guiGridListAddColumn(bodygrid, "Price", 0.4) 
local vCompUpgrades = getVehicleCompatibleUpgrades(element) 
for key, value in ipairs(vCompUpgrades) do -- for all compatibles upgrades ... 
    local upgradeDetails = getVehcileUpgradeDetails(value) -- get the upgrade details 
    if upgradeDetails then --if we got the the name (if we didn't get false or nil) 
        local row = guiGridListAddRow(bodygrid) 
        guiGridListSetItemText(bodygrid, row, bname, upgradeDetails[1], false, false) 
        guiGridListSetItemText(bodygrid, row, bname, upgradeDetails[2], false, true) --true for the ability to sort the grid per price 
    else 
        --Problem that should never happen if the vehicleuprades is complete, but if it's not, we will see it in the client logs. 
        outputDebugString("[ERROR] Couldn't get a vehicle upgrade name (" + tostring(value) + ")", 1) 
    end 
end 
  
--add this function somewhere in your script file 
function getVehcileUpgradeDetails( upgradeId ) 
    for k, i in ipairs(vehicleuprades) do --iterate over the vehicleuprades table 
        if i[3] == upgradeId then --if the id (3rd column) in the current row is equal to upgradeId then 
            return i --return the entire row of that upgrade (so the name, the price and the id) 
        end 
    end -- go to the next row or go to the line below if it was the last row. 
    return nil --If the code goes here, it means he didn't found, so we return nil 
end 

(I'm in a good day, but I almost put a screenshot instead to let you see how it can be annoying to rewrite code instead of a simple copy paste :lol: )

Link to comment

Your Error: Perform arthimetic with string value or something.

Before:

outputDebugString("[ERROR] Couldn't get a vehicle upgrade name (" + tostring(value) + ")", 1) 

Fix:

outputDebugString("[ERROR] Couldn't get a vehicle upgrade name (" .. tostring(value) ..")", 1) 

My Error: Element was not the vehicle but the player inside

Fix: Sent over thePlayer Arg. and then used get getPedOccupiedVehicle to get the compatible upgrades.

Link to comment
  • Moderators
Your Error: Perform arthimetic with string value or something.

Before:

outputDebugString("[ERROR] Couldn't get a vehicle upgrade name (" + tostring(value) + ")", 1) 

Fix:

outputDebugString("[ERROR] Couldn't get a vehicle upgrade name (" .. tostring(value) ..")", 1) 

Haha yeah, too much Java and C# these days sorry about that mistake :lol:

Link to comment
  • Moderators

Did you go in the shop with other cars before trying with jester ?

I mean, if you restart the resource and then try directly with the jester, does it show the exact same list ?

If yes, then it's a bug coming from the getVehicleCompatibleUpgrades function.

If not, then it's just that you have to clear the gridlist before executing the loop that fill the list (guiGridListClear).

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