Jump to content

[help]Health bar blink


Xierra

Recommended Posts

Posted

Hi guys!

I want to keep updating the Alternate HUD, so I made this.

You might know what happens when health is low right? It blinks every second.

So I want to make this kind of anim on my HUD, any clues how to do that?

Posted
addEventHandler("onClientRender",getRootElement(),
function()
if getTickCount()%2000 < 1000 then
--draw it here
end
end
)

Posted

It's working, but it blinks regardless of the health amount.

So I want it to blink only if the health is less than equals to 25. How to do that?

Posted

I know that already. But I don't know where to put. So My try:

if getTickCount () %2000 < 1000 and health <= 25 then
dxDrawRectangle(sWidth-206,sHeight-23,114.0,14.0,tocolor(50,0,0,150),false) -- Health inactive bar
dxDrawRectangle(sWidth-206,sHeight-23,lineLength1,14.0,tocolor(175,0,0,200),false) --Health active bar
else
dxDrawRectangle(sWidth-206,sHeight-23,114.0,14.0,tocolor(50,0,0,150),false) -- Health inactive bar
dxDrawRectangle(sWidth-206,sHeight-23,lineLength1,14.0,tocolor(175,0,0,200),false) --Health active bar
end

But it didn't blink if health is actually less than 25.

How to fix it?

Posted

LOL

It doesn't blink because you draw it, whether you have more than 25 of health or not. Both of your dxDrawRectangle pairs are the same. Change the colour and see the difference.

Posted
addEventHandler("onClientRender",getRootElement(),
function()
if getTickCount()%2000 < 1000 then
--draw it here
end
end
)

hi

to my personal culture, i'd like to understand the addition of %2000 which is not explained in the wiki.

Can you guys tell me? :)

Good idea about the blink thing XX3, also i would put health bar colors like it:

green when >= 60

orange >=30 & <60

red <30

what do you think?

Posted
to my personal culture, i'd like to understand the addition of %2000 which is not explained in the wiki.

% is about the same as doing this:

number = 9001
while number >= 2000 do
   number = number - 2000
end

You basically set a maximum for your number. If it exceeds the maximum, % rounds it back to within the range you specify.

Posted

I made a dynamic colour change health bar for a Flash game long time ago (college project), I'll port it to Lua for you:

local health = getElementHealth( getLocalPlayer( ) );
local maxHealth = getPedStat( getLocalPlayer(), 24 ); -- get max health stat
local colourPercent = ( health / maxHealth ) * 255;
local red, green; -- we don't need blue because we don't use it, it'll be 0
if health < ( maxHealth / 2 ) then
  red = 255;
  green = ( health / 50 ) * ( colorPercent * 2 );
else
  green = 255;
  red = 255 - ( ( health - 50 ) / 50 ) * 255;
end
local color = tocolor( red, green, 0, 150 );
 
-- Now, use this "color" variable instead your tocolor

I haven't tested it but it should work just fine since it's a simple port from ActionScript to Lua. If you get some issues, tell me and I'll test it and fix it if necessary. I know for a fact, at first the colour was weird due to Flash colour transformation but it should work.

As your health goes down, the colour will transform. The colour should change like so: Green (100%) -> Yellow (50%) -> Red (0%).

Posted (edited)

OK, just tested and found out that getPedStat returns 569 not as I expected it to return value of what max health you see on the health bar. Use this code then:

local maxHealth = 100; -- get max health stat
local colourPercent = ( health / maxHealth ) * 255;
local red, green; -- we don't need blue because we don't use it, it'll be 0
if health < ( maxHealth / 2 ) then
red = 255;
green = ( health / 50 ) * ( colourPercent * 2 );
else
green = 255;
red = 255 - ( ( health - 50 ) / 50 ) * 255;
end
local color = tocolor( red, green, 0, 150 );

Edited by Guest
Posted

When health is full, the colour is green, but if my health was reduced a bit, it suddenly become yellow.

Health: 100% --> Green

Health: 99% --> Yellow

Posted

Yes! It should work now.

Btw, I need a darker colour for the back of the health bar. I was thinking like MTA's nametag colour.

I want to learn how to make dynamic colour regarding to this kind of thing.

Posted

You can get darker colour by yourself... Make it static and don't change it as player's health change.

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