addon format?

ive been trying to make a hud using animated vtf textures instead of drawing a (i dont know what to call it except the “hl2 health/ammo/battery box”) so i put it in addon format, its not showing up so im wondering if its because its in the form of an addon?

Show us the Lua file?

[lua]
local function inrange(val, low, high) --simple function to see if a value is inrange of two values
return val > low and val < high --return if the value is higher than the low, and lower than the high.
end

local client = LocalPlayer()
local c_health = 0
local c_weapon = nil

local mag_left = 0
local mag_extra = 0
local secondary_ammo = 0

local tohide = { --Since this is static, and always will be, there is no need to remake the table every frame
[“CHudHealth”] = true, – hide health
[“CHudBattery”] = true, – hide battery
[“CHudAmmo”] = true, – hide ammo count
[“CHudSecondaryAmmo”] = true – hide the secondary ammo count
}

hook.Add(‘ShouldDrawHud’, ‘zerohud.disableDefaultHud’, function(name)
return not tohide[name] --return the inverse of if we found the hud element in our table, eg. return inverse of true = false
end)

function zerohud()
if not IsValid(client) or not client:Alive() and not IsValid(c_weapon) then return end --combine the two if statements into one

c_health = client:Health() -- just telling whether 
c_weapon = client:GetActiveWeapon()

mag_left = c_weapon:Clip1()
mag_extra = client:GetAmmoCount(c_weapon:GetPrimaryAmmoType())
secondary_ammo = client:GetAmmoCount(c_weapon:GetSecondaryAmmoType())

if inrange(c_health, 0, 26) then
	surface.SetTexture('materials/VGUI/health/Health_danger') and sound.emit(
elseif inrange(c_health, 27, 100) then --check if the lower is 1 above the last high so there is no conflicts
	surface.SetTexture('materials/VGUI/health/Health_Fine')
end

draw.RoundedBox(3, 5, 5, 200, 100, Color(0, 0, 51, 255))

surface.SetDrawColor(Color(255, 255, 255, 255))
surface.DrawTexturedRect(0, 0, 8, 8)

end

hook.Add(“HUDPaint”, “zerohud.drawHud”, zerohud)
[/lua]

name it whatever with the .lua extension and put it in garrysmod/lua/autorun/client

It might not work and require something extra to be added to /server. but good luck

its still not working, its not giving me any errors or anything its just not showing up at all

Line 35
[lua]surface.SetTexture(‘materials/VGUI/health/Health_danger’) and sound.emit([/lua] and sound.emit( should output an error if your code is run. Look in the console, autorun runs pretty early, the error might be a bit hidden.

Also LocalPlayer() probably returns NULL when you’re calling it during code execution, store LocalPlayer and use client() or use LocalPlayer() directly into the function hook. (If LocalPlayer is NULL then the rest of HUDPaint won’t get called at all)

oh, i forgot to remove the sound emit, and how would i put that? i dont quite understand if you mean adding “client health (etc)” or what, im kind of confused

A better thing to do then what I suggested yesterday would probably be:
Change
[lua]if not IsValid(client) or not client:Alive() and not IsValid(c_weapon) then return end --combine the two if statements into one[/lua]
to
[lua]
if not client:IsValid() then client = LocalPlayer() return end – If the client is NULL, get a new instance of it
if not client:Alive() then return end – Client is dead, don’t draw the HUD
if c_weapon ~= client:GetActiveWeapon() then c_weapon = client:GetActiveWeapon() end – The last weapon doesn’t match the earlier active weapon, change it to that
if not ValidEntity(c_weapon) then return end – if the weapon is NULL or nil then the HUD should not be drawn.[/lua]
It’s kinda bad with that many if cases, but the only way to fix that is to alter your code very much.

thanks

BUMP, its still not working, ive looked through it and it seems fine. it just wont display the image

[LUA]
local function inrange(val, low, high) --simple function to see if a value is inrange of two values
return val > low and val < high --return if the value is higher than the low, and lower than the high.
end

local client = LocalPlayer() – making sure its the client
local c_health = 0
local c_weapon = nil

local mag_left = 0
local mag_extra = 0
local secondary_ammo = 0

local tohide = { --Since this is static, and always will be, there is no need to remake the table every frame
[“CHudHealth”] = true, – hide health
[“CHudBattery”] = true, – hide battery
[“CHudAmmo”] = true, – hide ammo count
[“CHudSecondaryAmmo”] = true – hide the secondary ammo count
}

hook.Add(‘ShouldDrawHud’, ‘zerohud.disableDefaultHud’, function(name) – add hook to function, just letting it know its added to the function
return not tohide[name] --return the inverse of if we found the hud element in our table, eg. return inverse of true = false
end)

function zerohud()

if not client:IsValid() then client = LocalPlayer() return end -- If the client is NULL, get a new instance of it
if not client:Alive() then return end -- Client is dead, don't draw the HUD
if c_weapon ~= client:GetActiveWeapon() then c_weapon = client:GetActiveWeapon() end -- The last weapon doesn't match the earlier active weapon, change it to that
if not ValidEntity(c_weapon) then return end -- if the weapon is NULL or nil then the HUD should not be drawn.

c_health = client:Health() -- telling it that the shortcut "c_health" is client health
c_weapon = client:GetActiveWeapon() -- shortcut "c_weapon" is active weapon
c_PrimaryAmmo = client:GetPrimaryAmmoType
mag_left = c_weapon:Clip1()
mag_extra = client:GetAmmoCount(c_weapon:GetPrimaryAmmoType())
secondary_ammo = client:GetAmmoCount(c_weapon:GetSecondaryAmmoType())

if inrange(c_health, 0, 26) then -- if within these health ranges, turn to danger
	surface.SetTexture('materials/VGUI/health/Health_danger')
elseif inrange(c_health, 27, 100) then --check if the lower is 1 above the last high so there is no conflicts
	surface.SetTexture('materials/VGUI/health/Health_Fine')
end --yay! end function, on to the weapon signs

draw.RoundedBox(3, 5, 5, 200, 100, Color(0, 0, 51, 255)) -- how big/where the box is

surface.SetDrawColor(Color(255, 255, 255, 255)) -- color for it
surface.DrawTexturedRect(0, 0, 8, 8)

[/LUA]

Oh right, I’m not quite sure why I didn’t see this earlier, but you’re using **[Surface.SetTexture

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Surface.SetTexture)** wrong, the parameter it takes is what **[Surface.GetTextureID

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Surface.GetTextureID)** returns. And that’s where you should supply the texture path & name.

Also:
Only call surface.GetTextureID outside of any think hook or only call it once, if you call it too many times things might start to get wrong and all textures & fonts in the game will mess up until you restart gmod.