So I'm trying to make a custom HUD for Gmod and I'm trying to do something but it wont work,
I wanna make it so that when your health goes below 100 it moves a bit to the right to eliminate the space left and move even more when its below 10
One way i thought it would work was to replace a variable instead of a number but I need help to actually do it.
Heres part of the code I want to change.
I want to replace the 122 with the changing variable.
draw.SimpleText( math.Clamp( health, 0, 999 ), "Text1", 122, ScrH() - 52 - 40, Color(255,255,255,255) )
Maybe you wanna see this
https://www.youtube.com/watch?v=UK-9ZRpBkLs
I already saw it and it doesnt explain anything about hiding changing hud color or even hiding hud on death, just hud creation.
what are you even trying to do exacly? i dont know what you mean with moving the object more to the right...
Basically, I want a variable that changes valuable (say from 1 to 2 to 3) depending on the health.
For example
if health more than 90, set [variable] to 1
if health less than 90 but higher than 10, then set [variable] to 2
if health less than 10 set [variable] to 3
if health == 100 then
draw.SimpleText( health, "Text1", x+10, ScrH() - 52 - 40, Color(255,255,255,255) )
else
draw.SimpleText( health, "Text1", x, ScrH() - 52 - 40,Color(255,255,255,255) )
end
your code :
draw.SimpleText( math.Clamp( health, 0, 999 ), "Text1", 122, ScrH() - 52 - 40, Color(255,255,255,255) )
x = 122 -- Because in your code u set the x pos 122.
fix me if you are meaning to another thing.
Yea that code is the goal i'm aiming for but that specifically doesnt work, if i put it with the variables I want it shows this error in the console:
[ERROR] addons/fritz_hud/lua/autorun/client/fritzhud.lua:27: '=' expected near 'HPP'
1. unknown - addons/fritz_hud/lua/autorun/client/fritzhud.lua:0
it's necessary for us to see your code...Otherwise expect vague responses/no responses at all
Oh sorry,
heres the current one with the previous thing added to it, you can see i replaced the 122 with the variable at the second draw.SimpleText
function hud()
local health = LocalPlayer():Health()
draw.RoundedBox(0, 78, 635, 150, 20, Color(255,0,0,255))
draw.RoundedBox(0, 78, ScrH() - 45 - 20, health*1.5, 20, Color(0,255,0,255))
draw.SimpleText("/100", "Text1", 170, ScrH() - 52 - 40, Color(255,255,255,255) )
draw.SimpleText( math.Clamp( health, 0, 999 ), "Text1", HPP, ScrH() - 52 - 40, Color(255,255,255,255) )
draw.SimpleText("HP", "Text2", 48, ScrH() - 27 - 45, Color(255,255,255,255))
end
hook.Add("HUDPaint", "FritzHud", hud)
if health > 90 then
set HPP to 1
elseif health < 90 and health > 10 then
set HPP to 2
elseif health < 10 then
set HPP to 3
end
function hidehud(name)
for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw", "Fritzhud", hidehud)
surface.CreateFont( "Text1", {
font = "Determination Mono",
extended = false,
size = 30,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
surface.CreateFont( "Text2", {
font = "Determination Mono",
extended = false,
size = 28,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
You cannot "set" HHP to an integer like that. I assume that HPP is a local varaiable:
function hud()
local health, HPP = LocalPlayer():Health()
draw.RoundedBox(0, 78, 635, 150, 20, Color(255,0,0,255))
draw.RoundedBox(0, 78, ScrH() - 45 - 20, health*1.5, 20, Color(0,255,0,255))
draw.SimpleText("/100", "Text1", 170, ScrH() - 52 - 40, Color(255,255,255,255) )
draw.SimpleText( math.Clamp( health, 0, 999 ), "Text1", HPP, ScrH() - 52 - 40, Color(255,255,255,255) )
draw.SimpleText("HP", "Text2", 48, ScrH() - 27 - 45, Color(255,255,255,255))
if health > 90 then
HPP = 1
elseif health < 90 and health > 10 then
HPP = 2
elseif health < 10 then
HPP = 3
end
end
Othrwise instead if "HPP = <some integer>" needs to be used as convar, just run RunConsoleCommand("HPP", <some integer>)
I'd like to store it as a local variable so it doesn't interfere with other addons. so since its local, do i need to put LOCAL HPP or still just HPP
Sorry, you need to Log In to post a reply to this thread.