Jump to content

Loop is not executed


Mishqutin

Recommended Posts

So I am making a vehicle shop system. I want some vehicles to have changed handling when they spawn. There's a problem, 'cause a 'for loop' that sets handlings isn't executed. I don't know what could cause this. Here's the code:

local vehSale = {}
vehSale["premier"] = {426, 2000, {}}
vehSale["blista-compact"] = {496, 2400, {}}

hdl_blista_compact_rwd = {}
hdl_blista_compact_rwd["driveType"] = "rwd"
hdl_blista_compact_rwd["mass"] = 1040
vehSale["blista-compact-rwd"] = {496, 2800, hdl_blista_compact_rwd}

hdl_blista_sport = {}
hdl_blista_sport["driveType"] = "rwd"
hdl_blista_sport["mass"] = 1100
hdl_blista_sport["engineAcceleration"] = 12.8
hdl_blista_sport["engineInertia"] = 4
hdl_blista_sport["collisionDamageMultiplier"] = 0.55
hdl_blista_sport["steeringLock"] = 35
vehSale["blista-sport"] = {496, 4500, hdl_blista_sport}

function buyVehicle(source, cmdName, vName)
    if not vehSale[vName] then
        outputChatBox("There is no such vehicle for sale", source)
        return false
    end
    
    if getPlayerMoney(source) < vehSale[vName][2] then
        outputChatBox("You don't have money for that", source)
        return false
    end
    
    local veh = createVehicle(vehSale[vName][1], 0, 0, 0)
    spawnVehicle(veh, -1706, 13, 5)
    
    for k, v in ipairs(vehSale[vName][3]) do
        print(k)
        
        setVehicleHandling(veh, k, v)
    end
    setPlayerMoney(source, getPlayerMoney(source)-vehSale[vName][2])
    outputChatBox("Vehicle bought", source)
end
addCommandHandler("buy", buyVehicle)

So I made a table (vehSale) where I put all avaliable cars. Under key premier at 1st index is vehicle ID, 2nd - price, 3rd - Handlings to change.

I wrote a function that lets players buy vehicles. It's named buyVehicle(). First it checks if vehicle is avaliable and if player can afford it. Next it spawns vehicle at San Fierro docks and then applies handling. And that part of code doesn't work. After loop subtracts player money and outputs "Vehicle bought". Anything but that loop does work. I tried this code at the beggining of program:

for k, v in ipairs(getOriginalHanling(496)) do
  print(k)
  print(v)
end

And this doesn't work too.

Man, f*ck this. I've just changed ipairs() to pairs() and ANYTHING is WORKING. Lol

Edited by Mishqutin
Link to comment
  • Scripting Moderators

ipairs : the index of table from 1 to ∞ which can only be continuous.

pairs: the index of table can be everything.(even it is continuous)

Edited by thisdp
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...