harryh Posted April 20, 2014 Share Posted April 20, 2014 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: Script: Vehicle mods list is in the meta file as g_vehmods and works. Section of Vehicle Mods List: Link to comment
abu5lf Posted April 20, 2014 Share Posted April 20, 2014 https://wiki.multitheftauto.com/wiki/Ge ... leUpgrades Link to comment
harryh Posted April 20, 2014 Author Share Posted April 20, 2014 Mate if you read the script you would see that I already have that function. But I do not understand how to use in for this coding situation. I need someone to look at the script and tell me where I'm going wrong Link to comment
Moderators Citizen Posted April 20, 2014 Moderators Share Posted April 20, 2014 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 ) Link to comment
harryh Posted April 21, 2014 Author Share Posted April 21, 2014 Edit: fixed the problem Link to comment
Moderators Citizen Posted April 21, 2014 Moderators Share Posted April 21, 2014 Edit: fixed the problem An error in my code ? If yes, then I would like to know what it was please Link to comment
harryh Posted April 22, 2014 Author Share Posted April 22, 2014 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 Citizen Posted April 22, 2014 Moderators Share Posted April 22, 2014 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 Link to comment
harryh Posted April 22, 2014 Author Share Posted April 22, 2014 Haha, its alright. Thanks for helping me Link to comment
harryh Posted April 23, 2014 Author Share Posted April 23, 2014 Citizen, I have a problem with the script but Im unsure why. For some reason upgrades for different cars show up in the sultan upgrades list. Link to comment
Moderators Citizen Posted April 24, 2014 Moderators Share Posted April 24, 2014 Probably because a vehicle upgrade can be available for more than one car ? Link to comment
harryh Posted April 24, 2014 Author Share Posted April 24, 2014 Probably because a vehicle upgrade can be available for more than one car ? Problem is its for jester car and it doesn't fit. addVehicleUpgrade outputs false when trying to add it. Link to comment
Moderators Citizen Posted April 24, 2014 Moderators Share Posted April 24, 2014 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
harryh Posted April 24, 2014 Author Share Posted April 24, 2014 Yeah, must be as it have cleared the gridlist and its still not working. 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