Jump to content

[HELP] HUD render


iPanda

Recommended Posts

Posted

Hi guys. I have a problem with my code is thin. Not play. Please, help.

Here's the code:

local player = getLocalPlayer() 
local x, y = guiGetScreenSize() 
local ox = x/1000 
local oy = y/1000 
local healh = math.ceil( getElementHealth( player )) 
  
scale = guiCreateStaticImage(0, 878, 1440, 27, "data/scale.png", false) 
number = guiCreateStaticImage(0, 864, 1440, 27, "data/number.png", false) 
guiSetVisible( scale, true ) 
guiSetVisible( number, true ) 
  
local HEALTH_line = function() 
    local on = guiSetVisible( line, true ) 
        line = guiCreateStaticImage(health*ox, 882, 2, 23, "data/line.png", false) 
end 
addEventHandler("onClientRender", getRootElement(), HEALTH_line) 

I have a problem: not showing beacons that determines the player's life (beacon must move along the X axis, but there is a problem - it does not work)

*I use the Google translator, so if you did not understand me, write, I try to give a more open description.

Posted (edited)
health and ox are never being updated. You need to define the in the render function too.

* Most likely a bug in my code.

I did not understand you. How to define the in the render function too?

Edited by Guest
Posted
local player = getLocalPlayer() 
local x, y = guiGetScreenSize() 
local oy = y/1000 
  
scale = guiCreateStaticImage(0, 878, 1440, 27, "data/scale.png", false) 
number = guiCreateStaticImage(0, 864, 1440, 27, "data/number.png", false) 
guiSetVisible( scale, true ) 
guiSetVisible( number, true ) 
  
local HEALTH_line = function()6 
    local healh = math.ceil( getElementHealth( player )) 
    local ox = x/1000 
    line = guiCreateStaticImage(health*ox, 882, 2, 23, "data/line.png", false) 
end 
addEventHandler("onClientRender", getRootElement(), HEALTH_line) 

Posted
Well , he has to update the health of the player, otherwise it would be 100% only.

How to update the player's health?

* I'm not really a long time to write lua, is not yet a lot of things to be understood.

Posted
Well , he has to update the health of the player, otherwise it would be 100% only.

How to update the player's health?

* I'm not really a long time to write lua, is not yet a lot of things to be understood.

In the code that I posted.

Now I checked your code. Unfortunately does not work.

* Do not show beacon. (Beacon- is a variable line)

What to do?

Posted

Maybe code by xXMADEXx doesn't work because after "function()" number 6. I think it's just misprint.

local player = getLocalPlayer() 
local x, y = guiGetScreenSize() 
local oy = y/1000 
  
scale = guiCreateStaticImage(0, 878, 1440, 27, "data/scale.png", false) 
number = guiCreateStaticImage(0, 864, 1440, 27, "data/number.png", false) 
guiSetVisible( scale, true ) 
guiSetVisible( number, true ) 
  
function HEALTH_line() 
    local healh = math.ceil( getElementHealth( player )) 
    local ox = x/1000 
    line = guiCreateStaticImage(health*ox, 882, 2, 23, "data/line.png", false) 
end 
addEventHandler("onClientRender", getRootElement(), HEALTH_line) 

Ingame name: [sV]Kostya

Name in scripts: Kostya

Posted
Maybe code by xXMADEXx doesn't work because after "function()" number 6. I think it's just misprint.
local player = getLocalPlayer() 
local x, y = guiGetScreenSize() 
local oy = y/1000 
  
scale = guiCreateStaticImage(0, 878, 1440, 27, "data/scale.png", false) 
number = guiCreateStaticImage(0, 864, 1440, 27, "data/number.png", false) 
guiSetVisible( scale, true ) 
guiSetVisible( number, true ) 
  
function HEALTH_line() 
    local healh = math.ceil( getElementHealth( player )) 
    local ox = x/1000 
    line = guiCreateStaticImage(health*ox, 882, 2, 23, "data/line.png", false) 
end 
addEventHandler("onClientRender", getRootElement(), HEALTH_line) 

Ah, my bad. Didn't see the "6" before posting.
Posted
Maybe code by xXMADEXx doesn't work because after "function()" number 6. I think it's just misprint.
local player = getLocalPlayer() 
local x, y = guiGetScreenSize() 
local oy = y/1000 
  
scale = guiCreateStaticImage(0, 878, 1440, 27, "data/scale.png", false) 
number = guiCreateStaticImage(0, 864, 1440, 27, "data/number.png", false) 
guiSetVisible( scale, true ) 
guiSetVisible( number, true ) 
  
function HEALTH_line() 
    local healh = math.ceil( getElementHealth( player )) 
    local ox = x/1000 
    line = guiCreateStaticImage(health*ox, 882, 2, 23, "data/line.png", false) 
end 
addEventHandler("onClientRender", getRootElement(), HEALTH_line) 

Ah, my bad. Didn't see the "6" before posting.

Yes, but I noticed it before and removed. But all does not work exactly.

* The principle of operation of the lighthouse:

There is a scale - a line lengthwise which must crawl beacon in the X axis, the higher the player's health, the higher the beacon, and when health is spent crawling beacon in the opposite direction. (On the right - rises to the left - is reduced)

Posted

You are constantly creating a GUI image every render, that's a really bad idea and it won't even work.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
local localPlayer = getLocalPlayer() 
local x, y = guiGetScreenSize() 
local oy = y/1000 
  
function HEALTH_line() 
    local health = math.ceil( getElementHealth( localPlayer )) 
    local ox = x/1000 
    if health then 
          dxDrawImage ( health*ox, 882, 2, 23, "data/line.png", angle, 0, -120 ) 
    end 
end 
addEventHandler("onClientRender", getRootElement(), HEALTH_line) 

Still found one misprint in previous codes.    

local healh = math.ceil( getElementHealth( player ))

line = guiCreateStaticImage(health*ox, 882, 2, 23, "data/line.png", false)

Ingame name: [sV]Kostya

Name in scripts: Kostya

Posted (edited)
local localPlayer = getLocalPlayer() 
local x, y = guiGetScreenSize() 
local oy = y/1000 
  
function HEALTH_line() 
    local health = math.ceil( getElementHealth( localPlayer )) 
    local ox = x/1000 
    if health then 
          dxDrawImage ( health*ox, 882, 2, 23, "data/line.png", angle, 0, -120 ) 
    end 
end 
addEventHandler("onClientRender", getRootElement(), HEALTH_line) 

Still found one misprint in previous codes.    

local healh = math.ceil( getElementHealth( player ))

line = guiCreateStaticImage(health*ox, 882, 2, 23, "data/line.png", false)

Your code has flaws, I corrected them, but exactly - does not work. I do not know what to do .... .... :cry:

* I will use guiCreateStaticImage

Edited by Guest
Posted
local localPlayer = getLocalPlayer() 
local x, y = guiGetScreenSize() 
local oy = y/1000 
  
function HEALTH_line() 
    local health = math.ceil( getElementHealth( localPlayer )) 
    local ox = x/1000 
    if health then 
          dxDrawImage ( health*ox, 882, 2, 23, "data/line.png", angle, 0, -120 ) 
    end 
end 
addEventHandler("onClientRender", getRootElement(), HEALTH_line) 

Still found one misprint in previous codes.    

local healh = math.ceil( getElementHealth( player ))

line = guiCreateStaticImage(health*ox, 882, 2, 23, "data/line.png", false)

Where have you define "angle"?

State: Inactive

Posted
You are constantly creating a GUI image every render, that's a really bad idea and it won't even work.

Please, could you write me an example of a function similar to the one that I want to do, that I understand and forever decided for themselves the problem

Posted

* I will use guiCreateStaticImage

onClientRender is triggered with every frame, you'll be making 30-60 images per second. Use dxDrawImage or dxDrawImageSection.

If you wanna use GUI instead, create the image as the player is spawned or joins the server. Then use onClientPlayerDamage to update it.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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