Setting variable per player?

Hi guys,

I want to give players extra ammo when they pickup a weapon. For some reason it does not always work.
My guess is that I need to set the ammo type variable per player. But how do you do that in lua? I tried v.ammotype but that screws up the server creating loads of errors :<
[lua]
hook.Add(“WeaponEquip”, “ammofix”, function(weapon)
for k, v in pairs( player.GetAll() ) do

    if !v:Alive() or v:IsFrozen() then return end
    local ammotype = weapon:GetPrimaryAmmoType()
    if weapon == "weapon_crowbar" then return end
    v:SetAmmo( 9999 , ammotype )

end

end )
[/lua]



hook.Add("WeaponEquip", "GiveAmmo", function( weapon )
	timer.Simple(0, function() 
		local owner = weapon:GetOwner()

		if not IsValid(owner) or not IsValid(weapon) then return end
		local ammo1 = weapon:GetPrimaryAmmoType()
		local ammo2 = weapon:GetSecondaryAmmoType()
		
		owner:GiveAmmo(1000, ammo1)
		owner:GiveAmmo(1000, ammo2)
	end)
end)



You sir made my day! Thanks :slight_smile: