Vice City HUD Weapon Icons problem

Hello there! I making hud styled like Vice City HUD, but sometimes i get errors and i think i does something wrong.

[ERROR] addons/vicecityhud/lua/autorun/vicecityhud.lua:168: Tried to use a NULL entity!
  1. GetClass - [C]:-1
   2. v - addons/vicecityhud/lua/autorun/vicecityhud.lua:168
    3. unknown - lua/includes/modules/hook.lua:84

168 stroke is:

hook.Add( "HUDPaint", "m1918", function()
    if not LocalPlayer():Alive() then return end
	if LocalPlayer():GetActiveWeapon():GetClass() == "m9k_m1918bar" then <- Exactly this is 168
	surface.SetDrawColor( 255, 255, 255, 255 )
	surface.SetMaterial( m1918 ) -- If you use Material, cache it!
	surface.DrawTexturedRect( 1770, 0, 130, 130 )
end )

HUD Screenshot

Am i doing something wrong?

[editline]24th August 2016[/editline]

Icon is working, but that error brokes sometimes hud

if (IsValid(LocalPlayer():GetActiveWeapon()) and (LocalPlayer():GetActiveWeapon():GetClass() == "m9k_m1918bar")) then 

I honestly think you’d be better off looking up your values from a table. For example:

weapon_data = {
    ["weapon_class"] = {
        x = 0,
        y = 0,
        w = 512,
        h = 256

and later

local wep = LocalPlayer():GetActiveWeapon()
if IsValid(wep) then 
    cl = wep:GetClass()
    --Use data from weapon_data[cl]

Damn! It’s works!! Thank you mate, i really love you!

[editline]24th August 2016[/editline]

Previous Coffee’s code works. I just need to check it on dedicated server

[editline]24th August 2016[/editline]

Yes, i checked and it’s works. Thanks to you Coffeee, and to TFA for your help, love you