Jump to content

[HELP] onVehicleExplode and respawnVehicle


..:D&G:..

Recommended Posts

Posted

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.

Posted

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) 
  

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

Posted

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) 
  

  • Moderators
Posted

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) 

  • Moderators
Posted

Just for the info. With the normal code on wiki, you will get problems with helicopters and planes that don't stop exploding.

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