Im making a function that refills your ammo on active weapon every 60 secons (10 seconds when i debug).
[PHP]timer.Create( "RefillAmmo", 10, 0,RefillAmmo())[/PHP][PHP]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[/PHP]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
[code]timer.Create( "RefillAmmo", 10, 0, RefillAmmo )[/code]
:ninja:
Secondly, your ammo thing won't work because SetAmmo uses a string ammo type whereas GetPrimaryAmmoType returns an integer.
[QUOTE=Entoros;20721794]First of all, the syntax for the timer is
[code]timer.Create( "RefillAmmo", 10, 0, RefillAmmo )[/code]
:ninja:
Secondly, your ammo thing won't work because SetAmmo uses a string ammo type whereas GetPrimaryAmmoType returns an integer.[/QUOTE]
GetPrimaryAmmoType returns a string.
[editline]04:38PM[/editline]
[b][url=http://wiki.garrysmod.com/?title=Weapon.GetPrimaryAmmoType]Weapon.GetPrimaryAmmoType [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
@Entoros the script is already working but thanks anyway
[QUOTE=Entoros;20726675][code]
] lua_run_cl print(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())
3
[/code]
=\[/QUOTE]
You must have overridden it somewhere.
Sorry, you need to Log In to post a reply to this thread.