• Weapon Dropping Ammo Glitch
    13 replies, posted
okay, so i have a bug for my gamemode. players can drop their weapons, then pick them back up and EXTRA ammo for doing it. i beleive it has to do with the clip size in the weapon's LUA. How can i code a function that TAKES AWAY all of the ammo that you gain in that clip, so one cannot continue to drop and pick up the weapon to get virtually limitless ammo?
[url]http://wiki.garrysmod.com/?title=Player.RemoveAmmo[/url]
thanks, that was useful. another question then, how can i get this to KNOW how many bullets it needs to take away, and what type automatically? heres a pseudo-code: [lua] function OnPlayerPickup() local ammotype = Self.Owner.Weapon:primaryammo() local ammount = Self.Owner.Weapon:Clip() pl:RemoveAmmo (ammount, ammotype) end [/lua]
That should be working, yes. If it picks up the default amount of ammo for the weapon, set ammount to this instead: [lua] Self.Owner.Weapon:GetTable().Primary.DefaultClip [/lua]
Try this [lua] local AmmoToTake = 40; for k, v in pairs(Player:GetWeapons()) do if v:GetPrimaryAmmoType() == 'pistol' or v:GetPrimaryAmmoType() == 'smg' or v:GetPrimaryAmmoType() == 'shotgun' then local ToTake = math.Clamp(v:Clip1(), 0, AmmoToTake); if ToTake > 0 then v:SetClip1(v:Clip1() - ToTake); AmmoToTake = AmmoToTake - ToTake; end end end[/lua] [editline]28th January 2011[/editline] [QUOTE=mikeym;27705917]Try this [lua] local AmmoToTake = 40; for k, v in pairs(Player:GetWeapons()) do if v:GetPrimaryAmmoType() == 'pistol' or v:GetPrimaryAmmoType() == 'smg' or v:GetPrimaryAmmoType() == 'shotgun' then local ToTake = math.Clamp(v:Clip1(), 0, AmmoToTake); if ToTake > 0 then v:SetClip1(v:Clip1() - ToTake); AmmoToTake = AmmoToTake - ToTake; end end end[/lua][/QUOTE] You can make AmmoToTake how ever much the max it always gives on weapon pickup. Spawn all the SMGs, see what it gives every time, rinse and refresh every time.
self.Owner.ammo = 0 function Whateverthefunctionnameisthatiscalledwhenyoudropweapons() actwep = self.Owner:GetActiveWeapon() self.Owner.ammo = GetAmmoCount(actwep:GetPrimaryAmmoType()) self.Owner:RemoveAmmo( GetAmmoCount(actwep:GetPrimaryAmmoType()), actwep:GetPrimaryAmmoType()) end function OnPlayerPickup() self.Owner: Uhhhh rofl I got stuck, basically, if you didnt get what I tried to do is, assign the ammo to a variable/NWVar and strip the ammo from that gun, then when the player picks it up again, set the ammo to the variable/NWVar that stored the ammo count when the gun was dropped. My code is messy/useless/pretty much psuedocode, or whatever you wanna call it, I recommend you recode it rofl. EDIT: I have no idea why the space is in the imaginary first function name, in weapons, I did not intend to do that and when I go to edit, its not there lol Reply to post below: This is the real convo... 11:11 PM - C to the UNIT: [url]http://www.facepunch.com/threads/1054078-Weapon-Dropping-Ammo-Glitch?p=27706202&viewfull=1#post27706202[/url] 11:11 PM - C to the UNIT: my best post 11:14 PM - [NK] Andriko: wdude 11:15 PM - C to the UNIT: yo yoyoy 11:15 PM - [NK] Andriko: your gonna get banned again 11:15 PM - [NK] Andriko: snip it 11:15 PM - [NK] Andriko: jesus you need therapy =/ 11:16 PM - C to the UNIT: [url]http://www.facepunch.com/threads/1054078-Weapon-Dropping-Ammo-Glitch?p=27706202&viewfull=1#post27706202[/url] 11:16 PM - C to the UNIT: umad
-snipped, so that kids stop being so madd-
hmm. to refine my question, i want it to remove ANY extra ammo that you get from ANY gun. so itd be a function to find the ammo that you got, and remove it. [editline]28th January 2011[/editline] [QUOTE=mikeym;27705917]Try this [lua] local AmmoToTake = 40; for k, v in pairs(Player:GetWeapons()) do if v:GetPrimaryAmmoType() == 'pistol' or v:GetPrimaryAmmoType() == 'smg' or v:GetPrimaryAmmoType() == 'shotgun' then local ToTake = math.Clamp(v:Clip1(), 0, AmmoToTake); if ToTake > 0 then v:SetClip1(v:Clip1() - ToTake); AmmoToTake = AmmoToTake - ToTake; end end end[/lua] [editline]28th January 2011[/editline] You can make AmmoToTake how ever much the max it always gives on weapon pickup. Spawn all the SMGs, see what it gives every time, rinse and refresh every time.[/QUOTE] Closest so far. what if the SMG's have different ammo counts per weapon?
ply:StripAmmo() strips all ammo
[QUOTE=Kruel Kramer;27713669]hmm. to refine my question, i want it to remove ANY extra ammo that you get from ANY gun. so itd be a function to find the ammo that you got, and remove it. [editline]28th January 2011[/editline] Closest so far. what if the SMG's have different ammo counts per weapon?[/QUOTE] Put the largest amount of ammo, you can put 100000 and it will only strip what they have.
[lua] function OnPlayerPickup() local AmmoToTake = 10000; for k, v in pairs(Player:GetWeapons()) do if v:GetPrimaryAmmoType() == 'pistol' or v:GetPrimaryAmmoType() == 'smg' or v:GetPrimaryAmmoType() == 'shotgun' or v:GetPrimaryAmmoType() == 'smg1' or v:GetPrimaryAmmoType() == '357' or v:GetPrimaryAmmoType() == 'ar2' or v:GetPrimaryAmmoType() == 'xbowbolt' or v:GetPrimaryAmmoType() == 'buckshot' then local ToTake = math.Clamp(v:Clip1(), 0, AmmoToTake); if ToTake > 0 then v:SetClip1(v:Clip1() - ToTake); AmmoToTake = AmmoToTake - ToTake; end end end end [/lua] okay, here's my code. now how do i get it to call EVERY TIME that a weapon is picked up?
[b][url=wiki.garrysmod.com/?title=Gamemode.WeaponEquip]Gamemode.WeaponEquip [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Okay, close. i decided to take the weapon on the SROP function so you dont spawn with 0 ammo. however, it does not work =\ here is my DropWeapon Code: [lua] function GM:ShowTeam(pl) if (pl:Team() == TEAM_HUMAN) then if (pl:HasWeapon(pl:GetActiveWeapon():GetClass())) then local wep = pl:GetWeapon(pl:GetActiveWeapon():GetClass()) -- Prevents dropping weapons for more ammo local Primary = wep.Primary or 'none' Primary = Primary.Ammo or 'none' local AmmoStr = string.lower(Primary) -- If we have an ammo type, remove one "clip" if (AmmoStr ~= "none") then local AmmoNum = GM.AmmoRegeneration[AmmoStr] pl:RemoveAmmo( AmmoNum, AmmoStr ) end -- Drop it pl:DropWeapon(wep) wep.Dropped = true end end if REDEEM and not AUTOREDEEM and pl:Team() == TEAM_UNDEAD and pl:Frags() >= REDEEM_KILLS then pl:Redeem() end end [/lua] any ideas on why? OH, also, heres the weapon ammo table: [lua] GM.AmmoRegeneration = {} -- Leave it. GM.AmmoRegeneration["ar2"] = 90 GM.AmmoRegeneration["alyxgun"] = 60 GM.AmmoRegeneration["pistol"] = 80 GM.AmmoRegeneration["smg1"] = 100 GM.AmmoRegeneration["smg"] = 150 GM.AmmoRegeneration["357"] = 45 GM.AmmoRegeneration["xbowbolt"] = 10 GM.AmmoRegeneration["buckshot"] = 35 GM.AmmoRegeneration["ar2altfire"] = 6 GM.AmmoRegeneration["slam"] = 2 GM.AmmoRegeneration["rpg_round"] = 1 GM.AmmoRegeneration["smg1_grenade"] = 1 GM.AmmoRegeneration["sniperround"] = 1 GM.AmmoRegeneration["sniperpenetratedround"] = 5 GM.AmmoRegeneration["grenade"] = 1 GM.AmmoRegeneration["thumper"] = 1 GM.AmmoRegeneration["Gravity"] = 2 GM.AmmoRegeneration["battery"] = 1 GM.AmmoRegeneration["gaussenergy"] = 50 GM.AmmoRegeneration["combinecannon"] = 10 GM.AmmoRegeneration["airboatgun"] = 100 GM.AmmoRegeneration["striderminigun"] = 100 GM.AmmoRegeneration["helicoptergun"] = 100 [/lua]
[QUOTE=Kruel Kramer;27701823]okay, so i have a bug for my gamemode. players can drop their weapons, then pick them back up and EXTRA ammo for doing it. i beleive it has to do with the clip size in the weapon's LUA. How can i code a function that TAKES AWAY all of the ammo that you gain in that clip, so one cannot continue to drop and pick up the weapon to get virtually limitless ammo?[/QUOTE] Store how much ammo the player has into the weapon entity when the weapon is dropped. Then add/remove ammo to match that amount when the player picks it up. Weapons created should have that stored value set to its default ammo.
Sorry, you need to Log In to post a reply to this thread.