Fanbox Posted March 1, 2018 Share Posted March 1, 2018 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]) endspwan only one car how use spawns 1 and 2 cars ( all table) TY Link to comment
Forthwind Posted March 1, 2018 Share Posted March 1, 2018 (edited) 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 March 1, 2018 by Forthwind Link to comment
NeXuS™ Posted March 1, 2018 Share Posted March 1, 2018 @Forthwind or you could just use v[1], v[2], etc. 1 Link to comment
Fanbox Posted March 1, 2018 Author Share Posted March 1, 2018 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 Pirulax Posted March 8, 2018 Discord Moderators Share Posted March 8, 2018 (edited) 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 March 8, 2018 by Pirulax added another ex. 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