Add Ammo To Player ( ready to be shot )

How can I add ammo to the players currently equipped gun so it’s in the clip ready to be shot, rather then in reserve?

I’ve looked at SetAmmo and GiveAmmo, but both of these don’t put it in the gun.

Or

Better still, stop the currently equipped weapon using ammo - so it can shoot infinitely?

What do you mean? GiveAmmo should work perfectly fine as long as you are giving the correct ammo type for the gun. Maybe show us the code you have tried.

GiveAmmo puts the ammo in reserve, ready to be loaded, rather then putting it in the gun ready to be shot.

Eg:


local ammo = v:GetWeapons()[1]:GetPrimaryAmmoType()
v:SetAmmo( 1000, ammo )

I would be nice to avoid rating as ‘dumb’ before hearing an explanation, as you miss-understood. That may have been me being unclear, but still - I think it was fairly obvious.

You where marked dumb because you did not describe your problem clearly and failed to provide any type of code. You made it sound as if they where not providing you ammo you did not say that you wanted them in the currently active clip just in the gun.

Based on what you are saying it sounds like you are trying to make it so that a gun does not have to be reloaded rather it can continuously fire. You are going to need to modify the sweps themselves in order to change the clip cappacity or not have them use a clip at all.

Ok, I appreciate the help - but this section is used for lua questions as well as discussions, hence the ‘question’ and ‘help’ tags. However I could have been clearer.

So you’re saying there’s no way to place the ammo in the clip rather then in reserve?

PS: Also as you can see above, there’s really not much code as I mentioned I’d already used SetAmmo and GiveAmmo ( although I suppose I could have been using them wrong for all you knew )

Nothing that I am aware of or could find in the wiki. You are welcome to look for yourself but I am pretty sure the only way to accomplish what you want is to modify the swep itself.

Thanks for this Robotboy - Can this be used to get a players weapon and add to Clip1, or only when creating a SWEP?

It can be called on a player’s weapon if the player’s active weapon exist and is valid.

ply:GetActiveWeapon():SetClip1(100)

Thanks. This worked perfectly. I’ve never used anything for WEAPON: before :confused: wasn’t sure what you run it on. Thanks.