Xierra Posted July 1, 2010 Posted July 1, 2010 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?
Spider Pork Posted July 1, 2010 Posted July 1, 2010 guiSetVisible in a timer? When your health is low, your normal health bar dissappears and appears back each second or so.
Xierra Posted July 1, 2010 Author Posted July 1, 2010 yeah something like that, I want to make it to my HUD.
Spider Pork Posted July 1, 2010 Posted July 1, 2010 Yea, just use guiSetVisible every second to hide and re-show the health bar.
Xierra Posted July 1, 2010 Author Posted July 1, 2010 But it was a DX rectangle. So you can't use guiSetVisible in a DX drawing. Any way around?
DiSaMe Posted July 1, 2010 Posted July 1, 2010 addEventHandler("onClientRender",getRootElement(), function() if getTickCount()%2000 < 1000 then --draw it here end end )
Xierra Posted July 1, 2010 Author Posted July 1, 2010 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?
Spider Pork Posted July 1, 2010 Posted July 1, 2010 https://wiki.multitheftauto.com/wiki/GetElementHealth
Xierra Posted July 1, 2010 Author Posted July 1, 2010 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?
50p Posted July 1, 2010 Posted July 1, 2010 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.
Xierra Posted July 2, 2010 Author Posted July 2, 2010 Ahh yes it worked! I forgot about that. Now I see it blinks if health is less than 25.
FabienWang Posted July 2, 2010 Posted July 2, 2010 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?
Xierra Posted July 2, 2010 Author Posted July 2, 2010 Ahh good idea. Maybe I could add it if I have some time.
Gamesnert Posted July 2, 2010 Posted July 2, 2010 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.
50p Posted July 2, 2010 Posted July 2, 2010 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%).
Xierra Posted July 2, 2010 Author Posted July 2, 2010 Thanks 50p, but the problem is: If health is 100%, it's yellow instead of green
50p Posted July 2, 2010 Posted July 2, 2010 (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 July 3, 2010 by Guest
Xierra Posted July 3, 2010 Author Posted July 3, 2010 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
Xierra Posted July 3, 2010 Author Posted July 3, 2010 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.
Xierra Posted July 4, 2010 Author Posted July 4, 2010 Ahh man I don't want this topic left cause I'm not finished here yet...
Xierra Posted July 5, 2010 Author Posted July 5, 2010 Lol, the previous post of course. This post: http://www.forum.multitheftauto.com/vie ... 48#p314849
50p Posted July 5, 2010 Posted July 5, 2010 You can get darker colour by yourself... Make it static and don't change it as player's health change.
Xierra Posted July 5, 2010 Author Posted July 5, 2010 Hmm alright then, I'll choose the red ones for the back. Topic finished.
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