• Extra reserve ammo for guns in TTT?
    18 replies, posted
I was wondering how to get extra reserve ammo for a gun when it is spawned in. I tried using this: [CODE]if SERVER then function SWEP:Initialize() self.Owner:GiveAmmo( self.Primary.Ammo, 30 ) end end [/CODE] But it doesn't actually give ammo.
You have the arguments mixed up.
[QUOTE=txike;52008370]You have the arguments mixed up.[/QUOTE] It still doesn't work.
What doesn't work? Is there any error message or do you just get no extra ammo?
[QUOTE=markusmarkusz;52010094]What doesn't work? Is there any error message or do you just get no extra ammo?[/QUOTE] There's no error message in my console, and I do not receive any extra ammo.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/SetClip2]Weapon:SetClip2[/url]?
[QUOTE=JasonMan34;52010193][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/SetClip2]Weapon:SetClip2[/url]?[/QUOTE] Doesn't that just change the secondary ammo and not the reserve ammo?
This code will give you an additional of 5 ammo on spawn. [lua] SWEP.Primary.ClipSize = 5 SWEP.Primary.DefaultClip = 10 -- DefaultClip - ClipSize = additional ammo [/lua] source: [url]http://wiki.garrysmod.com/page/Structures/SWEP[/url]
[QUOTE=Fruitwesp;52010209]This code will give you an additional of 5 ammo on spawn. [lua] SWEP.Primary.ClipSize = 5 SWEP.Primary.DefaultClip = 10 -- DefaultClip - ClipSize = additional ammo [/lua] source: [url]http://wiki.garrysmod.com/page/Structures/SWEP[/url][/QUOTE] Thanks, do you know how I can prevent the ammo from two weapons stacking above a limit?
[QUOTE=fruma;52010225]Thanks, do you know how I can prevent the ammo from two weapons stacking above a limit?[/QUOTE] Set SWEP.Primary.ClipMax to the correct value. In TTT the reserve ammo is shared between weapons. And every ammo has a limit.
[QUOTE=markusmarkusz;52010250]Set SWEP.Primary.ClipMax to the correct value. In TTT the reserve ammo is shared between weapons. And every ammo has a limit.[/QUOTE] Also, whenever I drop the weapon and pick it back up, it gives me more ammo, which gives me essentially infinite ammo.
[QUOTE=fruma;52010265]Also, whenever I drop the weapon and pick it back up, it gives me more ammo, which gives me essentially infinite ammo.[/QUOTE] iirc It's because SWEP.Primary.DefaultClip is higher than SWEP.Primary.ClipSize.
[QUOTE=markusmarkusz;52010275]iirc It's because SWEP.Primary.DefaultClip is higher than SWEP.Primary.ClipSize.[/QUOTE] Ok, so how do I do this without allowing infinite ammo?
[QUOTE=fruma;52010280]Then how do I do this without allowing infinite ammo?[/QUOTE] Example: [code] SWEP.Primary.ExtraAmmo = 10 -- how much extra ammo function SWEP:Equip(newowner) if not self.HasExtraAmmo and IsValid(newowner) and newowner:IsPlayer() and self.Primary.Ammo ~= "none" then local ammo = newowner:GetAmmoCount(self.Primary.Ammo) local give = self.Primary.ExtraAmmo local max = self.Primary.ClipMax - ammo if max <= 0 or max - give <= 0 then give = 0 else give = math.min(give, max - give) end newowner:GiveAmmo(give, self.Primary.Ammo) self.HasExtraAmmo = true end return self.BaseClass.Equip(self, newowner) end [/code] I'm sure there are other ways too. I didn't test this code and it was written on my mobile phone. I hope everything works.
[QUOTE=markusmarkusz;52010322]Example: [code] SWEP.Primary.ExtraAmmo = 10 -- how much extra ammo function SWEP:Equip(newowner) if not self.HasExtraAmmo and IsValid(newowner) and newowner:IsPlayer() and self.Primary.Ammo ~= "none" then local ammo = newowner:GetAmmoCount(self.Primary.Ammo) local give = self.Primary.ExtraAmmo local max = self.Primary.ClipMax - ammo if max <= 0 or max - give <= 0 then give = 0 else give = math.min(give, max - give) end newowner:GiveAmmo(give, self.Primary.Ammo) self.HasExtraAmmo = true end return self.BaseClass.Equip(self, newowner) end [/code] I'm sure there are other ways too. I didn't test this code and it was written on my mobile phone. I hope everything works.[/QUOTE] Thanks, but it doesn't seem to have an effect.
Did you test it with a weapon you picked up? I'm not sure but afaik Player:Give() doesn't trigger SWEP:Equip(). Do you need this extra ammo for a special item or a normal weapon that you can easily pick up?
[QUOTE=markusmarkusz;52010352]Did you test it with a weapon you picked up? I'm not sure but afaik Player:Give() doesn't trigger SWEP:Equip(). Do you need this extra ammo for a special item or a normal weapon that you can easily pick up?[/QUOTE] It's for weapons that can be picked up and given through loadouts, which use Give(). It still allows for infinite ammo even when the weapon was picked up.
I'm having a really hard time understanding what "Reserve ammo" is. But you should be able to achieve anything ammo related with SetClip1 and SetClip2. Want a player to have more ammo when he first picks up the weapon/when the weapon is first picked up? Use SetClip1 according to the aforementioned condition...
[QUOTE=JasonMan34;52010365]I'm having a really hard time understanding what "Reserve ammo" is. But you should be able to achieve anything ammo related with SetClip1 and SetClip2. Want a player to have more ammo when he first picks up the weapon/when the weapon is first picked up? Use SetClip1 according to the aforementioned condition...[/QUOTE] Reserve ammo as in the ammo you reload from. I've tried using SetClip1 but it only sets ammo in the current clip and not reserve ammo. [editline]25th March 2017[/editline] Ok, it looks like this works: [CODE]function SWEP:Equip(newowner) local w = weapons.GetStored( self.ClassName ) if not w.HasExtraAmmo then self.Owner:SetAmmo( self.Primary.ClipMax, self.Primary.Ammo ) w.HasExtraAmmo = true end end[/CODE]
Sorry, you need to Log In to post a reply to this thread.