Skip to content

Gun Base Template

Vuthakral edited this page Oct 21, 2022 · 19 revisions

Gun Base Template

On this page you can find a template for a working gun with ironsights capability. I highly recommend you copy and paste the first code block, and then use the rest of the page here as reference for what each setting does.

The rest of the page also details settings not listed in the template. The template serves only to give a basic functioning weapon.

Start by making a new lua file in your lua\weapons\ folder and name it what you want. e.g. drc_swepname.lua
IMPORTANT: If you intend on your weapon being usable for NPCs, it MUST have drc_ as the filename prefix.


Clean Paste

SWEP.Base			= "draconic_gun_base"

SWEP.HoldType			= "pistol"
SWEP.Author			= "Vuthakral"
SWEP.Category			= "Draconic"
SWEP.PrintName			= "Draconic Base Template Weapon"
SWEP.Contact			= "Steam: Vuthakral \nDiscord: Vuthakral#9761 " -- use \n to start a new line in any of these fields.
SWEP.Purpose			= ""
SWEP.Instructions		= ""
SWEP.WepSelectIcon 		= "vgui/entities/drc_default"

SWEP.InfoName			= nil
SWEP.Manufacturer		= nil
SWEP.InfoDescription		= nil

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= false
SWEP.NPCSpawnable		= true

SWEP.Slot				= 1
SWEP.SlotPos			= 0

SWEP.ViewModelFlip		= false
SWEP.UseHands			= true
SWEP.DoesPassiveSprint	= false
SWEP.ViewModel			= "models/weapons/c_pistol.mdl"
SWEP.WorldModel			= "models/weapons/w_pistol.mdl"
SWEP.ViewModelFOV		= 54
SWEP.VMPos = Vector(0, 0, 0)
SWEP.VMAng = Vector(0, 0, 0)
SWEP.VMPosCrouch = Vector(0, 0, 0)
SWEP.VMAngCrouch = Vector(0, 0, 0)
SWEP.IronSightsPos = Vector(-5.854, -8.4, 3)
SWEP.IronSightsAng = Vector(0.206, -1.349, 1.666)
SWEP.PassivePos = Vector(5, 0, 3)
SWEP.PassiveAng = Vector(-15, 25, 0)
SWEP.SS = 1
SWEP.BS = 1

SWEP.Primary.Spread			= 3.5
SWEP.Primary.SpreadDiv		= 100
SWEP.Primary.Kick			= 0.5
SWEP.Primary.IronRecoilMul	= 0.5
SWEP.Primary.RecoilUp		= 1
SWEP.Primary.RecoilDown		= 1
SWEP.Primary.RecoilHoriz	= 1
SWEP.Primary.Force			= 0.2
SWEP.Primary.Damage			= 12
SWEP.Primary.Ammo			= "pistol"
SWEP.Primary.ReloadHoldType	= "pistol"
SWEP.Primary.Automatic		= false
SWEP.Primary.RPM			= 444
SWEP.Primary.ClipSize		= 18
SWEP.Primary.DefaultClip	= 18
SWEP.Primary.APS			= 1
SWEP.Primary.Tracer			= 1
SWEP.Primary.Sound = Sound("weapon_pistol.Single")

SWEP.Secondary.Ironsights			= true
SWEP.Secondary.SightsSuppressAnim 	= false
SWEP.Secondary.Scoped				= false
SWEP.Secondary.ScopeHideVM			= false
SWEP.Secondary.IronFOV				= 60
SWEP.Secondary.IronFOVAlt			= 60
SWEP.Secondary.IronInFP				= nil
SWEP.Secondary.IronOutFP			= nil
SWEP.Secondary.ScopeZoomTime 		= 0.25
SWEP.Secondary.SpreadRecoilMul 		= 1.0
SWEP.Secondary.SightsKickMul 		= 1.0
SWEP.Secondary.ScopePitch 			= 0
SWEP.Secondary.ScopeYOffset 		= 0
SWEP.Secondary.ScopeMat		= "overlays/draconic_scope"
SWEP.Secondary.Q2Mat		= nil
SWEP.Secondary.Q3Mat		= nil
SWEP.Secondary.Q4Mat		= nil
SWEP.Secondary.ScopeCol		= Color(255, 255, 255, 255)
SWEP.Secondary.ScopeBlur	= true
SWEP.Secondary.ScopeBGCol	= Color(0, 0, 0, 0)
SWEP.Secondary.ScopeScale	= 1
SWEP.Secondary.ScopeWidth	= 1
SWEP.Secondary.ScopeHeight	= 1

SWEP Settings

This is the part of the page that tells you what every setting on this hunk of code does, and then some:

Definitions

  • SWEP.Base // What defines which base to use for your weapon.

  • SWEP.WepSelectIcon = string path to vmt // Assign a material to use for a weapon select icon (Must be a 1:1 image, e.g. 256x256, 512x512)

  • SWEP.Holdtype // The standing holdtype of your weapon. https://wiki.garrysmod.com/page/Hold_Types

  • SWEP.ReloadHoldtype // holdtype reload animation to play (doesn't always sync well)

  • SWEP.Contact // ^^^

  • SWEP.Purpose // ^^^

  • SWEP.Instructions // ^^^

  • SWEP.Spawnable // The setting that must be set to true for your weapon to appear in the spawnmenu.

  • SWEP.AdminSpawnable // A setting that, if set to true, will make it so only admins can spawn your weapon.

  • SWEP.NPCSpawnable // A setting that when set to true will make your weapon be registered with the NPC weapon override lists.

  • SWEP.Slot // The inventory slot which hte weapon will be categories into. It starts from 0. Slot 0 is your "1" key ingame.

  • SWEP.SlotPos // How far down in the slot your weapon will be placed. Again, 0 is the start.

  • SWEP.Category // The category in the spawnmenu in which your weapon will appear. Also appears as subheader for the stats screen.

  • SWEP.PrintName // The name that will appear on the HUD & stats screen for your weapon.

  • SWEP.Author // The name that will appear under the name/icon in the weapon select menu, and in the inspection mode underneath the category.

  • SWEP.InfoName // The shorthand name which will appear when switching firing modes, and will appear in the stats screen in the inspection mode.

  • SWEP.Manufacturer // Company/organization that manufactures the weapon. Appears in the stats screen.

  • SWEP.InfoDescription // Short description that appears in the stats screen. Use "\n" to start a new line.

Models

  • SWEP.ViewmodelFOV // The field of view of the viewmodel. Source displays your current weapon on a unique FOV.
  • SWEP.ViewModelFlip // The setting which will flip your viewmodel from left -> right or right -> left.
  • SWEP.UseHands // The setting to tell the weapon whether or not it should use Garry's Mod's c_hands system
  • SWEP.ViewModel // The setting to define what model to use for the first person model of your weapon
  • SWEP.WorldModel // The setting to define what model to use for the third person model of your weapon
  • SWEP.VMPos // The offset position of your SWEP.
  • SWEP.VMAng // ^ but for angles.
  • SWEP.IronSightsPos // The setting to set the position for your weapon's ironsights
  • SWEP.IronSightsAng // ^ but for angles
  • SWEP.PassivePos // ^ The setting to set the position for your weapon's possive position in first person
  • SWEP.PassiveAng // ^ but for angles
  • SWEP.SS // The sway scale built into source. Defaulted to 1. Sway is the movement when you move your character's vision around.
  • SWEP.BS // The bob scale built into source. Defaulted to 1. Bob is the movement when you move your character around in the world.

Firing Settings

  • SWEP.LoadAfterShot // See This page

  • SWEP.LoadAfterReloadEmpty // See This page

  • SWEP.ManualReload // See This page

  • SWEP.MagazineEntity // The entity which can be dropped from the weapon when reloading, if set. If unset this does nothing. (Note, this spawns from the left hand of the character holding the weapon.)

  • SWEP.FireModes_CanAuto // Can the firing mode be switched to fully automatic

  • SWEP.FireModes_CanBurst // Can the firing mode be switched to burst

  • SWEP.FireModes_CanSemi // Can the firing mode be switched to semi-automatic

  • SWEP.FireModes_BurstShots // How many times the weapon should fire when burst fired

  • SWEP.FireModes_SwitchSound // The sound which is made when the weapon switches firing modes.

Primary Attack

  • SWEP.Primary.Disabled // Whether or not the primary attack functionality should be disabled entirely.
  • SWEP.Primary.Spread // The amount of spread a weapon has. This isn't really in any form of measurable unit.
  • SWEP.Primary.SpreadDiv // The amount the spread is divided by. It goes through more math than just this behind the scenes. A note, using higher values for spread & spread divider create more diverse patterns but increase complexity of the math per shot calculated. I suggest a spread between 2-20 and divider of 100-300 for an even balance of around what traditional hl2 weapons would take to process.
  • SWEP.Primary.Kick // The amount of visual screen kick the weapon gives every time it fires. This setting plays the most critical role in weapon handling in how fast the spread increases & recovers.
  • SWEP.Primary.IronRecoilMul // A setting I misnamed from the earliest days of writing the base, this actually controls the level of visual kick on the player's view the weapon has when fired down sights. It has no effect on weapon spread.
  • SWEP.Primary.RecoilUp // The amount of aim offset the weapon gives upward every time it fires.
  • SWEP.Primary.RecoilDown // The amount of aim offset the weapon gives downward every time it fires.
  • SWEP.Primary.RecoilHoriz // The amount of aim offset the weapon gives to the left & right every time it fires.
  • SWEP.Primary.Force // The amount of physics force applied to an object hit by a bullet.
  • SWEP.Primary.Damage // The amount of damage a bullet deals.
  • SWEP.Primary.Ammo // The ammo type the weapon's primary fire uses.
  • SWEP.Primary.Automatic // Whether the weapon is automatic or not. (Should be auto-managed by the base when using multiple firing modes, but can be altered safely with custom lua).
  • SWEP.Primary.RPM // The rounds per minute of the weapon.
  • SWEP.Primary.ClipSize // How large every magazine is.
  • SWEP.Primary.DefaultClip // How much ammo the gun comes pre-loaded with when spawned.
  • SWEP.Primary.DropMagReload // Whether or not the weapon should drop the currently loaded magazine's ammo upon being reloaded. AKA if you have 22/30 rounds and you reload, if this is set to true you lose those 22 rounds. If set to false, you only lose the 8 rounds already shot.
  • SWEP.Primary.APS // How much ammo is consumed per shot.
  • SWEP.Primary.Tracer // https://wiki.garrysmod.com/page/Effects.
  • SWEP.Primary.ReloadHoldType // Holdtype that is used when the reload is called. https://wiki.garrysmod.com/page/Hold_Types
  • SWEP.Primary.Sound // Weapon's firing sound
  • SWEP.Primary.NPCSound // Firing sound used when an NPC has this weapon. If set to nil, will default to SWEP.Primary.Sound
  • SWEP.Primary.Projectile // Entity to fire, if set to nil fires bullet(s) instead.
  • SWEP.Primary.ProjSpeed // Speed at which to fire the entity.
  • SWEP.Primary.ProjInheritVelocity // Whether the entity inherits velocity from the player or not

Ironsights

  • SWEP.Secondary.Ironsights // Whether the weapon uses ironsights as a secondary function or not
  • SWEP.Secondary.SightsSuppressAnim // Prevents firing animations while sights are down
  • SWEP.Secondary.IronFOV // FOV the player's view is transitioned into. This will raise the FOV if it is higher than their own client setting.
  • SWEP.Secondary.Scoped // Whether or not the weapon uses a 2D scope
  • SWEP.Secondary.ScopeHideVM // Whether or not the viewmodel should be hidden while aiming down sights
  • SWEP.Secondary.IronFOVAlt // Not fully implemented yet
  • SWEP.Secondary.IronInFP // Directory to a wav or mp3 file to be played on the client of the player zooming in
  • SWEP.Secondary.IronOutFP // See above
  • SWEP.Secondary.ScopePitch // Alters the angle at which the player's aim is oriented vertically (in degrees) while aiming down sights
  • SWEP.Secondary.ScopeYOffset // Adjusts the Y (vertical) center of the 2D scope, allowing the scope to be raised or lowered to help align non-uniform scopes with the user's aim.
  • SWEP.Secondary.ScopeMat // Primary material for the scope. Should be a quarter image of the bottom-right corner of a scope. All four sections will automatically flip as needed. Can be either a vmt or a png. (Note, if you use a png file it MUST have .png at the end of this string)
  • SWEP.Secondary.Q2Mat // Override of ScopeMat for the 2nd quarter. Should still be formatted the same way as the ScopeMat texture.
  • SWEP.Secondary.Q3Mat // See above
  • SWEP.Secondary.Q4Mat // See above
  • SWEP.Secondary.ScopeCol // Tint for the Scope textures
  • SWEP.Secondary.ScopeBlur // Whether or not the scope should do a radial zoom-blur effect outside the scope's mask
  • SWEP.Secondary.ScopeBGCol // The colour of the blank canvas outside of the scope's textures.
  • SWEP.Secondary.ScopeScale // Scope size scale
  • SWEP.Secondary.ScopeWidth // Scope width scale
  • SWEP.Secondary.ScopeHeight // Scope height scale

Secondary Attack

  • All entries from Primary Attack except instead of SWEP.Primary use SWEP.Secondary

NPC Settings

  • SWEP.Weight // NPCs are able to pick up weapons based on the "weight", of the weapon. The higher the number then the more priority it has to an NPC. See the Half-Life: 2 Weapon Weights page for a list of relative weight numbers.
Clone this wiki locally