Jump to content

Vehicle Respawning problem


Recommended Posts

Posted

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?

Posted (edited)

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
Posted
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?

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

Posted

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  

Posted

and it still wont work in DP2

for theKey,theVehicle in getElementsByType ( "vehicle" ) do <---------- Line 95      
     toggleVehicleRespawn ( theVehicle, true ) 
     setVehicleRespawnDelay ( theVehicle, 5000 )     
end 

ERROR: attemt to call a table value

Posted
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)

Posted

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.

Posted

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 
  

Posted

er, maybe "for theKey,theVehicle in ipairs(cars) do" should be "for theKey, theVehicle in ipairs(cars) do"

(space after comma). I dunno though, looks like it should work = /

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