Jump to content

Vehicle Respawning problem


Recommended Posts

hi, look at my code, my vehicles wont respawn when they die

for theKey,theVehicle in getElementsByType ( "vehicle" ) do 
local rand1  = randInt(50,255) 
local rand2  = randInt(50,255) 
local rand3  = randInt(50,255) 
local rand4  = randInt(50,255) 
id = getVehicleID ( theVehicle ) 
setVehicleColor ( id, rand1, rand2, rand3, rand4 ) 
toggleVehicleRespawn ( id, true ) 
setVehicleRespawnDelay ( id, 5000 ) 
end  

the setvehiclecolor works, the cars will be colored randomly, but they aint respawning

can someone help me with this?

Link to comment

Simbad ik denk niet dat je hier veel aan hebt maar heb je er wat aan ? :P

function respawnVehicle( vehicle ) 
    spawnVehicle ( vehicle, getElementData( vehicle, "posX" ), getElementData( vehicle, "posY" ), getElementData( vehicle, "posZ" ), getElementData( vehicle, "rotX" ), getElementData( vehicle, "rotY" ), getElementData( vehicle, "rotZ" ) ) 
end 
  
function onVehicleExplode () 
    setTimer( respawnVehicle, 10000, 1, source ) 
end 

I will translate i'm sorry:

Simbad i don't think you have something with this but is this something for you? :P

Edited by Guest
Link to comment
Simbad aan mij zal je niet veel hebben ik ben niet zo snugger maar :P heb je hier wat aan?

function respawnVehicle( vehicle ) 
    spawnVehicle ( vehicle, getElementData( vehicle, "posX" ), getElementData( vehicle, "posY" ), getElementData( vehicle, "posZ" ), getElementData( vehicle, "rotX" ), getElementData( vehicle, "rotY" ), getElementData( vehicle, "rotZ" ) ) 
end 
  
function onVehicleExplode () 
    setTimer( respawnVehicle, 10000, 1, source ) 
end 

eh, English?

Link to comment
Simbad aan mij zal je niet veel hebben ik ben niet zo snugger maar :P heb je hier wat aan?

function respawnVehicle( vehicle ) 
    spawnVehicle ( vehicle, getElementData( vehicle, "posX" ), getElementData( vehicle, "posY" ), getElementData( vehicle, "posZ" ), getElementData( vehicle, "rotX" ), getElementData( vehicle, "rotY" ), getElementData( vehicle, "rotZ" ) ) 
end 
  
function onVehicleExplode () 
    setTimer( respawnVehicle, 10000, 1, source ) 
end 

eh, English?

I'm sorry i will translate see my edit.

Link to comment

This should work. You should use the vehicle object to call the functions, not the model ID. getVehicleID() returns the model ID.

And indentation is priceless, especially when you need others to understand it :P

for theKey,theVehicle in getElementsByType ( "vehicle" ) do 
    local rand1  = randInt(50,255) 
    local rand2  = randInt(50,255) 
    local rand3  = randInt(50,255) 
    local rand4  = randInt(50,255) 
     
    setVehicleColor ( theVehicle, rand1, rand2, rand3, rand4 ) 
    toggleVehicleRespawn ( theVehicle, true ) 
    setVehicleRespawnDelay ( theVehicle, 5000 ) 
end  

Link to comment
This should work. You should use the vehicle object to call the functions, not the model ID. getVehicleID() returns the model ID.

And indentation is priceless, especially when you need others to understand it :P

for theKey,theVehicle in getElementsByType ( "vehicle" ) do 
    local rand1  = randInt(50,255) 
    local rand2  = randInt(50,255) 
    local rand3  = randInt(50,255) 
    local rand4  = randInt(50,255) 
     
    setVehicleColor ( theVehicle, rand1, rand2, rand3, rand4 ) 
    toggleVehicleRespawn ( theVehicle, true ) 
    setVehicleRespawnDelay ( theVehicle, 5000 ) 
end  

Uhm, this isn't really about the problem but rand1 is a random color right? but arent car colors codes between 0 and 126?

or is it something else... (im just wondering)

Link to comment

I'm sorry, I usually only code for Garry's Mod, were all colors are using the 255 RGB scale, I didn't really know anything about the way MTA worked at the time, that could very well be the problem.

Link to comment

Try this code

  
local cars = getElementsByType ( "vehicle" ) 
for theKey,theVehicle in ipairs(cars) do 
    local rand1  = randInt(0,126) 
    local rand2  = randInt(0,126) 
    local rand3  = randInt(0,126) 
    local rand4  = randInt(0,126) 
     
    setVehicleColor ( theVehicle, rand1, rand2, rand3, rand4 ) 
    toggleVehicleRespawn ( theVehicle, true ) 
    setVehicleRespawnDelay ( theVehicle, 5000 ) 
end 
  

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