SWEP

From GMod Wiki

Revision as of 12:25, 18 September 2011 by Snyper (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Warning 64.pngThis page needs to be edited as it contains information that is unclear or incorrect. Improvement can be discussed on the talk page. Find more pages that need work here.
Details: None given.
Structure
Name SWEP
Available On: NewerShared.png
Description:
A SWEP is a Scripted Weapon, such as the weapons in the Weapons Menu. These weapons vary from melee weapons (such as knives or fists) to long-ranged weapons (such as sniper rifles) to prop/NPC spawners (such as Garry's Manhack Gun).

Other SWEPs you may have used are the Toolgun and Camera. SWEPs are written in Lua and reside in the lua/weapons directory.

Shared Members

Type Name Description
Boolean AdminSpawnable NewerShared.png If false, admins can't spawn that weapon (you can set to false for base weapons).
String AnimPrefix NewerShared.png This is for animations.
String Author NewerShared.png The Author of the SWEP.
String Base NewerShared.png The SWEP your SWEP is based on.
String Category NewerShared.png The category containing that Weapon. The SWEP menu sorts all the weapons of the same category together. You can create your own.
String Contact NewerShared.png An e-mail address to contact the author.
String Folder NewerShared.png The folder in which the SWEP files are located.
String Instructions NewerShared.png Short manual of how to use the weapon.
Number m_WeaponDeploySpeed NewerShared.png Multiplier of deploy speed.
Entity Owner NewerShared.png The entity that owns this SWEP.
Table Primary NewerShared.png Contains infos about the primary attack.
String Purpose NewerShared.png What the weapon is made for.
Table Secondary NewerShared.png Contains infos about the secondary attack.
Boolean Spawnable NewerShared.png If false, players can't spawn that weapon (you can set to false for base weapons).
String ViewModel NewerShared.png Path to the view model (the weapon viewed from the player's point of view). See the Weapon Models List.
Boolean ViewModelFlip NewerShared.png Should the view model be flipped? (left handed weapon).
Number ViewModelFOV NewerShared.png An angle of FOV used for the view model.
Entity Weapon NewerShared.png The Weapon object manipulated by the SWEP.
String WorldModel NewerShared.png Path to the world model (the weapon viewed on the ground or in hands of NPCs). See the Weapon Models List.
String HoldType NewerShared.png How the weapon is held. (pistol, smg, grenade, ar2, etc...)

Primary/Secondary Members

Type Name Description
String Ammo NewerShared.png Ammo type for the primary/secondary fire mode ("Pistol", "SMG" etc)
Boolean Automatic NewerShared.png Should the weapon keep firing if the player's mouse is still down?
Integer ClipSize NewerShared.png The size of a clip (how much you can shoot before you reload)
Integer DefaultClip NewerShared.png The default amount of ammo to give when you get the weapon

Server side Members

Type Name Description
Boolean AutoSwitchFrom NewerServer.png Auto switch from if you pick up a better weapon.
Boolean AutoSwitchTo NewerServer.png Auto switch to if we pick it up.
Integer Weight NewerServer.png Decides whether we should switch from/to this.

Client side Members

Type Name Description
Number BobScale NewerClient.png The scale of the viewmodel bob (1.0 should be the default).
Boolean BounceWeaponIcon NewerClient.png Should the weapon icon bounce?.
Boolean DrawAmmo NewerClient.png Should draw the default HL2 ammo counter.
Boolean DrawCrosshair NewerClient.png Should draw the default crosshair.
Boolean DrawWeaponInfoBox NewerClient.png Should draw the weapon info box.
String PrintName NewerClient.png 'Nice' Weapon name (Shown on HUD).
Integer RenderGroup NewerClient.png ?.
Integer Slot NewerClient.png Slot in the weapon selection menu.
Integer SlotPos NewerClient.png Position in the slot.
String SpeechBubbleLid NewerClient.png Path to a texture. This is the corner of the speech bubble.
Float SwayScale NewerClient.png The scale of the viewmodel sway (1.0 should be the default).
Integer WepSelectIcon NewerClient.png Path to an texture. Override this in your SWEP to set the icon in the weapon selection. This must be the texture ID, see surface.GetTextureID.
Boolean CSMuzzleFlashes NewerClient.png Should use Counter-Strike muzzle flashes upon firing

Example

DescriptionA default pistol, change the variables under SWEP.Primary and SWEP.Secondary
Used onNewerShared.png
Code
//General Settings \\ 
SWEP.PrintName 		= "Killa_Pistol" // The name of your SWEP 
 
SWEP.Author 		= "yaddablahdah" // Your name 
SWEP.Instructions 	= "SwepInstructions" // How do people use your SWEP? 
SWEP.Contact 		= "YourMailAdress" // How people should contact you if they find bugs, errors, etc 
SWEP.Purpose 		= "WhatsThePurposeOfThisSwep" // What is the purpose of the SWEP? 
 
SWEP.AdminSpawnable = true // Is the SWEP spawnable for admins? 
SWEP.Spawnable 		= false // Can everybody spawn this SWEP? - If you want only admins to spawn it, keep this false and admin spawnable true. 
 
SWEP.ViewModelFOV 	= 64 // How much of the weapon do you see? 
SWEP.ViewModel 		= "models/weapons/v_pistol.mdl" // The viewModel = the model you see when you're holding the weapon.
SWEP.WorldModel 	= "models/weapons/w_pistol.mdl" // The world model = the model you when it's down on the ground.
 
SWEP.AutoSwitchTo 	= false // When someone picks up the SWEP, should it automatically change to your SWEP? 
SWEP.AutoSwitchFrom = true // Should the weapon change to the a different SWEP if another SWEP is picked up?
 
SWEP.Slot 			= 1 // Which weapon slot you want your SWEP to be in? (1 2 3 4 5 6) 
SWEP.SlotPos = 1 // Which part of that slot do you want the SWEP to be in? (1 2 3 4 5 6) 
 
SWEP.HoldType = "Pistol" // How is the SWEP held? (Pistol SMG Grenade Melee) 
 
SWEP.FiresUnderwater = true // Does your SWEP fire under water?
 
SWEP.Weight = 5 // Set the weight of your SWEP. 
 
SWEP.DrawCrosshair = true // Do you want the SWEP to have a crosshair? 
 
SWEP.Category = "Biobastards" // Which weapon spawning category do you want your SWEP to be in?
 
SWEP.DrawAmmo = true // Does the ammo show up when you are using it? True / False 
 
SWEP.ReloadSound = "sound/owningyou.wav" // Reload sound, you can use the default ones, or you can use your own; Example; "sound/myswepreload.wav" 
 
SWEP.base = "weapon_base" //What your weapon is based on.
//General settings\\
 
//PrimaryFire Settings\\ 
SWEP.Primary.Sound = "sound/seeya.wav" // The sound that plays when you shoot your SWEP :-] 
SWEP.Primary.Damage = 1000 // How much damage the SWEP will do.
SWEP.Primary.TakeAmmo = 1 // How much ammo does the SWEP use each time you shoot?
SWEP.Primary.ClipSize = 100 // The clip size.
SWEP.Primary.Ammo = "Pistol" // The ammo used by the SWEP. (pistol/smg1) 
SWEP.Primary.DefaultClip = 100 // How much ammo do you get when you first pick up the SWEP? 
SWEP.Primary.Spread = 0.1 // Do the bullets spread all over when firing? If you want it to shoot exactly where you are aiming, leave it at 0.1 
SWEP.Primary.NumberofShots = 1 // How many bullets the SWEP fires each time you shoot. 
SWEP.Primary.Automatic = false // Is the SWEP automatic?
SWEP.Primary.Recoil = 10 // How much recoil does the weapon have?
SWEP.Primary.Delay = 3 // How long must you wait before you can fire again?
SWEP.Primary.Force = 1000 // The force of the shot.
//PrimaryFire settings\\
 
//Secondary Fire Variables\\ 
SWEP.Secondary.NumberofShots = 1 // How many explosions for each shot.
SWEP.Secondary.Force = 1000 // The force of the explosion.
SWEP.Secondary.Spread = 0.1 // How much of an area does the explosion affect? 
SWEP.Secondary.Sound = "sound/ultrakill.wav" // The sound that is made when you shoot.
SWEP.Secondary.DefaultClip = 100 // How much secondary ammo does the SWEP come with?
SWEP.Secondary.Automatic = false // Is it automactic? 
SWEP.Secondary.Ammo = "Pistol" // Leave as Pistol! 
SWEP.Secondary.Recoil = 10 // How much recoil does the secondary fire have?
SWEP.Secondary.Delay = 3 // How long you have to wait before firing another shot?
SWEP.Secondary.TakeAmmo = 1 // How much ammo does each shot take?
SWEP.Secondary.ClipSize = 100 // The size of the clip for the secondary ammo.
SWEP.Secondary.Damage = 1000 // The damage the explosion does. 
SWEP.Secondary.Magnitude = "175" // How big is the explosion ? 
//Secondary Fire Variables\\
 
//SWEP:Initialize\\ 
function SWEP:Initialize() //Tells the script what to do when the player "Initializes" the SWEP.
	util.PrecacheSound(self.Primary.Sound) 
	util.PrecacheSound(self.Secondary.Sound) 
        self:SetWeaponHoldType( self.HoldType )
end 
//SWEP:Initialize\\
 
//SWEP:PrimaryFire\\ 
function SWEP:PrimaryAttack()
 
	if ( !self:CanPrimaryAttack() ) then return end
 
	local bullet = {} 
		bullet.Num = self.Primary.NumberofShots //The number of shots fired
		bullet.Src = self.Owner:GetShootPos() //Gets where the bullet comes from
		bullet.Dir = self.Owner:GetAimVector() //Gets where you're aiming
		bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
                //The above, sets how far the bullets spread from each other. 
		bullet.Tracer = 0 
		bullet.Force = self.Primary.Force 
		bullet.Damage = self.Primary.Damage 
		bullet.AmmoType = self.Primary.Ammo 
 
	local rnda = self.Primary.Recoil * -1 
	local rndb = self.Primary.Recoil * math.random(-1, 1) 
 
	self:ShootEffects()
 
	self.Owner:FireBullets( bullet ) 
	self:EmitSound(Sound(self.Primary.Sound)) 
	self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) ) 
	self:TakePrimaryAmmo(self.Primary.TakeAmmo) 
 
	self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) 
end 
//SWEP:PrimaryFire\\
 
//SWEP:SecondaryFire\\ 
function SWEP:SecondaryAttack() 
	if ( !self:CanSecondaryAttack() ) then return end 
 
	local rnda = -self.Secondary.Recoil 
	local rndb = self.Secondary.Recoil * math.random(-1, 1) 
 
	self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) ) //Makes the gun have recoil
        //Don't change self.Owner:ViewPunch() if you don't know what you are doing.
 
	local eyetrace = self.Owner:GetEyeTrace()
	self:EmitSound ( self.Secondary.Sound ) //Adds sound
	self:ShootEffects() 
	local explode = ents.Create("env_explosion")
		explode:SetPos( eyetrace.HitPos ) //Puts the explosion where you are aiming
		explode:SetOwner( self.Owner ) //Sets the owner of the explosion
		explode:Spawn()
		explode:SetKeyValue("iMagnitude","175") //Sets the magnitude of the explosion
		explode:Fire("Explode", 0, 0 ) //Tells the explode entity to explode
		explode:EmitSound("weapon_AWP.Single", 400, 400 ) //Adds sound to the explosion
 
	self:SetNextPrimaryFire( CurTime() + self.Secondary.Delay ) 
	self:SetNextSecondaryFire( CurTime() + self.Secondary.Delay ) 
	self:TakePrimaryAmmo(self.Secondary.TakeAmmo) 
end 
//SWEP:SecondaryFire\\
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox