Try this
local respawnTime = 1000*60
addEventHandler("onPlayerWasted", getRootElement(), function()
local theVehicle = getPedOccupiedVehicle(source)
if theVehicle then
removePedFromVehicle(source)
setTimer(respawnPlayer,respawnTime,1,source,true) -- Here the player will respawn with a vehicle if he was in one
return --Here we abort the function | The function that comes below won't be executed.
end
setTimer(respawnPlayer,respawnTime,1,source,false) -- Here the player will resapwn WITHOUT a vehicle
end)
function respawnPlayer(thePlayer,inVehicle)
local x,y,z = 0,0,5 -- SET THE CORDINATES YOU WANT
if inVehicle then
spawnPlayer(thePlayer, x,y,z+5) -- We move the player a bit up to prevent collision with the vehicle
local theVehicle = createVehicle(411,x,y,z)
warpPedIntoVehicle(thePlayer,theVehicle)
return --Here we abort the function | The function that comes below won't be executed.
end
spawnPlayer(thePlayer, x,y,z+3) --Here we don't move the player 5 points up (Just try)
end
Im not sure if this is what you want. As far as I understand, you want that:
When a player dies, if he was in a vehicle then respawn it in a vehicle, otherwise not.
Im using a similar system with it, however, to prevent the creation of a new vehicle im storing them into a table and when the player respawn (In the case that he was a vehicle, restore the vheicle by fixing it ...etc)
Regards.