Jump to content

[Help] Healthbar not decreasing until ped low hp


Recommended Posts

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 by sirrjohn
Link to comment

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

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