Dzsozi (h03) Posted March 10, 2014 Share Posted March 10, 2014 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 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. 1 Link to comment
Hell-Mate Posted March 10, 2014 Share Posted March 10, 2014 screenX,screenY = guiGetScreenSize() Link to comment
Moderators Citizen Posted March 10, 2014 Moderators Share Posted March 10, 2014 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
Hell-Mate Posted March 10, 2014 Share Posted March 10, 2014 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
Dzsozi (h03) Posted March 10, 2014 Author Share Posted March 10, 2014 Here is my resouliton, it's 1680x1050, and as you can see it fits correctly: Link to comment
Dzsozi (h03) Posted March 10, 2014 Author Share Posted March 10, 2014 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
Hell-Mate Posted March 10, 2014 Share Posted March 10, 2014 i just wrote it because u didnt mention. but if u wrote it then the script is okay and it will fit correctly with any resolution. Link to comment
Moderators Citizen Posted March 10, 2014 Moderators Share Posted March 10, 2014 really ? he didnt define screenX and screenY .. He obviously did, but somewhere else in his code. Otherwise he wouldn't be able to take a screenshot ... Link to comment
Hell-Mate Posted March 10, 2014 Share Posted March 10, 2014 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
Karuzo Posted March 10, 2014 Share Posted March 10, 2014 Well he used screenX and screenY, so yeah, you could think that he used it. Link to comment
Hell-Mate Posted March 10, 2014 Share Posted March 10, 2014 Well he used screenX and screenY, so yeah, you could think that he used it. He didnt mentioned it. thats why i just posted the line !! is there is problem with my post guys !!??? Link to comment
Dzsozi (h03) Posted March 10, 2014 Author Share Posted March 10, 2014 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. Link to comment
Hell-Mate Posted March 10, 2014 Share Posted March 10, 2014 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 Citizen Posted March 10, 2014 Moderators Share Posted March 10, 2014 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 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
Dzsozi (h03) Posted March 10, 2014 Author Share Posted March 10, 2014 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 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 Citizen Posted March 10, 2014 Moderators Share Posted March 10, 2014 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
Dzsozi (h03) Posted March 10, 2014 Author Share Posted March 10, 2014 (edited) Here's another picture of the buggy hp bar: It's 1360x768 resolution Edited March 10, 2014 by Guest Link to comment
Dzsozi (h03) Posted March 10, 2014 Author Share Posted March 10, 2014 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 Citizen Posted March 10, 2014 Moderators Share Posted March 10, 2014 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
Moderators IIYAMA Posted March 11, 2014 Moderators Share Posted March 11, 2014 P.s: Enable this: dxSetAspectRatioAdjustmentEnabled (true) Recommended when you are going to draw things near the hud. See wiki sample how to use it. https://wiki.multitheftauto.com/wiki/Dx ... entEnabled Every player can adjust their hud ratio, this will fix that. Link to comment
Dzsozi (h03) Posted March 11, 2014 Author Share Posted March 11, 2014 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 Citizen Posted March 11, 2014 Moderators Share Posted March 11, 2014 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
Dzsozi (h03) Posted March 11, 2014 Author Share Posted March 11, 2014 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. Link to comment
Dzsozi (h03) Posted March 11, 2014 Author Share Posted March 11, 2014 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 Citizen Posted March 11, 2014 Moderators Share Posted March 11, 2014 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
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