Unlimited Ammo

Im trying to create a pistol that has unlimited clips, so you still have to reload, but you can never run out of ammo.


(User was banned for this post ("Wrong section" - Gran PC))

You missed the questions section.

Make the weapon not take primary ammo on reload. Done.

Dunno if this is the best solution but you could try SetNWInt to the weapon like:

If GetNWInt(“rounds”) > 29 then

reload??

else

SetNWInt(“rounds”, GetNWInt(“rounds”) + 1)

end

Ummm… What?

I see what you are ATTEMPTING to do Timpo… But that is horribly written. Why use Networked Variables when you can just use NORMAL ones.

Because I’m stupid and did not think about that ^^

What I forgot to mention is that im new to lua. Now im even more confused. If I want to remove the reload function, what in the SWEP do I do. The only function that I see is the takeprimaryammo.

A very cheap but guaranteed to work solution would be to give more ammo every time you reload. Like, if you reload 16 bullets, give 16 extra bullets after reloading. This way you never run out.

Then there are cleaner solutions, but it all depends on the way the weapon is coded. Do you actually have the code for a regular pistol weapon without unlimited ammo or are you starting from scratch?

Here. [lua] function SWEP:Reload() if self:DefaultReload( ACT_VM_RELOAD ) then self.Owner:GiveAmmo(self.Primary.ClipSize - self:Clip1, self.Primary.Ammo, true); end end [/lua]

[editline]14th June 2012[/editline]

Fucking 1 line bullshit again.

Also, definitely do NOT use networked variables for this. It’s completely unnecessary. Forget about TakePrimaryAmmo as well, what this function does is take ammo from the clip. If you removed that, your weapon would never reload because it simply wouldn’t consume ammo at all.

You missed a pair of parentheses after self:Clip1 but other than that yeah, it’s pretty much what I meant.

[lua]
function SWEP:Reload()
if self:DefaultReload( ACT_VM_RELOAD ) then
self.Owner:GiveAmmo(self.Primary.ClipSize - self:Clip1, self.Primary.Ammo, true);
end
end
[/lua]

Here. Every time I try to edit something it winds up fucking up my code segments.

Just use this.

[editline]14th June 2012[/editline]

Oh. Fuck. Thats why I was trying to edit, but then forgot it when I pasted it again into the forums. I’m not sure if it is firefox or what, but each time I edit code on here it squishes everything onto one line.

[editline]14th June 2012[/editline]

Merges seem to still work though…

Doesn’t setting Primary Fire to -1 Work?

Took a while, but somebody finally got it.

Horray.

Primary Fire? You mean [LUA]SWEP.Primary.ClipSize = -1 [/LUA]

This???

or

[LUA]
function SWEP:PrimaryAttack()

self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
if ( !self:CanPrimaryAttack() ) then return end
self.Weapon:EmitSound(self.Primary.Sound)
self:ShootBullet( 150, 1, 0.01 )
self:TakePrimaryAmmo( 1 )


//Or this?
return -1

end
[/Lua]

Either way, I don’t think this accomplishes what he wanted to do.

Setting clip size to -1 allows you never to reload. He wants to have to reload.
and the second thing… Well… I’m not even sure that does anything.

If you are all knowing, why didn’t you say anything? :tinfoil:

Yeah…
You can just set the Primary ClipSize to -1

-_-

Can’t he just add the ammo back to the gun when reloading?

Say the gun has 500 ammo, on reload you just check the amount of ammo (500 - current ammo) and just add that to the amount of ammo again, this would make it so that you still have to reload, but you never loose ammo…

Learn to read before you rate all of my posts Dumb. Because you sir, are wrong.

I did this. You need to read too…

Sorry 2 hours of sleep does things to you.
My apologies <3