Jump to content

Dx HUD problem


Recommended Posts

Hello people! I made a Dx HUD, and the problem is that I don't know how to attach guiGetScreenSize to a HP bar, so in lower resolutions the HP bar looks like this

1899061_672752819438375_1248928072_n.jpg?oh=f2292e60d0e78ccee1e787ce10efbd69&oe=532001F2&__gda__=1394618685_e7454ddd2338cf41fe2ac47986603ffc

Can somebody help me how to make the HP bar fit the background? Thank you!

Bit of the script:

  
local hp = getElementHealth(localPlayer) 
  
dxDrawRectangle(screenX*0.235 , screenY*0.8142, screenX*0.0654, screenY*0.0238, tocolor(0, 0, 0, 150)) 
dxDrawRectangle(screenX*0.238 , screenY*0.819, hp, screenY*0.0142, tocolor(135, 34, 34, 200)) 

P.S.: In my resolution it fits correctly.

  • Like 1
Link to comment
  • Moderators
screenX,screenY = guiGetScreenSize() 

Please don't help others when you can't even help yourself ...

P.S.: In my resolution it fits correctly.

Well, the script should be fine, can you show us a screen when the hp bar fits correctly ?

Thanks

Link to comment
screenX,screenY = guiGetScreenSize() 

Please don't help others when you can't even help yourself ...

P.S.: In my resolution it fits correctly.

Well, the script should be fine, can you show us a screen when the hp bar fits correctly ?

Thanks

really ? he didnt define screenX and screenY .. and how it will work correctly without guiGetScreenSize ?

he want it to fit in the same place for any resolution.

btw do u have any problem if i tried to help ?

Link to comment
screenX,screenY = guiGetScreenSize() 

Please don't help others when you can't even help yourself ...

P.S.: In my resolution it fits correctly.

Well, the script should be fine, can you show us a screen when the hp bar fits correctly ?

Thanks

really ? he didnt define screenX and screenY .. and how it will work correctly without guiGetScreenSize ?

he want it to fit in the same place for any resolution.

btw do u have any problem if i tried to help ?

I haven't mentioned it but I've written it in the script.

Link to comment

He said in his post >>

I don't know how to attach guiGetScreenSize to a HP bar

and he didnt mention the line of guiGetScreenSize, so i replied my post as trying to help him.

and u replied stop helping people if u dont know how to help ur self ..

do u think only u helping in this forum ?

i feel free to post in this forum and u have no perm to tell me stop helping !! okay ?

Have a nice day !

Link to comment
Stop this! I just wanted to know how to make a dxRectangle, which is used as a health bar fit in any resolutions, because instead of numbers it is defined as "hp". And I don't know how to make it fit correctly on all resolutions. Help please. Don't fight.

We're not fighting .- anyway your code is okay. and it will fit any resolution.

Link to comment
  • Moderators
We're not fighting .- anyway your code is okay. and it will fit any resolution.

And you are wrong again ... The code is obviously not okay ! Did you see the screenshots he made :roll: come on, use your brain.

@Dzsozi: I need to know the screen resolution of the first screenshot and if both screenshots had been just cropped/trimmed and not zoomed in or out

Link to comment
We're not fighting .- anyway your code is okay. and it will fit any resolution.

And you are wrong again ... The code is obviously not okay ! Did you see the screenshots he made :roll: come on, use your brain.

@Dzsozi: I need to know the screen resolution of the first screenshot and if both screenshots had been just cropped/trimmed and not zoomed in or out

The player's resolution on the first picture is 1360x768 pixels. The HP and Armor bar is a little bit larger than the background on their resolution. Anything else you need to know to help me?

Link to comment
  • Moderators
1360x768 pixels

1366x768*

Ok I'll check if I can make it only using the screenshots. If I can't, I will need the way you calculate the position and size of the radar (border included).

Anything else you need to know to help me?

Hmmm yeah, the way you calculate the bars width.

Link to comment
    local screenX, screenY = guiGetScreenSize() 
     
    dxDrawImage(screenX*0.145, screenY*0.744, screenX*0.25, screenY*0.19, "bgt.png") 
     
    local hp = getElementHealth (localPlayer) 
    -- 1310, 860, 16, 16 
    dxDrawImage(screenX*0.22, screenY*0.82, screenX*0.00952, screenY*0.01523, "heal.png") 
    -- 1285, 855, 110, 25 
    -- 1280, 860, hp, 15 
    dxDrawRectangle(screenX*0.235 , screenY*0.8142, screenX*0.0654, screenY*0.0238, tocolor(0, 0, 0, 150)) 
    dxDrawRectangle(screenX*0.238 , screenY*0.819, hp, screenY*0.0142, tocolor(135, 34, 34, 200)) 
     
    local arm = getPedArmor (localPlayer) 
    dxDrawImage(screenX*0.22, screenY*0.8515, screenX*0.00952, screenY*0.01523, "kevlar.png") 
    dxDrawRectangle(screenX*0.235 , screenY*0.8476, screenX*0.0654, screenY*0.0238, tocolor(0, 0, 0, 150)) 
    dxDrawRectangle(screenX*0.238 , screenY*0.8523, arm, screenY*0.0142, tocolor(93, 125, 150, 200)) 
     
    local oxy = getPedOxygenLevel (localPlayer) 
    dxDrawImage(screenX*0.313, screenY*0.82, screenX*0.00952, screenY*0.01523, "ox.png") 
    dxDrawRectangle(screenX*0.327 , screenY*0.81333, screenX*0.0238, screenY*0.10095, tocolor(0, 0, 0, 150)) 
     
    -- 1125, 950, 27, 5 
    if oxy > 0 then 
        dxDrawImage(screenX*0.3305, screenY*0.9047, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 100 then 
        dxDrawImage(screenX*0.3305, screenY*0.8952, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 200 then 
        dxDrawImage(screenX*0.3305, screenY*0.8857, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 300  then 
        dxDrawImage(screenX*0.3305, screenY*0.8761, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 400 then 
        dxDrawImage(screenX*0.3305, screenY*0.8666, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 500 then 
        dxDrawImage(screenX*0.3305, screenY*0.8571, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 600 then 
        dxDrawImage(screenX*0.3305, screenY*0.8476, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 700 then 
        dxDrawImage(screenX*0.3305, screenY*0.8380, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 800 then 
        dxDrawImage(screenX*0.3305, screenY*0.8285, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 
     
    if oxy > 900 then 
        dxDrawImage(screenX*0.3305, screenY*0.8190, screenX*0.01607, screenY*0.00476, "oxy-bar.png") 
    end 

Hope this helps

Link to comment
  • Moderators

Lol ok you were right, the resolution is 1360x768. I never saw that resolution on any computer lol (but 1366x768 is common on laptops).

Hope this helps

Yeah, it helps a lot, I could fix the health and armor bars:

Replace line 11 by this:

local maxHealthWidth = screenX*0.0654 - 0.003 
dxDrawRectangle(screenX*0.238 , screenY*0.819, hp*maxHealthWidth/100, screenY*0.0142, tocolor(135, 34, 34, 200)) 

Replace line 16 by this:

local maxArmorWidth = screenX*0.0654 - 0.003 
dxDrawRectangle(screenX*0.238 , screenY*0.8523, arm*maxArmorWidth/100, screenY*0.0142, tocolor(93, 125, 150, 200)) 

The problem seems to come from the radar positioning/sizing. I would like to see this part of the radar code. Or maybe a fullscreen (do not edit) of the hud in your resolution. Thanks.

Link to comment
Lol ok you were right, the resolution is 1360x768. I never saw that resolution on any computer lol (but 1366x768 is common on laptops).
Hope this helps

Yeah, it helps a lot, I could fix the health and armor bars:

Replace line 11 by this:

local maxHealthWidth = screenX*0.0654 - 0.003 
dxDrawRectangle(screenX*0.238 , screenY*0.819, hp*maxHealthWidth/100, screenY*0.0142, tocolor(135, 34, 34, 200)) 

Replace line 16 by this:

local maxArmorWidth = screenX*0.0654 - 0.003 
dxDrawRectangle(screenX*0.238 , screenY*0.8523, arm*maxArmorWidth/100, screenY*0.0142, tocolor(93, 125, 150, 200)) 

Instead of screenX*0.0654 - 0.003 I should write screenX*0.059, but now it's perfect! It fits the background on all resolutions! Thank you very much!

Wasn't the perfect, instead of local maxHealthWidth = screenX*0.0654 - 0.003 I should write 0.059 to fit correctly, but now it's good! Thank you very much!!

The problem seems to come from the radar positioning/sizing. I would like to see this part of the radar code. Or maybe a fullscreen (do not edit) of the hud in your resolution. Thanks.

Link to comment
  • Moderators
Instead of screenX*0.0654 - 0.003 I should write screenX*0.059, but now it's perfect! It fits the background on all resolutions! Thank you very much!

Wasn't the perfect, instead of local maxHealthWidth = screenX*0.0654 - 0.003 I should write 0.059 to fit correctly, but now it's good! Thank you very much!!

Hummm the two piece of code I gave you were only for the two bars (health and armor) not for the background oO

But if you say you fixed it, then it's okay.

Link to comment
Instead of screenX*0.0654 - 0.003 I should write screenX*0.059, but now it's perfect! It fits the background on all resolutions! Thank you very much!

Wasn't the perfect, instead of local maxHealthWidth = screenX*0.0654 - 0.003 I should write 0.059 to fit correctly, but now it's good! Thank you very much!!

Hummm the two piece of code I gave you were only for the two bars (health and armor) not for the background oO

But if you say you fixed it, then it's okay.

I just had to fix the bars. :D

Link to comment

One more thing. How could I make a hunger bar with dxDrawRectangle? I want to make a hunger bar which is like the other bars (armor and health), so it has a timer and the dx bar is going down slowly. When it reaches 0 the hp starts to go down as well. But how could I make a bar for hunger and a timer to lower it? Can you help me in this please? I would be grateful!

Link to comment
  • Moderators
One more thing. How could I make a hunger bar with dxDrawRectangle? I want to make a hunger bar which is like the other bars (armor and health), so it has a timer and the dx bar is going down slowly. When it reaches 0 the hp starts to go down as well. But how could I make a bar for hunger and a timer to lower it? Can you help me in this please? I would be grateful!

You have to create the functions to get and set the player hunger and create a timer to decrease it every X milliseconds when the player logs in.

You can then use the get function to update your dx bar.

function setPlayerHunger( thePlayer, hunger ) 
    -- check if thePlayer ~= nil and thePlayer element type is "player" and the lua type of hunger == "number" 
        -- set an element data on thePlayer using the key "hunger" and hunger (from the argument) as value 
        --return what setElementData function returned 
    --endif 
    -- returns false here 
end 
  
function getPlayerHunger( thePlayer ) 
    -- check if thePlayer ~= nil and thePlayer element type is "player" 
        -- get value of the element data on thePlayer using the same key ("hunger") 
        -- returns what the getElementData above returned or 0 if it returned false 
    --endif 
end 
  
function decreaseHunger( thePlayer ) 
    -- check if thePlayer ~= nil and thePlayer element type is "player" 
        -- get the hunger of that player using getPlayerHunger 
        -- check if that value is <= 0 
            -- get the player health 
            -- decrease it 
            -- set the new health for that player 
        -- else 
            -- decrease the hunger 
            -- set the new hunger using setPlayerHunger 
        -- endif 
    --endif 
end 
  
function whenPlayerLogsIn() --you can rename it if you want 
    -- set the hunger to whatever value you want for that player (100 or using getAccountData if you saves it in database) 
    -- set an infinite timer that will call decreaseHunger and giving the player element as argument 
    -- save that timer inside an element data on the player using the key "hungerTimer" (will be needed to kill it later) 
end 
-- When the player logs in (there is an event for that): execute the function above 
  
function whenPlayerQuitOrLogsOff() --you can rename it if you want 
    -- get the hunger timer of that player stored in its element data with the key "hungerTimer" 
    -- check if the value you got from the line above is not false and if it's a timer (use isTimer) 
        -- kill that timer 
    -- endif 
end 
-- When the player logs off (there is an event for that): execute the function above 
-- When the player quits (there is an event for that): execute the same function above 
  

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