• Help with HUD
    6 replies, posted
Ok, I'm trying to make a hud. It's not workin. It won't show up in GMod and it just uses the default HL2 HUD. Here's my code: [code] 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", "hidehud", hidehud) function myhud() local client = LocalPlayer() if !client:Alive() then return end // Don't draw the HUD if you're holding the camera or you're dead if(client:GetActiveWeapon() == NULL) or (client:GetActiveWeapon() == "gmod_camera") then return end // Make the fuckin font surface.CreateFont("coolvetica",32,400,true,false,"GTA") // Ammo shitz local mag_left = client:GetActiveWeapon():Clip1() local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) if mag_left == -1 then mag_left = 0 end draw.SimpleText( ..mag_left .. " " .. mag_extra, "GTA", ScrW()*0.85, ScrH()*0.1, Color(255,255,255,255)) draw.SimpleText("Secondary:"..secondary_ammo, "GTA", ScrW()*0.85, ScrH()*0.2, Color(88,88,88,255)) end hook.Add("HUDPaint", "myhud", myhud) [/code] Any help is appreciated.
[QUOTE=ThatzWatSheSed;24912689]Ok, I'm trying to make a hud. It's not workin. It won't show up in GMod and it just uses the default HL2 HUD. Here's my code: [code] 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", "hidehud", hidehud) function myhud() local client = LocalPlayer() if !client:Alive() then return end // Don't draw the HUD if you're holding the camera or you're dead if(client:GetActiveWeapon() == NULL) or (client:GetActiveWeapon() == "gmod_camera") then return end // Make the fuckin font surface.CreateFont("coolvetica",32,400,true,false,"GTA") // Ammo shitz local mag_left = client:GetActiveWeapon():Clip1() local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) if mag_left == -1 then mag_left = 0 end draw.SimpleText( ..mag_left .. " " .. mag_extra, "GTA", ScrW()*0.85, ScrH()*0.1, Color(255,255,255,255)) draw.SimpleText("Secondary:"..secondary_ammo, "GTA", ScrW()*0.85, ScrH()*0.2, Color(88,88,88,255)) end hook.Add("HUDPaint", "myhud", myhud) [/code] Any help is appreciated.[/QUOTE] Where exactly is it saying you're getting an error? Or is it just not running? Here is what I think might fix it: [lua] function GM:HUDPaint() self.BaseClass:HUDPaint() 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", "hidehud", hidehud) function myhud() local client = LocalPlayer() if !client:Alive() then return end // Don't draw the HUD if you're holding the camera or you're dead if(client:GetActiveWeapon() == NULL) or (client:GetActiveWeapon() == "gmod_camera") then return end // Make the fuckin font surface.CreateFont("coolvetica",32,400,true,false,"GTA") // Ammo shitz local mag_left = client:GetActiveWeapon():Clip1() local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) if mag_left == -1 then mag_left = 0 end draw.SimpleText( mag_left .. " " .. mag_extra, "GTA", ScrW()*0.85, ScrH()*0.1, Color(255,255,255,255)) draw.SimpleText("Secondary:"..secondary_ammo, "GTA", ScrW()*0.85, ScrH()*0.2, Color(88,88,88,255)) end hook.Add("HUDPaint", "myhud", myhud) [/lua]
I can see at least one syntax error. As it is a syntax error it should have crashed while loading up your server / joining a server. Haven't cheched the rest though, next time check your logs : draw.SimpleText( [highlight]..[/highlight]mag_left .. " " .. mag_extra, "GTA", ScrW()*0.85, ScrH()*0.1, Color(255,255,255,255) You placed a concatenation symbol from nothing with a string. Unaccounted some miscoded parts (like creating the font every frame as opposed to creating the font once) it should at least help the code running (not forcefully working well). Since it looks like an experimentation code and first code, let me remind you to check if your file is at least executed (= placed in the right lua folder for auto-execution).
Alright, thanks. I'll go change it and post if it works :)
snip
[QUOTE=H0rsey;24936001]snip[/QUOTE] Bump
Crash
Sorry, you need to Log In to post a reply to this thread.