• Infinite ammo
    18 replies, posted
How to make some autorun.lua that turn everybodys every weapon ammo to 999999 or bigger (infinite)? Instance: [code] function onThink() for k,v in pairs(ents.FindByClass("ammunition")) do v:SetKeyValue("ammo","9999999") end end hook.Add( "Think", "thik", onThink ) [/code]
This is my way of doing it, but there's probably a better one. [lua]function PLUGIN:FillClips( ply, wep ) if wep:Clip1() < 255 then wep:SetClip1( 250 ) end if wep:Clip2() < 255 then wep:SetClip2( 250 ) end if wep:GetPrimaryAmmoType() == 10 or wep:GetPrimaryAmmoType() == 8 then ply:GiveAmmo( 9 - ply:GetAmmoCount( wep:GetPrimaryAmmoType() ), wep:GetPrimaryAmmoType() ) elseif wep:GetSecondaryAmmoType() == 9 or wep:GetSecondaryAmmoType() == 2 then ply:GiveAmmo( 9 - ply:GetAmmoCount( wep:GetSecondaryAmmoType() ), wep:GetSecondaryAmmoType() ) end end function PLUGIN:Tick() for _, ply in pairs( player.GetAll() ) do if ( ply.EV_UnlimitedAmmo and ply:Alive() and ply:GetActiveWeapon() != NULL ) then self:FillClips( ply, ply:GetActiveWeapon() ) end end end[/lua]
I don't know jack shit about lua, but using the gmod wiki I threw this together a couple of weeks ago [lua] local function UnlimitedAmmo() for k,v in pairs(player.GetAll()) do curwep = v:GetActiveWeapon() if (v:Alive()) then if (curwep:Clip1() < 100) then curwep:SetClip1(100) end if (curwep:Clip2() < 100) then curwep:SetClip2(100) end if v:GetAmmoCount(curwep:GetPrimaryAmmoType() < 100)then v:SetAmmo(100,curwep:GetPrimaryAmmoType()) end if v:GetAmmoCount(curwep:GetSecondaryAmmoType() < 100)then v:SetAmmo(100,curwep:GetSecondaryAmmoType()) end end end timer.Simple(0.05,UnlimitedAmmo) end UnlimitedAmmo()[/lua]
Which one is the best?
Overv's way is the best, he just needs to get rid of the plugin part.
While on this topic, is there a way to do 'no reload'?
[QUOTE=Skapocalypse;18287893]While on this topic, is there a way to do 'no reload'?[/QUOTE] You can try setting the next reload to 0 every time but i doubt it works on all weapons.
Yeah I thought so. :P I'm prolly gonna end up recoding the weapons for my gamemode anyways. So I can just add a variable or whatever :)
[QUOTE=Skapocalypse;18287993]Yeah I thought so. :P I'm prolly gonna end up recoding the weapons for my gamemode anyways. So I can just add a variable or whatever :)[/QUOTE] My script makes it so you don't have to reload its a shoddy workaround tho
Oh you're right. I didn't really read it. Very cool :)
None of the SWEP functions work on stock weapons. I've tried, it gives you errors.
Hmmm we still need one
[QUOTE=grea$emonkey;18292739]None of the SWEP functions work on stock weapons. I've tried, it gives you errors.[/QUOTE] This is the result of stock - you can change the models, materials and sounds all you want, but when it comes to the actual code, you're better off making a new Source mod altogether. I suppose you could code SWEPs that use the stock models and then put these infinite ammo / no reload codes into those, but that's more work I guess.
[QUOTE=RikohZX;18327747]I suppose you could code SWEPs that use the stock models and then put these infinite ammo / no reload codes into those, but that's more work I guess.[/QUOTE] [url]http://www.facepunch.com/showthread.php?t=829230[/url] [lua]SWEP.Primary.NumAmmo = SWEP.Primary.NumShots // Number of taken from the clip per shot[/lua] Granted, this would be the most worthless pack of weapons you could make using my project. On the other hand, it's FP, someone will like it.
[QUOTE=raccoon2112;18283219]I don't know jack shit about lua, but using the gmod wiki I threw this together a couple of weeks ago [lua] local function UnlimitedAmmo() for k,v in pairs(player.GetAll()) do curwep = v:GetActiveWeapon() if (v:Alive()) then if (curwep:Clip1() < 100) then curwep:SetClip1(100) end if (curwep:Clip2() < 100) then curwep:SetClip2(100) end if v:GetAmmoCount(curwep:GetPrimaryAmmoType() < 100)then v:SetAmmo(100,curwep:GetPrimaryAmmoType()) end if v:GetAmmoCount(curwep:GetSecondaryAmmoType() < 100)then v:SetAmmo(100,curwep:GetSecondaryAmmoType()) end end end timer.Simple(0.05,UnlimitedAmmo) end UnlimitedAmmo()[/lua][/QUOTE] Everyone use this. Works Great! Works on ALL weapons Stock/Swep.
[QUOTE=Episode;18327978]Everyone use this. Works Great! Works on ALL weapons Stock/Swep.[/QUOTE] There are other methods which can prove more practical to the job.
[QUOTE=CptFuzzies;18328045]There are other methods which can prove more practical to the job.[/QUOTE] Well his is short and simple. Just add to lua and you have INFINITY ammo. What else could you get out of it?
[QUOTE=RikohZX;18327747]This is the result of stock - you can change the models, materials and sounds all you want, but when it comes to the actual code, you're better off making a new Source mod altogether. I suppose you could code SWEPs that use the stock models and then put these infinite ammo / no reload codes into those, but that's more work I guess.[/QUOTE] It's because the defaults are coded in C++, and do not use the SWEP library. I'm pretty sure they are made by valve, not garry.
[QUOTE=Overv;18279280]This is my way of doing it, but there's probably a better one. [lua]function PLUGIN:FillClips( ply, wep ) if wep:Clip1() < 255 then wep:SetClip1( 250 ) end if wep:Clip2() < 255 then wep:SetClip2( 250 ) end if wep:GetPrimaryAmmoType() == 10 or wep:GetPrimaryAmmoType() == 8 then ply:GiveAmmo( 9 - ply:GetAmmoCount( wep:GetPrimaryAmmoType() ), wep:GetPrimaryAmmoType() ) elseif wep:GetSecondaryAmmoType() == 9 or wep:GetSecondaryAmmoType() == 2 then ply:GiveAmmo( 9 - ply:GetAmmoCount( wep:GetSecondaryAmmoType() ), wep:GetSecondaryAmmoType() ) end end function PLUGIN:Tick() for _, ply in pairs( player.GetAll() ) do if ( ply.EV_UnlimitedAmmo and ply:Alive() and ply:GetActiveWeapon() != NULL ) then self:FillClips( ply, ply:GetActiveWeapon() ) end end end[/lua][/QUOTE] After making the lua file,where should i put it? (Do i need to make a .gma file for it?) [highlight](User was banned for this post ("Dumb bump" - Kiwi))[/highlight]
Sorry, you need to Log In to post a reply to this thread.