I'm trying to display, not the number of munitions in magazines, but only the number of magazines.
But I have an error :
[ERROR]
1. unknown - [C]:-1
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 ''
local ply = LocalPlayer()
local wep = ply:GetActiveWeapon()
local ammo = ply:GetAmmoCount(wep:GetPrimaryAmmoType() or 0)
local clip = wep:GetMaxClip1()
local simpleClip = wep:Clip1()
local charge = ammo / clip
if ply:Alive() && IsValid(wep) and ply:GetActiveWeapon() then
draw.SimpleText( math.floor(charge), "police" , 1100, ScrH()-70, Color(255,255,255,50) )
end
Check if weapon is valid before defining your ammo variable
local ammo = ply:GetAmmoCount(wep:GetPrimaryAmmoType() or0)
On your ammo variable you haven't put a space between or and 0.
Also on this line you should not be needing the "GetActiveWeapon()" function as you are already checking if your wep variable is valid which is the same function. I recommend using IsValid(ply) instead of ply:Alive() too.
if ply:Alive() && IsValid(wep) and ply:GetActiveWeapon() then
Also if you are counting magazines, should you not be using math.ceil due to using floor would show less magazines than what you have?
two ways to think of this: you have 1 magazine in the gun, with 25 rounds in it. you have no more magazines left in your pocket. do you display 1 mag or 0 mags?
I’ve not tried this function myself, but I assumed this function takes the ammo not already in the weapon, since ammo in a weapons clip is a different value than all the ammo you have on you. I think that function for ammo counting is Weapon:Clip1()
Thank you ! I tried to change all things, but there is errors again ...
Can you show us the code you got and the error aswell? There's no way you got the SAME error
okay yeah i see what you mean now
ceil would be useful, then -1 magazine if for example, you have a full magazine in the gun, you'd want it to retain its status as either 1 or 0 mags until that magazine is empty.
using floor would make it 0 magazines as soon as you spend the first bullet
I really have the same error ^^
Sorry, you need to Log In to post a reply to this thread.