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?

XX3 is gone. This is my new name. :3

Posted

But it was a DX rectangle. So you can't use guiSetVisible in a DX drawing. Any way around?

XX3 is gone. This is my new name. :3

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?

XX3 is gone. This is my new name. :3

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?

XX3 is gone. This is my new name. :3

Posted

Ahh yes it worked! I forgot about that. Now I see it blinks if health is less than 25.

XX3 is gone. This is my new name. :3

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?

If you require a paid scripter, don't contact me, you can't afford me.

my resources: autoteams_manager

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.

Projects:

Slothbot | Maximap

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

XX3 is gone. This is my new name. :3

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.

XX3 is gone. This is my new name. :3

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