Jump to content

HELP TABLE USE


Fanbox

Recommended Posts

how use its table
vehicleTable = {
{id = 422,stats = {4,1,1,1,1,0.25,50},pos = {
  {2433.3086, -1674.3926, 14.004364,0,0,0,30},
  {-2519.2705, -603.21094, 132.91457,0,0,0,30},

  }
},
}
 for _,data in ipairs(vehicleTable) do
  veh = createVehicle(data.id,data.pos[1][1],data.pos[1][2],data.pos[1][3],data.pos[1][4],data.pos[1][5],data.pos[1][6])
end
spwan only one car
how use spawns 1 and 2 cars ( all table) TY

Link to comment

Ipairs loops through all the rows of your table, with your code you only told the loop to create a vehicle for row 1 in your table. I remade the code my way, hope it'll help.

 

vehicleList = {
[1] = {422, -2409.80029, -598.06927, 132.64844},
[2] = {422, -2425.80981, -602.30896, 132.56250},
}

function spawnCar()
 for i, v in ipairs(vehicleList) do
  veh = createVehicle(vehicleList[i][1], vehicleList[i][2], vehicleList[i][3], vehicleList[i][4])
end
end

addCommandHandler("spawncarz", spawnCar)

i = index, meaning that when the loop starts it'll first go through everything in the first row of the table (this time it's [1], then it'll go through everything in the second row [2], etc. That's why I'm using vehicleList[(i)], because it'll first be 1, and when the loop completes the first section in the table, it'll become 2.

Edited by Forthwind
Link to comment
2 hours ago, Forthwind said:

Ipairs loops through all the rows of your table, with your code you only told the loop to create a vehicle for row 1 in your table. I remade the code my way, hope it'll help.

 


vehicleList = {
[1] = {422, -2409.80029, -598.06927, 132.64844},
[2] = {422, -2425.80981, -602.30896, 132.56250},
}

function spawnCar()
 for i, v in ipairs(vehicleList) do
  veh = createVehicle(vehicleList[i][1], vehicleList[i][2], vehicleList[i][3], vehicleList[i][4])
end
end

addCommandHandler("spawncarz", spawnCar)

i = index, meaning that when the loop starts it'll first go through everything in the first row of the table (this time it's [1], then it'll go through everything in the second row [2], etc. That's why I'm using vehicleList[(i)], because it'll first be 1, and when the loop completes the first section in the table, it'll become 2.

TY bu thow use it table 

vehicleTable = {
{id = 422,stats = {4,1,1,1,1,0.25,50},pos = {
  {2433.3086, -1674.3926, 14.004364,0,0,0,30},
  {-2519.2705, -603.21094, 132.91457,0,0,0,30},

  }
},
}

Link to comment
  • Discord Moderators

Try to NOT use numeric indexes, as you will get lost, always try to use worlds as index, ex.: tbl.someIndex, but here you go:

local vehTypes = {
    [442] = {--the index is the vehid
       stats = {4 ,1 ,1 ,1 , 1,0.25 ,50},--> i dont know what this table is, so i use numeric index.
       pos = {
             {x = 2433.3086, y = -1674.3926, z = 14.004364, rx = 0, ry = 0, rz = 0, 30},
             {x = -2519.2705, y = -603.21094, z = 132.91457, rx = 0, ry = 0, rz = 0, 30},--> i donw know that the last thing is for.
       }
    }      
}  

for vehModellId, vehTypeDatas in pairs(vehTypes) do
    for _, pos in pairs(vehTypeDatas.pos) do
        createVehicle(vehModellId, pos.x, pos.y, pos.z, pos.rx, pos.ry, pos.rz)
    end
end

Or with the table you provided:

vehicleTable = {
    {
        id = 422,
        stats = {4,1,1,1,1,0.25,50},
        pos = {
            {2433.3086, -1674.3926, 14.004364,0,0,0,30},
            {-2519.2705, -603.21094, 132.91457,0,0,0,30},
        }
    },
}

for _, vehTypeData in pairs(vehicleTable) do
    for _,pos in pairs(vehTypeData.pos) do
        createVehicle(vehTypeData.id, pos[1], pos[2], pos[3], pos[4], pos[5], pos[6])
    end
end

 

Edited by Pirulax
added another ex.
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...