I can not seem to get ammo to work on my custom hud.
Here is my code to add ammo:
[QUOTE] --Weapons and stuff
local function Ammo()
if client:GetActiveWeapon() != NULL then
if client:GetActiveWeapon():Clip1() != -1 then
if client:GetActiveWeapon():GetPrintName() != "#HL2_GravityGun" then
draw.RoundedBox(8, -210, -70, 200, 50, Color(0,0,0,150))
--Clip
draw.SimpleText(client:GetActiveWeapon():Clip1(),"eclipse",-210 + 80, - 70 + 3, Color(255,255,0,255),2,0)
--Extra
draw.SimpleText(client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()),"eclipse",-210 + 90, - 70, Color(255,255,0,255),0,0)
--Ammo bar
if client:GetActiveWeapon().Primary != nil then
draw.RoundedBox(6, -210 + 85, - 70 + 25, 105, 15, Color(0,0,0,150))
if client:GetActiveWeapon():Clip1() > 0 then
draw.RoundedBox(6, -210 + 85, - 70 + 25, (client:GetActiveWeapon():Clip1()*105)/client:GetActiveWeapon().Primary.ClipSize, 15, Color(255,255,0,255))
end
end
end
else
if client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) != 0 then
draw.RoundedBox(8, -210, - 70, 60, 50, Color(0,0,0,150))
draw.SimpleText(client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()),"eclipse",-210 + 50, - 70, Color(255,255,0,255),2,0)
end
end
end
end[/QUOTE]
Here is where I define the function "ammo":
[QUOTE]local function DrawHUD()
Base()
Health()
Salary()
Wallet()
Job()
Ammo()
GunLicense()
Agenda()
DrawVoiceChat()
LockDown()
Arrested()
AdminTell()
end[/QUOTE]
When I try this I get the error:
[QUOTE][ERROR] addons/darkrpmodification-master/lua/darkrp_modules/sanyhud_v2/cl_hudv2.lua:127: attempt to index global 'client' (a nil value)
1. Ammo - addons/darkrpmodification-master/lua/darkrp_modules/sanyhud_v2/cl_hudv2.lua:127
2. DrawHUD - addons/darkrpmodification-master/lua/darkrp_modules/sanyhud_v2/cl_hudv2.lua:262
3. v - addons/darkrpmodification-master/lua/darkrp_modules/sanyhud_v2/cl_hudv2.lua:366
4. unknown - lua/includes/modules/hook.lua:82[/QUOTE]
What am I doing wrong? Any help is greatly appreciated!
Edit: my whole code is located at: [url]http://pastebin.com/KdvFJQUC#[/url]
Add "local client = LocalPlayer()" outside of your function.
Okay I'll try it. Thanks.
Edit: Worked great. Thank you again. Another question though, when I use the physgun it is -1 ammo. I was wondering if there was a way to not draw the ammo box at all or just say '0' ammo if the physgun is in use.
[QUOTE=imMrAnarchy;44203209]Okay I'll try it. Thanks.
Edit: Worked great. Thank you again. Another question though, when I use the physgun it is -1 ammo. I was wondering if there was a way to not draw the ammo box at all or just say '0' ammo if the physgun is in use.[/QUOTE]
Check if the ammo is -1 and if it is draw 0.
Isn't it draw false?
[QUOTE=BFG9000;44212280]Isn't it draw false?[/QUOTE]
false == 0 == nil