HUD for the number of magazine (not the number of ammo in the current magazine).
7 replies, posted
I tried to make a script to see, not the number of ammo remaining, but a script which allows you to see how many magazines remaining.
But i noted that when i shoot with the weapon, the text representing the number of magazines remaining increases a lot, when I reload, all become normal.
Thank you for your help.
local ply = LocalPlayer()
local wep = ply:GetActiveWeapon()
local ammo = ply:GetAmmoCount(wep:GetPrimaryAmmoType())
local clip = wep:Clip1()
local charge = ammo / clip
if ply:Alive() && IsValid(wep) then
draw.SimpleText( math.floor(charge), "police" , 1100, ScrH()-70, Color(255,255,255,50) )
end
Weapon/GetMaxClip1
It's working, but I have this error sometimes :
Error in hook HUDPaint: addons/p_hud_lbdn/lua/autorun/client/hud.lua:44: attempt to call method 'GetPrimaryAmmoType' (a nil value)
stack traceback:
addons/p_hud_lbdn/lua/autorun/client/hud.lua:44: in function 'fn'
addons/ulib/lua/ulib/shared/hook.lua:109: in function <addons/ulib/lua/ulib/shared/hook.lua:92>
[C]: in function ''
[ERROR]
1. unknown - [C]:-1
Do you have any ideas ?
Thank you.
Check if you're actually holding a weapon, if you're not then it will show an error, even on spawn or during dead
How can I do that ?
if IsValid(wep) then
That function is part of the weapon metatable so it will always exist on valid weapons.
Sorry, you need to Log In to post a reply to this thread.