gerlachmax123 Posted February 8, 2013 Share Posted February 8, 2013 Vehicle must not explode, only burning In addition there is the resource: https://community.multitheftauto.com/index.php?p=r…details&id=6198 However, because I can change nothing because its .LUAC The vehicle should burning 5 minutes. After the 5 minutes the vehicle should explode.... Link to comment
K4stic Posted February 8, 2013 Share Posted February 8, 2013 this script is mine script who you find in community 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
gerlachmax123 Posted February 22, 2013 Author Share Posted February 22, 2013 If the vehicle have = 259 the vehicle will blow immediately... Link to comment
gerlachmax123 Posted February 22, 2013 Author Share Posted February 22, 2013 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
PaiN^ Posted February 22, 2013 Share Posted February 22, 2013 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
50p Posted February 22, 2013 Share Posted February 22, 2013 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
gokalpfirat Posted February 22, 2013 Share Posted February 22, 2013 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? Link to comment
50p Posted February 22, 2013 Share Posted February 22, 2013 Yes, you can. Skip the entire loop and use source instead of vehicle. Link to comment
gokalpfirat Posted February 22, 2013 Share Posted February 22, 2013 Because setTimer with every 1 sec. makes lag if there is lot player. Link to comment
MrDadosz Posted August 8, 2017 Share Posted August 8, 2017 (edited) 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 August 8, 2017 by MrDadosz Link to comment
NeXuS™ Posted August 8, 2017 Share Posted August 8, 2017 (edited) addEventHandler("onClientVehicleDamage", getRootElement(), function() setState = getElementHealth(source) <= 250 and setVehicleDamageProof(source, true) or setVehicleDamageProof(source, false) end) Totally unnecessary code removed. Edited August 8, 2017 by NeXuS™ Link to comment
MrDadosz Posted August 8, 2017 Share Posted August 8, 2017 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
NeXuS™ Posted August 8, 2017 Share Posted August 8, 2017 (edited) 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 August 8, 2017 by NeXuS™ Link to comment
Recommended Posts