• Hud wont show my box
    9 replies, posted
This is the code for my hud when I am ingame there is nothing there it is just a plain screen and I dont know why [CODE] function myhud() local client = LocalPlayer() if not client:Alive() then return end if (client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255)) draw.SimpleText(client:Health() .. "%", "ScoreboardText", 100, 50, Color(86, 104, 86, 255), 0, 0) local mag_left = client:GetActiveWeapon():Clip1() local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) end hook.Add("HUDPaint", "myhud", myhud) local tohide = { -- This is a table where the keys are the HUD items to hide ["CHudHealth"] = true, ["CHudBattery"] = true, ["CHudAmmo"] = true, ["CHudSecondaryAmmo"] = true } local function HUDShouldDraw(name) if (tohide[name]) then return false; end end hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw) hook.Add("HUDPaint", "myhud", myhud) local tohide = { ["CHudHealth"] = true, ["CHudBattery"] = true, ["CHudAmmo"] = true, ["CHudSecondaryAmmo"] = true } local function HUDShouldDraw(name) if (tohide[name]) then return false; end end hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw)[/CODE]
Where do you have the file located? It has to be in your "lua/autorun/client" directory, unless you are doing something with a gamemode.
The files are in the right place but it doesn't show anything on my screen like any boxes , or traces of anything
What gamemode is this for though?
Its just for practice I have it in garrysmod/lua/autorun/client so it will use it for sandbox but when I start the single player game there it no Hud and I don't get any errors so I dont know why
It probably isn't running because there's an error or 7. There's a lot of things wrong with this code. I'm assuming you should be getting a "tried to compare entity with nil" or maybe with string error.
[B]Your code.[/B] I added in some comments to tell you what you are doing wrong. [code] function myhud() local client = LocalPlayer() if not client:Alive() then return end if (client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end -- Don't use "NULL", Lua uses "nil" draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255)) -- Try to space your code properly, makes it easier to read, and easier to edit. draw.SimpleText(client:Health() .. "%", "ScoreboardText", 100, 50, Color(86, 104, 86, 255), 0, 0) local mag_left = client:GetActiveWeapon():Clip1() local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) -- I assume you will use these later. local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) end hook.Add("HUDPaint", "myhud", myhud) -- The FIRST HUDPaint hook. local tohide = { -- This is a table where the keys are the HUD items to hide ["CHudHealth"] = true, ["CHudBattery"] = true, ["CHudAmmo"] = true, ["CHudSecondaryAmmo"] = true } local function HUDShouldDraw(name) if (tohide[name]) then return false; end end hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw) -- Your FIRST HUDShouldDraw hook. hook.Add("HUDPaint", "myhud", myhud) -- the SECOND HUDPaint hook. You will only need 1, since you are basically hooking the same function twice. Potentially why your shit ain't working. local tohide = { ["CHudHealth"] = true, ["CHudBattery"] = true, ["CHudAmmo"] = true, ["CHudSecondaryAmmo"] = true } local function HUDShouldDraw(name) if (tohide[name]) then return false; end end hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw) -- Your SECOND HUDShouldDraw hook. YOU ONLY NEED ONE. [/code] [B]I reworked your code.[/B] [code] function myhud() local client = LocalPlayer() if not client:Alive() then return end if (client:GetActiveWeapon() == nil or client:GetActiveWeapon() == "Camera") then return end draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255)) draw.SimpleText(client:Health() .. "%", "ScoreboardText", 100, 50, Color(86, 104, 86, 255), 0, 0) local mag_left = client:GetActiveWeapon():Clip1() local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) end hook.Add("HUDPaint", "myhud", myhud) local tohide = { -- This is a table where the keys are the HUD items to hide ["CHudHealth"] = true, ["CHudBattery"] = true, ["CHudAmmo"] = true, ["CHudSecondaryAmmo"] = true } local function HUDShouldDraw(name) if (tohide[name]) then return false; end end hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw) [/code]
Ok now I get this error and they just keep popping up [ERROR] lua/autorun/client/cl_hud.lua:8: attempt to index global 'client' (a nil value) 1. unknown - lua/autorun/client/cl_hud.lua:8 Here is my code [CODE]draw.SimpleText(client:Health() .. "%", "default", 100, 50, Color(86, 104, 86, 255), 0, 0)[/CODE]
Replace client with LocalPlayer()
I give up, you are useless. edit: All it takes is a simple google search, you don't need the whole populous of FP to see your lack of simple LUA, Learn from this #1 : [URL]http://www.lua.org/manual/5.1/[/URL] Learn from this #2 : [URL]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7a06.html[/URL]
Sorry, you need to Log In to post a reply to this thread.