Jump to content

Custom Hud elements


DakiLLa

Recommended Posts

hello guys, i want to make my own hud elements and i started from health bar. Well, everything is going good but i have one problem. How do i make that red line will show my current health percentage? I know, it requires some math skills but i have no any ideas... Anybody can help me? Here is a little piece of code ofcourse.

addEventHandler( 'onClientRender', gRoot,
function()
local scX, scY = guiGetScreenSize();
local lineX = scX/1.1725;
local lineEndX = scX/1.053;
local lineY = scY/6.5;
 
dxDrawLine( lineX, lineY, lineEndX, lineY, tocolor( 0, 0, 0, 255 ), 17 );
dxDrawLine( lineX+5, lineY, lineEndX-5, lineY, tocolor( 150, 0, 0, 255 ), 9 );
dxDrawLine( lineX+5, lineY, lineEndX-5, lineY, tocolor( 255, 0, 0, 255 ), 9 );
end
);

So it looks like:

e1f212b8e23ct.jpg

Thx in advance :)

Link to comment

hello guys, i want to make my own hud elements and i started from health bar. Well, everything is going good but i have one problem. How do i make that red line will show my current health percentage? I know, it requires some math skills but i have no any ideas... Anybody can help me? Here is a little piece of code ofcourse.

addEventHandler( 'onClientRender', gRoot,  function()    local scX, scY = guiGetScreenSize();    local lineX = scX/1.1725;    local lineEndX = scX/1.053;    local lineY = scY/6.5;     dxDrawLine( lineX, lineY, lineEndX, lineY, tocolor( 0, 0, 0, 255 ), 17 );    dxDrawLine( lineX+5, lineY, lineEndX-5, lineY, tocolor( 150, 0, 0, 255 ), 9 );    dxDrawLine( lineX+5, lineY, lineEndX-5, lineY, tocolor( 255, 0, 0, 255 ), 9 );  end);

So it looks like:

e1f212b8e23ct.jpg

Thx in advance :)

Link to comment

First thing you need to know is Max length of the health bar (when health is full). Then, you need to calculate what percentage of health player currently have (getElementHealth divided by max health(eg.100)). Once you get the percentage, multiply that number by max health bar length and you will get the length of the health bar to show.

This is very simple math:

maxBarLength = 100;
maxHealth = 100;
 
local percentage = getElementHealth( player ) / maxHealth; -- between 0 and 1
local currentBarLength = percentage * maxHealth; -- length of the bar to display

Link to comment

First thing you need to know is Max length of the health bar (when health is full). Then, you need to calculate what percentage of health player currently have (getElementHealth divided by max health(eg.100)). Once you get the percentage, multiply that number by max health bar length and you will get the length of the health bar to show.

This is very simple math:

maxBarLength = 100;
maxHealth = 100;
 
local percentage = getElementHealth( player ) / maxHealth; -- between 0 and 1
local currentBarLength = percentage * maxHealth; -- length of the bar to display

Link to comment
First thing you need to know is Max length of the health bar (when health is full). Then, you need to calculate what percentage of health player currently have (getElementHealth divided by max health(eg.100)). Once you get the percentage, multiply that number by max health bar length and you will get the length of the health bar to show.

This is very simple math:

maxBarLength = 100;
maxHealth = 100;
 
local percentage = getElementHealth( player ) / maxHealth; -- between 0 and 1
local currentBarLength = percentage * maxHealth; -- length of the bar to display

Have you just been busy with PHP maybe? :-P

Since you use the ";" tags at the end haha.

Link to comment
First thing you need to know is Max length of the health bar (when health is full). Then, you need to calculate what percentage of health player currently have (getElementHealth divided by max health(eg.100)). Once you get the percentage, multiply that number by max health bar length and you will get the length of the health bar to show.

This is very simple math:

maxBarLength = 100;
maxHealth = 100;
 
local percentage = getElementHealth( player ) / maxHealth; -- between 0 and 1
local currentBarLength = percentage * maxHealth; -- length of the bar to display

Have you just been busy with PHP maybe? :-P

Since you use the ";" tags at the end haha.

Link to comment
First thing you need to know is Max length of the health bar (when health is full). Then, you need to calculate what percentage of health player currently have (getElementHealth divided by max health(eg.100)). Once you get the percentage, multiply that number by max health bar length and you will get the length of the health bar to show.

This is very simple math:

maxBarLength = 100;
maxHealth = 100;
 
local percentage = getElementHealth( player ) / maxHealth; -- between 0 and 1
local currentBarLength = percentage * maxHealth; -- length of the bar to display

Have you just been busy with PHP maybe? :-P

Since you use the ";" tags at the end haha.

No, I've been busy with other programming languages (C#, ActionScript and MAXScript) and it's just fine to use semicolons in Lua, so I don't care :)

Link to comment
First thing you need to know is Max length of the health bar (when health is full). Then, you need to calculate what percentage of health player currently have (getElementHealth divided by max health(eg.100)). Once you get the percentage, multiply that number by max health bar length and you will get the length of the health bar to show.

This is very simple math:

maxBarLength = 100;
maxHealth = 100;
 
local percentage = getElementHealth( player ) / maxHealth; -- between 0 and 1
local currentBarLength = percentage * maxHealth; -- length of the bar to display

Have you just been busy with PHP maybe? :-P

Since you use the ";" tags at the end haha.

No, I've been busy with other programming languages (C#, ActionScript and MAXScript) and it's just fine to use semicolons in Lua, so I don't care :)

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