iPanda Posted January 18, 2014 Posted January 18, 2014 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.
xXMADEXx Posted January 18, 2014 Posted January 18, 2014 health and ox are never being updated. You need to define the in the render function too.
iPanda Posted January 18, 2014 Author Posted January 18, 2014 (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 January 18, 2014 by Guest
Karuzo Posted January 18, 2014 Posted January 18, 2014 Well , he has to update the health of the player, otherwise it would be 100% only.
xXMADEXx Posted January 18, 2014 Posted January 18, 2014 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)
iPanda Posted January 18, 2014 Author Posted January 18, 2014 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.
xXMADEXx Posted January 18, 2014 Posted January 18, 2014 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.
iPanda Posted January 18, 2014 Author Posted January 18, 2014 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?
Memory Posted January 18, 2014 Posted January 18, 2014 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)
xXMADEXx Posted January 18, 2014 Posted January 18, 2014 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.
iPanda Posted January 18, 2014 Author Posted January 18, 2014 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)
Memory Posted January 18, 2014 Posted January 18, 2014 I think that I understood problem but now I wrote through phone. I will write tomorrow.
Castillo Posted January 18, 2014 Posted January 18, 2014 You are constantly creating a GUI image every render, that's a really bad idea and it won't even work.
Memory Posted January 19, 2014 Posted January 19, 2014 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)
iPanda Posted January 19, 2014 Author Posted January 19, 2014 (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 .... .... * I will use guiCreateStaticImage Edited January 19, 2014 by Guest
Sasu Posted January 19, 2014 Posted January 19, 2014 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"?
iPanda Posted January 21, 2014 Author Posted January 21, 2014 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
Dealman Posted January 21, 2014 Posted January 21, 2014 * 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.
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