'Realistic' SWEP Base (bullet physics and custom firemodes)



A SWEP base for making ‘realistic’ SWEPs (or anything you want really). This is more geared towards developers, but if you’re not a developer I don’t care if you use it or not. It comes with some spiffy features, which are listed below. Under garrysmod/addons/lua/weapons/weapon_rg_example/shared.lua there’s an example SWEP that shows you how to use all of the stuff.


[‘Realistic’ Recoil]
The longer you hold fire, the less accurate and more unpredictable your gun becomes. Crouching, aiming down the sights = more accurate. Jumping, running = less accurate. Just like Counter-Strike. Spiffy. This has been done before of course, but I added a few things that I think make it cool and unique or something.

[‘Realistic’ Bullet Physics]
Bullets aren’t just tracelines anymore. They travel with their own velocity and acceleration. You can give them gravity so that they travel in an arc. This has the delightful side effect of making sniping more challenging for the sniper and less sucky for the sniped.

Note: The bullets work pretty well in singleplayer, but I don’t know how well they work in multiplayer. Bullet prediction is done serverside, so things might get laggy or slow if there are too many people firing. This is something to test out.

[Select Fire]
This is surely a necessary requirement for any ‘realism’ buff. The SWEP base comes with four default fire modes: Semi-Automatic, Fully-Automatic, Three-Round Burst, and Grenade. Defining a the firemode’s a gun is capable of is as simple as adding/removing some strings from a table. As an added bonus, you get to see a cute little icon next to your health telling you what firemode you’re in.

[Custom Firemodes]
This is probably the niftiest feature of the whole SWEP. I added a type of framework thingy that allows you to define your own firemodes from outside the base SWEP. You can do pretty much anything in these firemodes- it’s pretty open ended. Check out the example SWEP to see what I mean.

[Cool ‘Realistic’ Effects]
You get six muzzle flash effects and three shell ejection effects. I made the muzzle flash effects after watching videos of various guns on youtube, so apparently they are ‘realistic.’ I also added little details like sexy crosshairs, raising your rifle to view through the scope, plus a little sound/fadein when you zoom in or out. Oh, and did I mention that you can have an arbitrary amount of scope magnification levels to switch to?

[Works With NPCs]
Well, it works with citizens at least. Combine soldiers just point at you and tremble. But citizens know how to use it very well, and it looks cool too (if you can ignore their hands clipping the world model). To spawn a citizen with the example swep, type “npc_create_equipment weapon_rg_example” in the console, then look at the ground and type “npc_create npc_citizen.” It should also work with any other gun-wielding friendly.

[Well Commented]
I suppose that depends on your definition of “well.” I did put comments in this SWEP more than I usually do though, so other people can look at it and hopefully get an idea as to wtf I am doing. Plus, it might make it a helpful example for Lua newbs to mess with (just please don’t pick up any of my horrible programming habits!).

There’s probably a bunch more that I forgot already. See for yourself if you wish.


Extract to C:\Program Files\Steam\SteamApps\YOUR STEAM NAME\garrysmod


This is very much a work in progress. And there’s always something to do…

  • Clean up code
  • Add custom ammo types
  • Develop/Test clientside bullet prediction
  • Get it working with other NPCs (probably impossible)
  • Make a cheasy FPSbanana weapon pack using this as a base
  • Something else, I just forgot what it was. :frowning:

Teta_Bonita: 99% of the coding
Garry: Various bits of Lua code that I filched from the garrysmod GCF
NightEagle: Looked through his CSE pack for ideas when I got stuck; Certain variable names xD
Wang - Chung: Sexy parabolic scope sight


-Initial beta/alpha/omega/whatever Release


Screenie: (same one from the download link :v:)

Here’s a video, showing off the SWEP base and a custom firemode I added called “Underwater Shotgun”:

Fun Facts

The phrase “I don’t know why this works, but it does” appears at least twice in the code commentary.

To Scripters:

You may modify/distribute this to your heart’s content, as long as you give credit where it is due.

Final Note

Let me know what you think about this. Is it useful? Does it rock? What about it rocks? Does it suck? What about it sucks? What do you want added? Removed? Is it too confusing? Found any bugs? etc…

Also, I’m thinking of making a SWEP pack using this. Something involving the Soviet Union. Because the Soviet Union is badass.

Damn, I just looked at the code from TWMCSWEP and found out that it does everything my SWEP does, only better. :uhoh: Back to the drawing board…

Holy shit… WINRAR!


Hope you don’t mind if I’m using this base for some of my private sweps? :dance:

Certainly. Matter o’ fact, I don’t mind if anybody uses/releases stuff with this provided they give credit where it is due. (I’ll add that to the main post…)

Ok I don’t releas my stuff anyhow. :wink:

Ah ha ha. This is pretty awesome. “I don’t know why this works but it does” happens a lot with me too. And the Soviet Union is baddass.


How do I make so you can only use auto and semi?



It’s really awesome … just tested it … super good work :smiley:

Nice to see you coming back from the dead, Teta. I have my share of the 'I don’t know why, but this works." moments as well.

M16 mortar?
High gravity bullets, so being able to see your opponent is now a disadvantage! :dance:

When using the example swep, I get the same delay everywhere I shoot. It takes 0.5 seconds before the bullet hits the ground. Even when I’m shooting straight down.

Well you have to have that delay in order to have the realistic trajectory I do believe.

So there’s supposed to be a 1 second delay before the bullet hits the ground when you’re firing it 1 CM away from the ground?

Mayby it’s something in the example weapons Lua?

It’s not compatable with Kogitsune’s bullettime mod, as far as I can tell…

I don’t have that problem with the sweps I made with this base… gues it’s you or the example swep then.

The example swep says

[lua]SWEP.MuzzleVelocity = 800 – How fast the bullet travels in meters per second. For reference, an AK47 shoots at about 750, an M4 shoots at about 900, and a Luger 9mm shoots at about 350 (source: Wikipedia)[/lua]

So it has to be me somehow.

Yeah, somehow. :geno:

No, it’s the same with me.

And it never will be since this weapon doesn’t use bullets. Leave my broken mod alone, it’s crap and doesn’t deserve being mentioned - Teta could do a far better job with this if it does what I think it does code-wise.