Jump to content

[HELP] İPAİRS


Recommended Posts

[2018-07-24 18:53:45] ERROR: [gameplay]/Freeroam/fr_server.lua:351: bad argument #1 to 'ipairs' (table expected, got string)

I need help. Could you resolve this error?

 

function giveMeVehicles(vehicles)
    if type(vehicles) == 'number' then
        vehicles = { vehicles }
    end

    local px, py, pz, prot
    local radius = 3
    local playerVehicle = getPedOccupiedVehicle(source)
    if playerVehicle and isElement(playerVehicle) then
        px, py, pz = getElementPosition(playerVehicle)
        prot, prot, prot = getVehicleRotation(playerVehicle)
    else
        px, py, pz = getElementPosition(source)
        prot = getPedRotation(source)
    end
    local offsetRot = math.rad(prot)
    local vx = px + radius * math.cos(offsetRot)
    local vy = py + radius * math.sin(offsetRot)
    local vz = pz + 2
    local vrot = prot

    local vehicleList = g_PlayerData[source].vehicles
    local vehicle
    if ( not vehicles ) then return end
    for i,vehID in ipairs(vehicles) do
        if i > getOption('vehicles.maxperplayer') then
            break
        end
        if vehID < 400 or vehID > 611 then
            errMsg(vehID ..' is incorrect vehicle model', source)
        elseif not table.find(getOption('vehicles.disallowed'), vehID) then
            if #vehicleList >= getOption('vehicles.maxperplayer') then
                unloadVehicle(vehicleList[1])
            end
            vehicle = createVehicle(vehID, vx, vy, vz, 0, 0, vrot)
            if (not isElement(vehicle)) then return end
            setElementInterior(vehicle, getElementInterior(source))
            setElementDimension(vehicle, getElementDimension(source))
            table.insert(vehicleList, vehicle)
            g_VehicleData[vehicle] = { creator = source, timers = {} }
            if vehID == 464 then
                warpPedIntoVehicle(source, vehicle)
            elseif not g_Trailers[vehID] then
                if getOption('vehicles.idleexplode') then
                    g_VehicleData[vehicle].timers.fire = setTimer(commitArsonOnVehicle, getOption('vehicles.maxidletime'), 1, vehicle)
                end
                g_VehicleData[vehicle].timers.destroy = setTimer(unloadVehicle, getOption('vehicles.maxidletime') + (getOption('vehicles.idleexplode') and 10000 or 0), 1, vehicle)
            end
            vx = vx + 4
            vz = vz + 4
        else
            errMsg(getVehicleNameFromModel(vehID):gsub('y$', 'ie') .. 's are not allowed', source)
        end
    end
end

 

Link to comment

giveMeVehicles shouldn't be called with a string in the first parameter, but a table (or a number which gets converted to a table containing the number on lines 2–4). Seems like you tried using the vehicle name, while the code clearly expects vehID, that is, vehicle model ID, a number between 400 and 611 according to line 29.

  • Like 1
Link to comment
33 minutes ago, MrTasty said:

giveMeVehicles  ilk parametrede bir dize ile çağrılmamalıdır, ancak bir tablo (veya 2–4 satırlarındaki sayıyı içeren bir tabloya dönüştürülen bir sayı). Araç adını kullanmayı denediğiniz gibi, araç açıkça taşıt aracını , yani araç modeli ID'sini, satır 29'a göre 400 ve 611 arasında bir sayı bekler .

My English is not very good :(

 

Could you show me what to do ?

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