Jump to content

[help]Health bar blink


Xierra

Recommended Posts

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?

Link to comment

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.

Link to comment
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?

Link to comment
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.

Link to comment

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

Link to comment

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