sirrjohn Posted February 15, 2024 Share Posted February 15, 2024 (edited) For some reason this script when ped is with high health (im using extra_health resource), when u shoot him its life bar only visually lowers after his life is low... if his health is high it wont even move or visually reduce the health bar. PS: Health works fine issue is only with the bar. I'm sure the code is wrong, I just need a little help with calculations here I believe... not sure. local maxHealth = 1000000 local healthPercentage = health / maxHealth local lineLength = 150 * healthPercentage local healthBar = dxDrawRectangle(sx - 60, sy - 70, lineLength, 7, tocolor(255, 0, 0, 210)) Appreciate all the help, I'm trying to not bother you guys here and trying to do by myself but this issue got me. Edited February 15, 2024 by sirrjohn Link to comment
sirrjohn Posted February 15, 2024 Author Share Posted February 15, 2024 Since i cant edit: Decided to do it a diff way, using imageSection health = exports["extra_health"]:getElementExtraHealth(peds) local healthround = math.ceil(health) local life_pc = (health / 1000) * 100 local vida_atual = life_pc*1.28 dxDrawImage(sx-60, sy- 70, 128, 16, "healthbarbg.png") dxDrawImageSection(sx-60, sy- 70, vida_atual, 16, 0, 0, vida_atual, 16, "healthbar.png") dxDrawText(healthround,sx-40+25,sy-70,sx, sy,tocolor ( 255, 255, 255, 255 ), 1,"sans") I just couldn't get the max health value so i had to put it manually, but it works. Problem now is when ped health reaches 0 it doesnt die... i need to shoot him a few more times, using extra_health script addEventHandler("onClientPedDamage", root, function(attacker, weapon, _, loss) if isElementInvulnerable(source) then cancelEvent() else local health = getElementExtraHealth(source) if health >= loss then setElementExtraHealth(source, health - loss) cancelEvent() end end end ) Link to comment
Moderators IIYAMA Posted February 15, 2024 Moderators Share Posted February 15, 2024 12 hours ago, sirrjohn said: if health >= loss then Not sure but, would the > operator not make more sense? if health > loss then --- ... else setElementExtraHealth(source, 0) -- clean dead status (not sure if this is a good idea) end 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