Jump to content

[HELP] onVehicleExplode and respawnVehicle


..:D&G:..

Recommended Posts

Hello guys, I am making an insurance system, and I got some problems with the respawn function on which I use onVehicleExplode. The vehicle respawns, but it explodes, and it keeps respawning and exploding... Any ideas?

function onInsuredVehicleExplode() 
    local dbid = tonumber(getElementData(source, "dbid")) 
    if (dbid) then 
        local thePlayer = getVehicleOwnerByDBid(dbid) 
        if (getElementData(source, "insured") == 1) then 
            respawnVehicle(source) 
            fixVehicle(source) 
        else 
            destroyElement(source) 
        end 
    end 
end 
addEventHandler("onVehicleExplode", getRootElement(), onInsuredVehicleExplode) 

Thanks.

Link to comment

You should use that

function onInsuredVehicleDamage(loss) 
-- The source of this event is the vehicle that got damaged. 
    local dbid = tonumber(getElementData(source, "dbid")) 
    if (dbid) then 
        local thePlayer = getVehicleOwnerByDBid(dbid) -- why you used that idk 
        if (getElementData(source, "insured") == 1) then 
            if getElementHealth(source) < 250 then  
            -- if the health gets to 250 the vehicle gets on fire 
            fixVehicle(source) 
            end 
        end 
    end 
end 
addEventHandler("onVehicleDamage", getRootElement(), onInsuredVehicleDamage) 
  

Link to comment
You should use that
function onInsuredVehicleDamage(loss) 
-- The source of this event is the vehicle that got damaged. 
    local dbid = tonumber(getElementData(source, "dbid")) 
    if (dbid) then 
        local thePlayer = getVehicleOwnerByDBid(dbid) -- why you used that idk 
        if (getElementData(source, "insured") == 1) then 
            if getElementHealth(source) < 250 then  
            -- if the health gets to 250 the vehicle gets on fire 
            fixVehicle(source) 
            end 
        end 
    end 
end 
addEventHandler("onVehicleDamage", getRootElement(), onInsuredVehicleDamage) 
  

That has nothing to do with what I want... I want to respawn the vehicle when the vehicle explodes, I want it to respawn, that just fixes the vehicle when it gets under 250 health... Thanks for trying to help tho..

Link to comment

I tried this but the vehicle keeps exploding and respawning -.-

function testRespawn() 
    respawnVehicle(source) 
end 
  
function getElementsOnExplode() 
    setTimer ( testRespawn(source), 1000, 1 ) 
end 
addEventHandler("onVehicleExplode", getRootElement(), getElementsOnExplode) 
  

Link to comment
  • Moderators

Did you checked your debug? Because there were warnings, knowing just by looking at your code.

local respawnTimers = {} 
function testRespawn(vehicle) 
    respawnTimers[vehicle] = nil 
    respawnVehicle(vehicle) 
end 
  
function getElementsOnExplode() 
    if not respawnTimers[source] then 
        respawnTimers[source] = setTimer ( testRespawn, 1000, 1,source ) 
    end 
end 
addEventHandler("onVehicleExplode", root, getElementsOnExplode) 

Link to comment
It's a simple code even available on the wiki example:

https://wiki.multitheftauto.com/wiki/RespawnVehicle

function respawnExplodedVehicle() 
    setTimer(respawnVehicle, 5000, 1, source) 
end 
addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) 

Thanks for help everyone, but I managed to find a solution myself xD I forgot to say it in the topic as well (I used setTimer as TAPL did)

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