Jump to content

Help with car respawn


Recommended Posts

I made a function that respawn cars when they explode (For My Freeroam server)

Its simple, when the car explodes, it respawn one at the same place where it exploded.

But What I really want is to respawn car at their original spawn when they move (hit or drive) or are damaged

Here is my function:

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 onVehicleSpawn () 
    local x,y,z = getElementPosition (source) 
    setElementData (source,"posX",x) 
    setElementData (source,"posY",y) 
    setElementData (source,"posZ",z) 
end 
addEventHandler ("onVehicleExplode",getRootElement(),onVehicleSpawn) 
  
function onVehicleExplode () 
    setTimer( respawnVehicle, 5000, 1, source ) 
end 
addEventHandler("onVehicleExplode", getRootElement(), onVehicleExplode) 

Thanks

Link to comment

I'll recreate your script, it's too easy:

function getElementsOnExplode() 
        model = getElementModel ( source ) 
        x, y, z, rx, ry, rz = getElementPosition ( source ) 
        driver = getVehicleOccupant ( source ) 
        driverskin = getElementModel ( driver ) 
        setTimer ( spawnPlayerAfterExplode, 1000, 1 ) 
end 
addEventHandler("onVehicleExplode", getRootElement(), getElementsOnExplode) 
  
function spawnPlayerAfterExplode() 
        spawnPlayer ( driver, 0, 0, 0 ) 
        setElementModel ( driver, driverskin ) 
        newvehicle = createVehicle ( model, x, y, z, rx, ry, rz ) 
        warpPedIntoVehicle ( driver, newvehicle ) 
end 
  

Not tested, but that must work :)

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