Jump to content

Vehicle is not exploding


Xabi

Recommended Posts

Hi all, I've got few errors in my script and I need a little bit of help, thanks:

function checkVehicleDestroyed(loss) 
    local vehHealth = getElementHealth(source) 
    if vehHealth < 260 then 
        setElementHealth(source, 150) 
        setVehicleEngineState(source, false) 
        setElementData(source, "vehicles.vEngine", false) 
        setTimer(function() 
            blowVehicle(source) 
            addEventHandler("onVehicleExplode", source, sendVehicleToRespawn) 
        end, 10000, 1) 
    end 
end 
  
function makeVehicleDamageProof(thePlayer, seat) 
    if seat == 0 then 
        setVehicleDamageProof(source, true) 
    end 
end 
  
addEventHandler("onVehicleDamage", root, checkVehicleDestroyed) 
addEventHandler("onVehicleExit", root, makeVehicleDamageProof) 

So having that code, when I exit the vehicle it will never explode because of nil parameters (it just sets its health to 150 and stops the engine, but the timer gives a nil parameter warning with the source).

Thanks for the help.

Link to comment
function checkVehicleDestroyed(loss) 
    local vehHealth = getElementHealth(source) 
    if vehHealth < 260 then 
        setElementHealth(source, 150) 
        setVehicleEngineState(source, false) 
        setElementData(source, "vehicles.vEngine", false) 
        setTimer(function(source) -- add it here 
            blowVehicle(source) 
            addEventHandler("onVehicleExplode", source, sendVehicleToRespawn) 
        end, 10000, 1, source) -- pass the source into the timer 
    end 
end 
  
function makeVehicleDamageProof(thePlayer, seat) 
    if seat == 0 then 
        setVehicleDamageProof(source, true) 
    end 
end 
  
addEventHandler("onVehicleDamage", root, checkVehicleDestroyed) 
addEventHandler("onVehicleExit", root, makeVehicleDamageProof) 

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