Jump to content

Defining multiple elements/cars at the same time?


kevin433

Recommended Posts

Posted

Hi,

I'm currently working on my Vehicle system. Now I want to spawn multiple cars at the same time, and that's working, but I want to set the Vehicle Color for each, and I'm using a for loop. How can I do this? That's how my code i currently looking:

function createCar()
local resultvehicle = executeSQLSelect("Vehicles","*")
if(#resultvehicle == 0) then	 
 
else
for i = 1, 2 do
createVehicle(resultvehicle[i].ModelID, resultvehicle[i].PosX,resultvehicle[i].PosY,resultvehicle[i].PosZ)
end
end
end
addCommandHandler("createcar", createCar)

Posted
for i = 1, 2 do
local tempVeh = createVehicle(resultvehicle[i].ModelID, resultvehicle[i].PosX,resultvehicle[i].PosY,resultvehicle[i].PosZ)
setVehicleColor( tempVeh, 126, 126 );
end

Posted
Thanks 50p! :D

BTW: Is the loop now re-defining "tempVeh" every time it runs through? Does it work this way?

Yup, every time it goes through tempVeh will get the element data of the newly created vehicle.

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