Okay I tried the Lua Tutorial on the Gmod Wiki for a simple HUD but no matter what I do it doesn't seem to work. Can anyone help me?
Heres the code
[lua]function district9hud
local client = LocalPlayer()
if !client:Alive() then return end
if(client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end
draw.RoundedBox(3, 5, 5, 200, 100, Color (13, 13, 189, 255), 0, 0)
local mage_left = client:GetActiveWeapon ():Clipl()
local mage_extra = client:GetAmmoCount (client:GetActiveWeapon():GetPrimaryAmmoType())
local secondary_ammo = client:GetAmmoCount (client:GetActiveWeapon():GetsecondaryAmmotype())
end
hook.Add("HUDPaint", "district9hud", district9hud)
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", "district9hud", district9hud)[/lua]
[lua]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", "district9hud", district9hud)[/lua]
Where did the district9hud come from? It isn't even in the hidehud function :frogdowns:
Well, firstly you need to have the second hook.Add add the hide HUD function, not the district9hud function. Then secondly, all your HUD is doing is drawing a rounded box.
why did you change the variables >.>? and don't use this tutorial ([url]http://wiki.garrysmod.com/?title=How_to:_HUD[/url]).
It's bad.
[editline]27th November 2010[/editline]
[url]http://wiki.garrysmod.com/?title=Creating_a_HUD[/url]
You're also missing a () after your function name.
[QUOTE=Jova;26327580]why did you change the variables >.>? and don't use this tutorial ([url]http://wiki.garrysmod.com/?title=How_to:_HUD[/url]).
It's bad.
[editline]27th November 2010[/editline]
[url]http://wiki.garrysmod.com/?title=Creating_a_HUD[/url][/QUOTE]
I tried that one already, and it didn't work I wanted a simplified tutorial not one that was freaking complicated as hell. I am somewhat new to lua coding, and I am also learning the visual basic language in school so its not my fault I DIDN'T KNOW.
[editline]27th November 2010[/editline]
[QUOTE=Kaleb;26325924][lua]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", "district9hud", district9hud)[/lua]
Where did the district9hud come from? It isn't even in the hidehud function :frogdowns:[/QUOTE]
Thats what it said to do in the tutorial.
download some random hud from [url]www.garrysmod.org[/url] and see how its made.
[QUOTE=blown25;26346118]download some random hud from [url]www.garrysmod.org[/url] and see how its made.[/QUOTE]
Isn't that against the rules though? Besides I want a tutorial so I can learn how to make my own and then improve on it.
"See how it's made" = tutorial.
[QUOTE=TheFallen(TF2);26346299]Isn't that against the rules though? Besides I want a tutorial so I can learn how to make my own and then improve on it.[/QUOTE]
Looking how something was coded isn't against the rules, since the author expected this when he released it. Using the code in your work and claiming you made / not giving credit is not allowed though.
[QUOTE=Lord Ned;26346336]"See how it's made" = tutorial.[/QUOTE]
Alright, fine.
[editline]27th November 2010[/editline]
[QUOTE=_nonSENSE;26346360]Looking how something was coded isn't against the rules, since the author expected this when he released it. Using the code in your work and claiming you made / not giving credit is not allowed though.[/QUOTE]
Oh...okay.
Since when were there rules? Do what you can to learn, different things works for different people.
There are forum rules, but something like that is more a question of ethics and morals.
Nothing says you cant copy code (unless theres some form of copywrite protection on it) other than people just calling you a dick for doing it.
Going to borrow this thread since it's on the same topic;
[lua]function HideHudBits( name )
for k, v in pairs {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo" } do
print("yeah")
if name == v then return false end
end
print("Hiding hud bits")
end
hook.Add( "HudShouldDraw", "HideHudBits", HideHudBits )[/lua]
This doesn't do anything at all. The print statement ("hiding hud bits") doesn't get called at all.
It's a Fretta gamemode if it makes a difference. The rest of the stuff in that lua file does get called.
"HudShouldDraw" != "HUDShouldDraw"
Sigh, I knew it was something simple. Thanks. :P
Okay I'm back, and I have good news and bad news, good news is I found a tutorial on youtube, bad news is that the hud isn't working.
Here is the code:
[lua]function hidehud(name)
for k, v in pairs ("CHudHealth", "CHudBattery") do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw","hidehud",hidehud)
function GM:HUDPaint()
self.BaseClass:HUDPaint()
local person = LocalPlayer()
local Health = LocalPlayer(): Health()
surface.CreateFont("D9 non-humans",54, 400, false, false, "district9")
surface.SetText( 255, 0, 0, 240 )
surface.SetTextPos( 34,ScrH()/2)+(ScrH()/4) )
surface.SetFont("district9")
surface.DrawText( Health )
end[/lua]
Which part doesn't work? Does it hide the original hud but not draw your own?
OH NOES!
Don't create a new font every frame, that's bad.
Put it outside your function; you might have to encase it in an if CLIENT block, but don't do it every frame.
Also are you getting any errors?
[editline]28th November 2010[/editline]
Also is "D9 non-humans" a legit font you downloaded or something?
[QUOTE=Feihc;26368082]OH NOES!
Don't create a new font every frame, that's bad.
Put it outside your function; you might have to encase it in an if CLIENT block, but don't do it every frame.
Also are you getting any errors?
[editline]28th November 2010[/editline]
Also is "D9 non-humans" a legit font you downloaded or something?[/QUOTE]
I got it from here: [url]http://www.mnuspreadslies.com/[/url]
[editline]28th November 2010[/editline]
[QUOTE=Lord Ned;26367783]Which part doesn't work? Does it hide the original hud but not draw your own?[/QUOTE]
It didn't hide the original HUD and it didn't freaking draw the new one.
Well, the font's filename is "D9 non-humans.ttf", but the actual font name also seems to be "D9 non-humans".
Try using:
[lua]surface.CreateFont( "coolvetica", 32, 500, true, false, "Text32") --FONT[/lua]
And then do "Text32' as your font (So surface.SetFont("Text32"))
Also change:
[lua] for k, v in pairs ("CHudHealth", "CHudBattery") do[/lua]
to
[lua] for k, v in pairs {"CHudHealth", "CHudBattery"} do[/lua]
[QUOTE=Lord Ned;26368576]Well, the font's filename is "D9 non-humans.ttf", but the actual font name also seems to be "D9 non-humans".
Try using:
[lua]surface.CreateFont( "coolvetica", 32, 500, true, false, "Text32") --FONT[/lua]
And then do "Text32' as your font (So surface.SetFont("Text32"))
Also change:
[lua] for k, v in pairs ("CHudHealth", "CHudBattery") do[/lua]
to
[lua] for k, v in pairs {"CHudHealth", "CHudBattery"} do[/lua][/QUOTE]
I'll try that and see if that works.
Don't both with a for loop if you dont have to
[lua]
if name == "CHudHealth" or name == "CHudBattery" then return false end[/lua]
[QUOTE=Feihc;26368873]Don't both with a for loop if you dont have to
[lua]
if name == "CHudHealth" or name == "CHudBattery" then return false end[/lua][/QUOTE]
Okay, I tried that and it didn't work but I want to ask one simple question where do I put the file?! in Autorun/client or somewhere else?
Well that depends if you need to send data from the server or not. If you don't need anything from the server, then put it in autorun/client.
[QUOTE=Feihc;26369670]Well that depends if you need to send data from the server or not. If you don't need anything from the server, then put it in autorun/client.[/QUOTE]
Okay, then I don't know whats causing the problem, I really want to get this to work because I want to make a District 9 Themed HUD for Garry's Mod and eventually a Bionicle Themed one. Could the problem be with the game itself or the way I coded it?
If this is a server, put this in lua/autorun/client/cl_hud_remove.lua
[lua]function hidehud(name)
for k, v in pairs ("CHudHealth", "CHudBattery") do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw","hidehud",hidehud)[/lua]
then make a file in lua/autorun/server/sv_hud_remove.lua
[lua]AddCSLuaFile("autorun/client/cl_hud_remove.lua")[/lua]
If you're doing this on the client, put it in the client autorun only.
If that doesn't work, then yo have a conflicting addon
[QUOTE=Banana Lord.;26372147]If this is a server, put this in lua/autorun/client/cl_hud_remove.lua
[lua]function hidehud(name)
for k, v in pairs ("CHudHealth", "CHudBattery") do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw","hidehud",hidehud)[/lua]
then make a file in lua/autorun/server/sv_hud_remove.lua
[lua]AddCSLuaFile("autorun/client/cl_hud_remove.lua")[/lua]
If you're doing this on the client, put it in the client autorun only.
If that doesn't work, then yo have a conflicting addon[/QUOTE]
Wait I don't understand do I make a new file with this in it:
[lua]function hidehud(name)
for k, v in pairs ("CHudHealth", "CHudBattery") do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw","hidehud",hidehud)[/lua]
and add this to my code:
[lua]AddCSLuaFile("autorun/client/cl_hud_remove.lua")[/lua]
or do I just add the string above to my code and see if that works?
No, the first code goes in 1 file in autorun/client, the second in a file in autorun/server
[QUOTE=Banana Lord.;26373580]No, the first code goes in 1 file in autorun/client, the second in a file in autorun/server[/QUOTE]
Ah okay.
Sorry, you need to Log In to post a reply to this thread.