Jump to content

Need Help With Tables !


3B00DG4MER

Recommended Posts

Hi Guys i wanted to create a table :

it's make all upgrades of cars in the table and set them Available as False

then get available Upgrades of current car and remove the upgrade same as the available upgrades and put it in the table and set them available as True

Here is the function :

  
function upgrade() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if not vehicle then 
        return 
    end 
    local allUpgrades = {} 
    local slotName 
        for i=0, 16 do 
    local upgrade = getVehicleUpgradeOnSlot ( vehicle, i ) 
    local upgradeName = getVehicleUpgradeSlotName ( i ) 
            local avFind = table.find(allUpgrades, "av", false ) 
    local nameFind = table.find(allUpgrades, "slotName" ,upgradeName  ) 
    if nameFind == false then 
    table.insert(allUpgrades, { [ "av" ] = false, [ "slotName" ] = upgradeName}) 
    end 
    end 
    for i,upgrade in ipairs(getVehicleCompatibleUpgrades(vehicle)) do 
        slotName = getVehicleUpgradeSlotName(upgrade) 
        local nameFind = table.find(allUpgrades, "slotName" ,slotName  ) 
        local avFind = table.find(allUpgrades, "av", false ) 
        if (nameFind == true) and (avFind == true) then 
         
        table.remove(allUpgrades, i) 
        table.insert(allUpgrades, {[ "av" ] = true, [ "slotName" ] = slotName} ) 
        end 
    end 
     
    return allUpgrades 
end 
  
 function table.find(t, ...) 
    local args = { ... } 
    if #args == 0 then 
        for k,v in pairs(t) do 
            if v then 
                return k 
            end 
        end 
        return false 
    end 
     
    local value = table.remove(args) 
    if value == '[nil]' then 
        value = nil 
    end 
    for k,v in pairs(t) do 
        for i,index in ipairs(args) do 
            if type(index) == 'function' then 
                v = index(v) 
            else 
                if index == '[last]' then 
                    index = #v 
                end 
                v = v[index] 
            end 
        end 
        if v == value then 
            return k 
        end 
    end 
    return false 
end 
  

Link to comment

There's no problem in debugscript

i want to add all Upgrades of GTA in that table and set availability as false ["av"] = false, ["slotName"] = SlotName (here slot name of Upgrade)

then remove upgrades that Compatible the current car

and add it but set the availability as true ["av"] = true, ["slotName"] = slotName

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