Hiding Posted May 1, 2023 Share Posted May 1, 2023 Hello, my question is how to detect if my vehicle's health is reaching 0? if so then write in the chat that "your vehicle's HP is 0". Link to comment
Doongogar Posted May 1, 2023 Share Posted May 1, 2023 onVehicleDamage getElementHealth Link to comment
Hiding Posted May 1, 2023 Author Share Posted May 1, 2023 (edited) I tried with onClientVehicleDamage, but it only triggered when my car was exploded. I need the localPlayer vehicle's health before the explosion. Edited May 1, 2023 by Hiding Link to comment
FLUSHBICEPS Posted May 1, 2023 Share Posted May 1, 2023 the event triggers because u dont use the loss parameter to check the amount of health the vehicle lost in onClientVehicleDamage addEventHandler("onClientVehicleDamage", root, function(loss) local vehHP = getElementHealth(source) if currentHealth - loss <= 0 then end end) 1 Link to comment
Doongogar Posted May 1, 2023 Share Posted May 1, 2023 (edited) 7 hours ago, Hiding said: I tried with onClientVehicleDamage, but it only triggered when my car was exploded. I need the localPlayer vehicle's health before the explosion. you can get the pilot with getVehicleOccupant function and check if it exists an example that maybe can help you function VehicleHealth(attacker, weapon, loss) local HealthOfVehicle = getElementHealth(source) local driver = getVehicleOccupant(source) if driver then outputChatBox("life before the crash: "..math.floor(HealthOfVehicle)) outputChatBox("life after the crash: "..math.floor(HealthOfVehicle - loss)) outputChatBox("damage taken: "..math.floor(loss)) end end addEventHandler("onClientVehicleDamage", root, VehicleHealth) Edited May 1, 2023 by SciptNovato 1 Link to comment
Hiding Posted May 2, 2023 Author Share Posted May 2, 2023 (edited) Thank you guys so much for trying to help me, but I guess you don't get it maybe I have to check with onClientRender when the HP reaches 0, because this onClientVehicleDamage is only triggering if damage happens, but for example when the vehicle is upside down and starts burning, it doesn't actually suffer any damage until it explodes and its life reaches zero. So what I would need is that as soon as the vehicle reaches zero hp output to the chat that "vehicle hp is 0" or something. But if I check it with onClientRender then it will flood the chat until my hp is 0, how can I manage to write once in the chat if the hp is reaching 0? Edited May 2, 2023 by Hiding Link to comment
Mkl Posted May 2, 2023 Share Posted May 2, 2023 (edited) Hi I noticed that : - The vehicle starts to be on fire below 250 / 1000 - When it's flipped it takes 1100 of damage during the explosion I don't see any event about detecting the vehicle on fire but you can still detect it like this : addEventHandler("onClientVehicleEnter", root, function() local vehicle = source setTimer(function() if getElementHealth(vehicle) < 250 then print("onFire") killTimer(sourceTimer) end end, 500, 0) end) Edited May 2, 2023 by Mkl 1 Link to comment
FLUSHBICEPS Posted May 2, 2023 Share Posted May 2, 2023 1 hour ago, Hiding said: Thank you guys so much for trying to help me, but I guess you don't get it &amp;lt;img alt=":D" data-emoticon="" height="20" src="https://forum.multitheftauto.com/uploads/emoticons/biggrin.png" srcset="https://forum.multitheftauto.com/uploads/emoticons/[email protected] 2x" title=":D" width="20" /&amp;gt; maybe I have to check with onClientRender when the HP reaches 0, because this onClientVehicleDamage is only triggering if damage happens, but for example when the vehicle is upside down and starts burning, it doesn't actually suffer any damage until it explodes and its life reaches zero. So what I would need is that as soon as the vehicle reaches zero hp output to the chat that "vehicle hp is 0" or something. But if I check it with onClientRender then it will flood the chat until my hp is 0, how can I manage to write once in the chat if the hp is reaching 0? local msg = false function checkVehHealth() local veh = getPedOccupiedVehicle(localPlayer) if veh then local currHealth = getElementHealth(veh) if currHealth <= 0 and not msg then outputChatBox("Your vehicle HP is 0", 255, 0, 0) msg = true elseif currHealth > 0 then msg = false end end end addEventHandler("onClientRender", root, checkVehHealth) u can use a boolean variable to ensure the message is only displayed once 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now