If statement help

hey,

I am working on a HUD and within this HUD I have an if statement deciding whether to draw an infinity material if the gun doesn’t take ammo, but ammo if the gun uses it.

Currently I’m using this:


ply = LocalPlayer()
if LocalPlayer():GetActiveWeapon() == "keys" then
        surface.SetDrawColor(Color(255,255,255))
        surface.SetMaterial( ico10 )
        surface.DrawTexturedRect(50, ScrH() - 110, 32, 32) 
    elseif LocalPlayer():GetActiveWeapon() == "arrest_stick" then
        surface.SetDrawColor(Color(255,255,255))
        surface.SetMaterial( ico10 )
        surface.DrawTexturedRect(50, ScrH() - 110, 32, 32)
    elseif LocalPlayer():GetActiveWeapon() == "unarrest_stick" then
        surface.SetDrawColor(Color(255,255,255))
        surface.SetMaterial( ico10 )
        surface.DrawTexturedRect(50, ScrH() - 110, 32, 32)
    elseif LocalPlayer():GetActiveWeapon() == "weapon_troopermedkit" then
        surface.SetDrawColor(Color(255,255,255))
        surface.SetMaterial( ico10 )
        surface.DrawTexturedRect(50, ScrH() - 110, 32, 32)
    elseif LocalPlayer():GetActiveWeapon() == "weapon_medkitjedi" then
        surface.SetDrawColor(Color(255,255,255))
        surface.SetMaterial( ico10 )
        surface.DrawTexturedRect(50, ScrH() - 110, 32, 32)
    elseif LocalPlayer():GetActiveWeapon() == "weapon_camo" then
        surface.SetDrawColor(Color(255,255,255))
        surface.SetMaterial( ico10 )
        surface.DrawTexturedRect(50, ScrH() - 110, 32, 32)
	else
	    local ammoleft = LocalPlayer():GetActiveWeapon():Clip1()
        local totalammo = LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())
        surface.SetTextColor(255,255,255)
        surface.SetTextPos(35, ScrH() - 110)
        surface.SetFont("wchudf2")
        surface.DrawText(ammoleft)
        surface.DrawText("/")
        surface.DrawText(totalammo)
end

But it’s not seeming to work, just shows ammo instead, even when equipping one of those weapons (keys, arreststick, etc)
Basically, my question is; what do I use instead of


LocalPlayer():GetActiveWeapon() == "weaponnamehere"

simply check if it actually uses ammo? if it wont, its maxammo or so is set to -1 by default.

How would that be done?

Basic lua knowledge &

WEAPON/Ammo2,

WEAPON/Ammo1

Also having tons of if statements is bad, you should really look into tables.

:snip: WRONG
but,
you’re checking if the entity itself, not its classname, is equal to a certain string, which will never return true


LocalPlayer():GetActiveWeapon():GetClass() == "arrest_stick"

Also, all those elseif blocks are identical, why don’t you put all conditions in a single block, separated with “OR”. Or better, put all your weapons inside a table and check if it contains LocalPlayer():GetActiveWeapon():GetClass(). Anyway, if you just want to check if the weapon has no ammo, you better do what whitestar said.