Hi, i would like to make an HUD that looks like this
https://imgur.com/jOn3WVG
I am the one that made it but without ScrW and ScrH, The only problem, is, i am confused. in 1600 x 900 resolution the right box is well placed, and in 1080p the box is in the 3/4 of the screen. I am so confused to make it work...
Here is the kinda code i tried...
local function Base()
draw.RoundedBox(6, 10, ScrH() - 135, 325, 125, Color(0,0,0,200)) --Boite Gauche
draw.RoundedBox(6, ScrW() * 0.5 + 465, ScrH() - 135, 325, 125, Color(0,0,0,200)) --Boite Droite
draw.RoundedBox(0, 10, ScrH() - 50, 325, 5, Color(255,0,0,255)) --Background Vie
draw.RoundedBox(0, 10, ScrW() * 0.5 2, 325, 5, Color(255,255,255,255)) --Background Énergie (faim)
local DrawHealth = LocalPlayer():Health() or 0
local EchoHealth = LocalPlayer():Health() or 0
local DrawEnergy = LocalPlayer():( "Energy" ) or 0
local DrawName = LocalPlayer():( "rpname" )
local DrawMoney = DarkRP.formatMoney (LocalPlayer():( "money" ))
local DrawJob = LocalPlayer():("job")
if DrawHealth > 100 then DrawHealth = 100 end
if DrawHealth < 0 then DrawHealth = 0 end
if DrawHealth != 0 then
draw.RoundedBox(0, 10, ScrH() - 65, (325) * DrawHealth / 100, 5, Color(0,255,0,255))
end
draw.DrawText(DrawName,"Trebuchet24", 175, ScrH() - 115, Color(255,255,255), TEXT_ALIGN_CENTER)
draw.DrawText(DrawMoney..("€"), "Trebuchet24", 1725, 960, Color(255,255,255,255), TEXT_ALIGN_CENTER)
draw.DrawText(DrawJob,"Trebuchet24", 175, ScrH() - 50, Color(255,255,255), TEXT_ALIGN_CENTER)
end
Don't laugh at me... im still learning...
And the HUD dosen't load on server startup.
And last thing, i get this error
[ERROR] lua/includes/modules/draw.lua:141: bad argument #1 to 'gmatch' (string expected, got nil)
That's because your screen scale is a tad weird. What you want to do is take the height of the resolution the game is currently running at and divide it by the height of the resolution your game was running at when you made the HUD. That gives you your screen scale factor. Save it as a variable at the top of your file for time saving and so the calculation doesn't have to be done every frame multiple times.
local SS = ScrH() / 900
And in your width and height sections for your draw functions you want to times the pixel size amount by your screen scale factor like so
draw.RoundedBox( 4, 797 * SS, 458 * SS, 6 * SS, 25 * SS, Color(255,255,255,255) )
As for the other error you are seeing its giving the error that is happening in draw.lua but not in your hud code so you are going to need to post the full error.
So now if i place it using your settings, every resolutions should see it? and for the error this is the full one
[ERROR] lua/includes/modules/draw.lua:141: bad argument #1 to 'gmatch' (string expected, got nil)
1. gmatch - [C]:-1
2. DrawText - lua/includes/modules/draw.lua:141
3. Base - addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hud.lua:21
4. fn - addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hud.lua:297
5. unknown - addons/ulib/lua/ulib/shared/hook.lua:110
It should yes but you'll probably have to do quite a bit of tweaking with the values you currently have. As for your error one of the variables you are trying to pass through to drawtext is nil meaning its not returning a value. The error is happening on line 214 in your hud file so what ever variable is being passed to that drawtext function is the issue.
The placement part is going SOOOO much better, can't wait to test other resolutions cause it's been 4 files i had to try, and for the error, i fixed the other lines but there is one that "pisses" me off...
[ERROR] lua/includes/modules/draw.lua:141: bad argument #1 to 'gmatch' (string expected, got nil)
1. gmatch - [C]:-1
2. DrawText - lua/includes/modules/draw.lua:141
3. Base - addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hud.lua:30
4. fn - addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hud.lua:306
5. unknown - addons/ulib/lua/ulib/shared/hook.lua:110
As i see it's on line 306, but on it it's Base()... why does it do that? The other ones are fixed by the way,
Whats on line 304 of cl_hud.lua?
i posted line 302 to 304
function DrawHUD()
localplayer = localplayer and IsValid(localplayer) and localplayer or LocalPlayer()
if not IsValid(localplayer) then return end
The error is still the same thing. A nil variable is being passed to drawtext.
It’s weird cause there is no text involved in the lines 302 to 304... i will try something maybe i need to remove Base()?
Could you upload that whole file to paste bin. Would be a lot easier to take a look at.
cl_hud.lua Here
What I would do is use print() to output to console all of the variables that you are passing to drawtext and see what one is returning nil
I don't follow you, what do i need to write in console? cause i typed print() and it says unknown command, both client and server
My bad I should of given an example. print is a default function that prints things into the console. So you would put it in your code like so
local DrawHealth = LocalPlayer():Health() or 0
local EchoHealth = LocalPlayer():Health() or 0
local DrawEnergy = LocalPlayer():( "Energy" ) or 0
local DrawName = LocalPlayer():( "rpname" )
local DrawMoney = DarkRP.formatMoney (LocalPlayer():( "money" ))
local DrawJob = LocalPlayer():("job")
print(DrawHealth)
print(DrawEnergy)
print(DrawName)
print(DrawMoney)
print(DrawJob)
You would just put those print statements under your variable definitions. It will print those values into the console for every frame it draws the HUD. They will print in the exact order you list them in the code and what ever one prints nil is the one causing the issue.
Sorry, you need to Log In to post a reply to this thread.