Jump to content

[BUG] What wrong in this circle hud?


Turbe$Z

Recommended Posts

i created a 'circle-hud' but it does not work well :( 

this is the problem: (when my Health = 14hp)

and when my Health = 100hp

the 100hp is fine, but the 14 hp not... :(

i want something like that when my hp <100

how to fix this? :| 

 

Edited by Dutchman101
Fix topic title for section requirements
Link to comment
6 minutes ago, pa3ck said:

I think the problem is at line 129, after the loop, inside the if but right after a trigger.

        dxDrawImage(screenW * 0.9583, screenH * 0.0022, screenW * 0.0361, screenH * 0.0005*playerHealth, "egyedi/hp_full.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)

this is the code

Link to comment

Try to use the example first, that should get you started. You will need to set the "vsize" parameter depending on the player's health. You can easily calculate that like this:

local health = getElementHealth(localPlayer)
local myIconHeight = 120 --pixels
local vSize = myIconHeight / 100 * health

If you can't figure it out, come back with the code you tried (for the dxDrawImageSection).

Edited by pa3ck
Link to comment
13 minutes ago, pa3ck said:

Try to use the example first, that should get you started. You will need to set the "vsize" parameter depending on the player's health. You can easily calculate that like this:


local health = getElementHealth(localPlayer)
local myIconHeight = 120 --pixels
local vSize = myIconHeight / 100 * health

If you can't figure it out, come back with the code you tried (for the dxDrawImageSection).

i tried with the example code, but does not work well too :| 

addEventHandler('onClientRender', root, function()
local health = getElementHealth(localPlayer)
local myIconHeight = 120 --pixels
local vSize = myIconHeight / 100 * health
	dxDrawImageSection(400, 200, 64, 64, 0, 0, myIconHeight, vSize, 'egyedi/hp_full.png')
	dxDrawImage(400, 300, 128, 128, 'egyedi/hp_full.png')
end)

 

Link to comment
local scrX, scrY = guiGetScreenSize()
local hudS = {}
hudS.bgX = scrX - 300 -- X position of background
hudS.bgY = 20 -- Y position of background
hudS.bgW = 128 -- background width (img size in pixels)
hudS.bgH = 128 -- background height (img size in pixels)
hudS.fX = scrX - 275 -- X position of fill
hudS.fY = 51 -- Y position of fill
hudS.fW = 78 -- fill width (img size in pixels)
hudS.fH = 66 -- fill height (img size in pixels)

addEventHandler("onClientResourceStart", resourceRoot, function()

	addEventHandler("onClientRender", root, function()
		dxDrawImage(hudS.bgX, hudS.bgY, hudS.bgW, hudS.bgH, "heart_bg.png")
		local currHeight = hudS.fH / 100 * getElementHealth(localPlayer) 
		dxDrawImageSection(hudS.fX, hudS.fY, hudS.fW, currHeight, 0, 0, hudS.fW, currHeight, "heart_fill.png")
	end)

end)

https://i.imgur.com/z2qzSA8.png

http://imgur.com/6gOIw5i

Change the images and width/height, X/Y positions.

 

  • Like 2
Link to comment
14 minutes ago, pa3ck said:

local scrX, scrY = guiGetScreenSize()
local hudS = {}
hudS.bgX = scrX - 300 -- X position of background
hudS.bgY = 20 -- Y position of background
hudS.bgW = 128 -- background width (img size in pixels)
hudS.bgH = 128 -- background height (img size in pixels)
hudS.fX = scrX - 275 -- X position of fill
hudS.fY = 51 -- Y position of fill
hudS.fW = 78 -- fill width (img size in pixels)
hudS.fH = 66 -- fill height (img size in pixels)

addEventHandler("onClientResourceStart", resourceRoot, function()

	addEventHandler("onClientRender", root, function()
		dxDrawImage(hudS.bgX, hudS.bgY, hudS.bgW, hudS.bgH, "heart_bg.png")
		local currHeight = hudS.fH / 100 * getElementHealth(localPlayer) 
		dxDrawImageSection(hudS.fX, hudS.fY, hudS.fW, currHeight, 0, 0, hudS.fW, currHeight, "heart_fill.png")
	end)

end)

https://i.imgur.com/z2qzSA8.png

http://imgur.com/6gOIw5i

Change the images and width/height, X/Y positions.

 

thanks :D and i can add oxygen, and armor? 

Link to comment

Sure, if you follow the same structure of the code (setting the X/Y, width/height) correctly, you should be able to add more. The calculation for armor is the same, imageHeight / 100 * armor, but for the oxygen, the maximum value is 1000, so it will be imageHeight / 1000 * oxygenLevel

  • Like 1
Link to comment
  • Moderators

I don't know if you have already tested it, but this code will leave your health bar inverted, compared to this one:

4 hours ago, Turbo777 said:

 

You can try to fix it using this way (with @pa3ck's code):

dxDrawImageSection( hudS.fX, hudS.fY + (hudS.fH - currHeight), hudS.fW, currHeight, 0, hudS.fH - currHeight, hudS.fW, currHeight, "heart_fill.png" )

 

Also, keep in mind that the health bar should get bugged if player's health is above 100%, so I recommend you to use this function: https://wiki.multitheftauto.com/wiki/GetPedMaxHealth

You can do it for the oxygen as well (use getPedMaxOxygenLevel).

Link to comment
10 hours ago, pa3ck said:

Sure, if you follow the same structure of the code (setting the X/Y, width/height) correctly, you should be able to add more. The calculation for armor is the same, imageHeight / 100 * armor, but for the oxygen, the maximum value is 1000, so it will be imageHeight / 1000 * oxygenLevel

Sorry, but you can send me a 'long-shadow' image about oxygen? I can not find anywhere :S 

Link to comment
12 hours ago, pa3ck said:

Sure, if you follow the same structure of the code (setting the X/Y, width/height) correctly, you should be able to add more. The calculation for armor is the same, imageHeight / 100 * armor, but for the oxygen, the maximum value is 1000, so it will be imageHeight / 1000 * oxygenLevel

What wrong with this? :(  

hudS.bgX = scrX - 60 -- X position of background
hudS.bgY = 4 -- Y position of background
hudS.bgW = 52 -- background width (img size in pixels)
hudS.bgH = 52 -- background height (img size in pixels)
hudS.fX = scrX - 275 -- X position of fill
hudS.fY = 51 -- Y position of fill
hudS.fW = 52 -- fill width (img size in pixels)
hudS.fH = 52 -- fill height (img size in pixels)

		dxDrawImage(hudS.bgX-60, hudS.bgY, hudS.bgW, hudS.bgH, "shield_bg.png")
		local currHeight2 = 66 / 100 * getPedArmor ( getLocalPlayer() )
        dxDrawImageSection(hudS.fX+163, hudS.fY-39, hudS.fW, currHeight2, 0, 0, hudS.fW+65, currHeight+195, "asda.png")

and this is the problem: 

how to fix? :( 

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