Hud error

Hook ‘Hud’ Failed: [gamemodes\mw2\gamemode\cl_init.lua:180] attempt to call method ‘Clip1’ (a nil value)

Thats the error in console. Whats causing it and what do you need to figure out?

Post cl_init line 180. You may need to post 170-190.

We can’t help you without code but my guess is that you are not checking if a player has a weapon like

[lua]
local wep = LocalPlayer():GetActiveWeapon() --in our case you don’t have a weapon therefor it returns nil
local clip = wep:Clip1() --since wep is nil there is no metafunction therefor Clip1() is nil too ERROR
[/lua]

To fix it you gotta check if the weapon exists.

[lua]
local wep = LocalPlayer():GetActiveWeapon()
local clip
if (ValidEntity(wep) == true) then
clip = wep:Clip1()
end
[/lua]

Everything may not be true since you didn’t post the code.

Here is lines 170-190

[lua]local segmentdist = 360 / ( 2 * math.pi * math.max( scale.x, scale.y ) / 2 )

for a = 0, 180 - segmentdist, segmentdist do
    surface.DrawLine( center.x + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y - math.sin( math.rad( a + segmentdist ) ) * scale.y )
    surface.DrawLine( center.x+1 + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y+1 - math.sin( math.rad( a + segmentdist ) ) * scale.y )
    surface.DrawLine( center.x+2 + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y+2 - math.sin( math.rad( a + segmentdist ) ) * scale.y )
end

 //Ammo
local bulletNum = SWEP:Clip1()
   draw.SimpleText(bulletNum, "BANKGOTHIC2", ScrW()-185, ScrH() - 75, Color(200,200,200,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

 if bulletNum <=50  then
    for i = 1,bulletNum do 
        surface.DrawLine( ScrW()-200-i*5, ypos-5,ScrW()-200-i*5, ypos+10 )      
        surface.DrawLine( ScrW()-201-i*5, ypos-5,ScrW()-201-i*5, ypos+10 )  
        surface.DrawLine( ScrW()-202-i*5, ypos-5,ScrW()-202-i*5, ypos+10 )         
    end
else
  local max = LocalPlayer():GetActiveWeapon().Primary.ClipSize[/lua]

Check if SWEP is valid before calling Clip1() on it.

mmk hold on

He is using the MW2 HUD

code:
[lua]surface.CreateFont( “BankGothic Md BT”, 20, 400, 0, 0, “BANKGOTHIC”)
surface.CreateFont( “BankGothic Md BT”, 30, 400, 0, 0, “BANKGOTHIC2”)
triangletex = surface.GetTextureID( “gui/gradient” ) – t
local shouldDraw = true

local function HUDPaint()
if shouldDraw then
SWEP = LocalPlayer():GetActiveWeapon()
length = LocalPlayer():Health() *2
Alength = LocalPlayer():Armor() *2
ypos = ScrH() - 75
poly = { { },{ },{ },{} }

poly[1][“x”] = 150
poly[1][“y”] = ypos
poly[1][“u”] = 1
poly[1][“v”] = 0

poly[2][“x”] = length+150
poly[2][“y”] = ypos
poly[2][“u”] =0
poly[2][“v”] = 0

poly[3][“x”] = length + 175
poly[3][“y”] = ypos+15
poly[3][“u”] = 0
poly[3][“v”] = 0

poly[4][“x”] = 150
poly[4][“y”] = ypos+15
poly[4][“u”] =1
poly[4][“v”] = 1

poly2 = { { },{ },{ },{} }

poly2[1][“x”] = 150
poly2[1][“y”] = ypos+15
poly2[1][“u”] =1
poly2[1][“v”] = 0

poly2[2][“x”] = Alength+175
poly2[2][“y”] = ypos+15
poly2[2][“u”] =0
poly2[2][“v”] = 0

poly2[3][“x”] = Alength+150
poly2[3][“y”] = ypos+30
poly2[3][“u”] = 0
poly2[3][“v”] = 0

poly2[4][“x”] = 150
poly2[4][“y”] = ypos +30
poly2[4][“u”] =1
poly2[4][“v”] = 1

local QuadTable = {}

QuadTable.texture = surface.GetTextureID( “gmodLogo/logo” )
QuadTable.color= Color( 255, 255, 255, 255 )

QuadTable.x = 40
QuadTable.y = ScrH()-110
QuadTable.w = 75
QuadTable.h = 75
angles2 = Angle(0,0,0)
draw.TexturedQuad( QuadTable )
local CamData = {}
CamData.angles = Angle(90,90,0)
CamData.origin = Vector(LocalPlayer():GetPos().x,LocalPlayer():GetPos().y,512)
CamData.x = 10
CamData.y = 10
CamData.w = 200
CamData.h = 200
render.RenderView( CamData )

surface.SetTexture( triangletex ) --set the texture of the triangle
surface.SetDrawColor( 255, 50, 50, 255 ) --set the additive color
surface.DrawPoly( poly ) --draw the triangle with our triangle table
surface.SetDrawColor( 50, 50, 255, 255 ) --set the additive color
surface.DrawPoly( poly2 ) --draw the triangle with our triangle table
surface.SetDrawColor( 200, 200, 200, 255 ) --set the additive color
surface.DrawLine( 150, ypos+14,400, ypos+14 )
surface.DrawLine( 150, ypos+15,400, ypos+15 )
surface.DrawLine( 150, ypos+16,400, ypos+16 )
surface.DrawLine( ScrW()-450, ypos+14,ScrW()-150, ypos+14 )
surface.DrawLine( ScrW()-450, ypos+15,ScrW()-150, ypos+15 )
surface.DrawLine( ScrW()-450, ypos+16,ScrW()-150, ypos+16 )
draw.SimpleText(LocalPlayer():Health(), "BANKGOTHIC", 170, ScrH() - 70, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.SimpleText(LocalPlayer():Armor(), "BANKGOTHIC", 170, ScrH() - 50, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.SimpleText(string.ToMinutesSeconds( CurTime()), "BANKGOTHIC", 80, ScrH() - 150, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

local center = Vector( 75, ScrH()-60, 0 )
local scale = Vector( 75, 75, 0 )
local segmentdist = 360 / ( 2 * math.pi * math.max( scale.x, scale.y ) / 2 )
surface.SetDrawColor( 200, 200, 200, 255 )

 for a = 0, 130 - segmentdist, segmentdist do
    surface.DrawLine( center.x + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y - math.sin( math.rad( a + segmentdist ) ) * scale.y )
    surface.DrawLine( center.x+1 + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y+1 - math.sin( math.rad( a + segmentdist ) ) * scale.y )
    surface.DrawLine( center.x+2 + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y+2 - math.sin( math.rad( a + segmentdist ) ) * scale.y )
end

 local center = Vector( ScrW()-75, ScrH()-60, 0 )
local scale = Vector( 75, 75, 0 )
local segmentdist = 360 / ( 2 * math.pi * math.max( scale.x, scale.y ) / 2 )


for a = 0, 180 - segmentdist, segmentdist do
    surface.DrawLine( center.x + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y - math.sin( math.rad( a + segmentdist ) ) * scale.y )
    surface.DrawLine( center.x+1 + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y+1 - math.sin( math.rad( a + segmentdist ) ) * scale.y )
    surface.DrawLine( center.x+2 + math.cos( math.rad( a ) ) * scale.x, center.y - math.sin( math.rad( a ) ) * scale.y, center.x + math.cos( math.rad( a + segmentdist ) ) * scale.x, center.y+2 - math.sin( math.rad( a + segmentdist ) ) * scale.y )
end

 //Ammo
local bulletNum = SWEP:Clip1()
   draw.SimpleText(bulletNum, "BANKGOTHIC2", ScrW()-185, ScrH() - 75, Color(200,200,200,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

 if bulletNum <=50  then
    for i = 1,bulletNum do 
        surface.DrawLine( ScrW()-200-i*5, ypos-5,ScrW()-200-i*5, ypos+10 )      
        surface.DrawLine( ScrW()-201-i*5, ypos-5,ScrW()-201-i*5, ypos+10 )  
        surface.DrawLine( ScrW()-202-i*5, ypos-5,ScrW()-202-i*5, ypos+10 )         
    end
else
  local max = LocalPlayer():GetActiveWeapon().Primary.ClipSize
   local BarLength = (bulletNum*240)/max
    surface.DrawRect(ScrW()-210-BarLength, ypos-5, BarLength, 15 )  
end 

end
end
hook.Add(“HUDPaint”,“Hud”, HUDPaint)

function hidehud(name)
if shouldDraw then
for k, v in pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)
function toggleCodHud()
shouldDraw = not shouldDraw
end
concommand.Add(“toggleCodHud”,toggleCodHud)[/lua]

Err… we already have 170-190 which is all we need.

Also, @ Fat Panda, this might fix it. (or break it D:)



     //Ammo
	if Entity:IsWeapon() then
		local bulletNum = SWEP:Clip1()
			draw.SimpleText(bulletNum, "BANKGOTHIC2", ScrW()-185, ScrH() - 75, Color(200,200,200,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)


IsWeapon() is a entity metatable function so it won’t work since SWEP is nil.

True. I’m a retard.

I fixed it… But now i get this error

@lua\includes\util.lua:23] bad argument #1 to ‘min’ (number expected, got nil)
[gamemodes\mw2\gamemode\cl_init.lua:66] attempt to call method ‘GetActiveWeapon’ (a nil value)

this is line 66 [lua] local wep = LocalPlayer():GetActiveWeapon() local clip [/lua]