Jump to content

Respawn vehicle placed in Map Editor.


S.Eagle

Recommended Posts

I've been searching, but could't find anything.

So here's my what I have:

I've placed a vehicle.

<vehicle id="VehicleS1" paintjob="3" model="411" plate="S EAGLE" interior="0" dimension="0" color="3,126,0,0" posX="1512.2879638672" posY="-1473.4406738281" posZ="12.349999427795" rotX="0" rotY="0" rotZ="246.13220214844" upgrades="1008,1080" />

But how can I make it respawn?

I know how to make vehicles respawn that are created using the createVehicle lua function, but not vehicles that are created with the Map Editor.

Thanks in advance.

S

Link to comment

Extended from mapmanager example:

function loadMap(startedMap)
   mapRoot = getResourceRootElement(startedMap)
local mapVehicles =  getElementsByType ( "vehicle", mapRoot )  --start at Map Root Element, we're not interested in other vehicles possibly existing
for _, veh in pairs ( mapVehicles ) do
toggleVehicleRespawn ( veh, true )
setVehicleRespawnDelay ( veh, 30000 )  --delay in milliseconds, this is 30 seconds
end
end
 
addEventHandler("onGamemodeMapStart", getRootElement(), loadMap)

Link to comment
Extended from mapmanager example:
function loadMap(startedMap)
   mapRoot = getResourceRootElement(startedMap)
local mapVehicles =  getElementsByType ( "vehicle", mapRoot )  --start at Map Root Element, we're not interested in other vehicles possibly existing
for _, veh in pairs ( mapVehicles ) do
toggleVehicleRespawn ( veh, true )
setVehicleRespawnDelay ( veh, 30000 )  --delay in milliseconds, this is 30 seconds
end
end
 
addEventHandler("onGamemodeMapStart", getRootElement(), loadMap)

Something is not working yet.

Is there anything I should change that I am not seeing?

Link to comment
Extended from mapmanager example:
function loadMap(startedMap)
   mapRoot = getResourceRootElement(startedMap)
local mapVehicles =  getElementsByType ( "vehicle", mapRoot )  --start at Map Root Element, we're not interested in other vehicles possibly existing
for _, veh in pairs ( mapVehicles ) do
toggleVehicleRespawn ( veh, true )
setVehicleRespawnDelay ( veh, 30000 )  --delay in milliseconds, this is 30 seconds
end
end
 
addEventHandler("onGamemodeMapStart", getRootElement(), loadMap)

Either toggleVehicleRespawn or setVehicleRespawnDelay doesn't work properly.

The best way to respawn vehicle after it explodes is to set a timer which will respawn the vehicle in onVehicleExplode event.

https://wiki.multitheftauto.com/wiki/RespawnVehicle (the example shows exactly what I described)

Link to comment
addEventHandler( "onVehicleExplode", getRootElement( ),
function( )
local parent = getElementParent( source )
if getElementType( parent ) == "map" and getElementID( parent ) ~= "dynamic" then
local parentRes = getElementParent( parent )
if parentRes == getResourceRootElement( getThisResource( ) ) then
setTimer( respawnVehicle, 5000, 1, source )
else
setTimer( destroyElement, 5000, 1, source )
end
else
setTimer( destroyElement, 5000, 1, source )
end
end
)

THIS IS NOT WRITTEN BY ME! This is 50p's script and all credits for him. I found this from one topic (cant remember/find) But this is anyway scripted by 50p's ;)

It's anyway fully working, dunno why 50p didn't put this into this topic?

Link to comment
....

It's anyway fully working, dunno why 50p didn't put this into this topic?

Because there are people like you who know how to use "Search" feature! lol

Well, I'm not even using this script in my servers. I just found it something like half year ago... :/

EDIT: I know you hate me, because EUHM... I was stupid, I'm now learned much about lua, just forget those old times.

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