Ammo regeneration

Im making a function that refills your ammo on active weapon every 60 secons (10 seconds when i debug).

timer.Create( "RefillAmmo", 10, 0,RefillAmmo())
function RefillAmmo()
local Wpn = ""
local Count = 0
    for k , v in ipairs(player.GetAll()) do
    Wpn = v:GetActiveWeapon():GetPrimaryAmmoType()
    Count = v:GetAmmoCount()
    v:SetAmmo(Count + 30, Wpn)
    end
end

i get this error “Timer Error: attempt to call a nil value”

You don’t need the brackets (parentheses) in the timer.Create function, at the moment you are passing the return value of RefillAmmo to the timer, not the actual function.

[editline]04:35PM[/editline]

[lua]timer.Create( “RefillAmmo”, 10, 0,RefillAmmo) [/lua]

First of all, the syntax for the timer is


timer.Create( "RefillAmmo", 10, 0, RefillAmmo )

:ninja:

Secondly, your ammo thing won’t work because SetAmmo uses a string ammo type whereas GetPrimaryAmmoType returns an integer.

GetPrimaryAmmoType returns a string.

[editline]04:38PM[/editline]

**[Weapon.GetPrimaryAmmoType

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Weapon.GetPrimaryAmmoType)**

Thanks both of you
and thank you MakeR again

You’re welcome.



] lua_run_cl print(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())
3


=\

@Entoros the script is already working but thanks anyway

You must have overridden it somewhere.