Jump to content

Vehicles cann not explode only burning


gerlachmax123

Recommended Posts

this script is mine script who you find in community :D

and link: https://community.multitheftauto.com/index.php?p= ... ls&id=6198

and i will help you!

--Client side

time1 = setTimer( 
function ( ) 
    for _, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do 
     if getElementHealth(vehicle) < 260 then 
     setVehicleDamageProof( vehicle, true) 
     time2 = setTimer( blowVehicle ( vehicle ), 500000, 0) 
 else 
     if getElementHealth(vehicle) >= 299 then 
     setVehicleDamageProof( vehicle, false) 
     killTimer ( time2 ) 
    end 
   end 
 end 
end, 
1000, 0) 

Link to comment
  • 2 weeks later...

It works:

time1 = setTimer( 
function ( ) 
    for _, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do 
     if getElementHealth(vehicle) < 260 then 
     setVehicleDamageProof( vehicle, true) 
     time2 = setTimer ( blowVehicle, 500000, 1, vehicle ) 
 else 
     if getElementHealth(vehicle) >= 299 then 
     setVehicleDamageProof( vehicle, false) 
     killTimer ( time2 ) 
    end 
   end 
 end 
end, 
1000, 0) 

Link to comment
time1 = setTimer( 
    function ( ) 
        for _, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do 
            if getElementHealth(vehicle) < 260 then 
                setVehicleDamageProof( vehicle, true) 
                time2 = setTimer( blowVehicle ( vehicle ), 500000, 1) 
            else 
                setVehicleDamageProof( vehicle, false) 
                killTimer ( time2 ) 
            end 
        end 
    end,1000, 0 
) 

Link to comment

All the above scripts are wrong. It will work but will throw errors after vehicles explode. Also, why keep creating new timer every second for the same vehicles? Think people. Create a table of timers and before you set new timer check if the timer is already set for this vehicle.

local vehTimers = { }; 
setTimer( 
    function ( ) 
        for _, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do 
            if getElementHealth(vehicle) < 260 then 
                setElementHealth( vehicle, 250 ); -- set vehicle health to "fire" health which is ~250 
                if not vehTimers[ vehicle ] then -- if we haven't set the timer 1 second earlier then: 
                    setVehicleDamageProof( vehicle, true) -- it only need to be called once so set the bulletproof property 
                    vehTimers[ vehicle ] = setTimer( blowVehicle, 300000, 1, vehicle); -- 5mins = 5 * 60sec = 300sec = 300000ms! It's NOT 500000ms 
                end 
            elseif vehTimers[ vehicle ] and isTimer( vehTimers[ vehicle ] ) then -- if we set a timer earlier but the vehicle was repaired within the 5mins then: 
                setVehicleDamageProof( vehicle, false) -- disable bulletproof property 
                killTimer( vehTimers[ vehicle ] ); -- kill the timer 
                vehTimers[ vehicle ] = nil; -- remove the variable from the memory since we killed the timer and it's no longer timer variable 
            end 
        end 
    end,1000, 0 
) 

Haven't tested but from "rubber duck" debugging it should work just fine without any error/warning messages.

Link to comment
All the above scripts are wrong. It will work but will throw errors after vehicles explode. Also, why keep creating new timer every second for the same vehicles? Think people. Create a table of timers and before you set new timer check if the timer is already set for this vehicle.
local vehTimers = { }; 
setTimer( 
    function ( ) 
        for _, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do 
            if getElementHealth(vehicle) < 260 then 
                setElementHealth( vehicle, 250 ); -- set vehicle health to "fire" health which is ~250 
                if not vehTimers[ vehicle ] then -- if we haven't set the timer 1 second earlier then: 
                    setVehicleDamageProof( vehicle, true) -- it only need to be called once so set the bulletproof property 
                    vehTimers[ vehicle ] = setTimer( blowVehicle, 300000, 1, vehicle); -- 5mins = 5 * 60sec = 300sec = 300000ms! It's NOT 500000ms 
                end 
            elseif vehTimers[ vehicle ] and isTimer( vehTimers[ vehicle ] ) then -- if we set a timer earlier but the vehicle was repaired within the 5mins then: 
                setVehicleDamageProof( vehicle, false) -- disable bulletproof property 
                killTimer( vehTimers[ vehicle ] ); -- kill the timer 
                vehTimers[ vehicle ] = nil; -- remove the variable from the memory since we killed the timer and it's no longer timer variable 
            end 
        end 
    end,1000, 0 
) 

Haven't tested but from "rubber duck" debugging it should work just fine without any error/warning messages.

Why use Timer? We can use onVehicleDamage to trigger this function am I right 50p? :roll:

Link to comment
  • 4 years later...

Too late, but if someone want this simple script:

 

local function checkVehicleHPCollision()
	if getVehicleOccupant(source) then
		if getElementHealth(source) <= 250 then
			setVehicleDamageProof(source, true)
		else
			setVehicleDamageProof(source, false)
		end
	end
end

addEventHandler("onClientVehicleCollision", getRootElement(), checkVehicleHPCollision)

local function checkVehicleHPDamage()
	if getVehicleOccupant(source) then
		if getElementHealth(source) <= 250 then
			setVehicleDamageProof(source, true)
		end
	end
end

addEventHandler("onClientVehicleDamage", getRootElement(), checkVehicleHPDamage)

 

Should work better than loop on every vehicle

Edited by MrDadosz
Link to comment
addEventHandler("onClientVehicleDamage", getRootElement(), function()
	setState = getElementHealth(source) <= 250 and setVehicleDamageProof(source, true) or setVehicleDamageProof(source, false)
end)

Totally unnecessary code removed.

Edited by NeXuS™
Link to comment

You can't use onClientVehicleDamage, proof: 

onClientVehicleCollision:

onClientVehicleCollision will work but it may cause FPS drop  for client. 

 

So this should work:

 

addEventHandler("onClientVehicleCollision", getRootElement(), function()
	setState = getElementHealth(source) <= 250 and setVehicleDamageProof(source, true) or setVehicleDamageProof(source, false)
end)

addEventHandler("onClientVehicleDamage", getRootElement(), function() -- shooting to vehicles etc.
	setState = getElementHealth(source) <= 250 and setVehicleDamageProof(source, true)
end)

 

Link to comment

I've tested it on my server, and it worked fine.

And you do realize that the function gets called, meaning that you have something wrong in your code, as mine works aswell.

addEventHandler("onClientVehicleDamage", getRootElement(), function(_, _, vehDmg)
	setState = getElementHealth(source)-vehDmg <= 250 and setVehicleDamageProof(source, true) or false
	outputChatBox("isProof: " .. tostring(isVehicleDamageProof(source)))
end)

Done.

Edited by NeXuS™
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...