SWEP framework

From GMod Wiki

Jump to: navigation, search


Scripted Weapons: SWEP Framework

Yarin Kaul Icon Lua48.png
Description:A commented framework for basing your sweps off, or if you just don't feel like typing it all out!
Original Author(s):Terence

Place all these files, in a folder, in:

Steamapps/<Steam Name>/Garrysmod/Garrysmod/lua/weapons/<Weapon_name>/

init.lua

 
AddCSLuaFile ("cl_init.lua")
AddCSLuaFile ("shared.lua")
 
include ("shared.lua")
 
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
 

cl_init.lua

 
include('shared.lua')
 
SWEP.PrintName          = "---SWEP NAME---"
SWEP.Slot               = 5
SWEP.SlotPos            = 1
SWEP.DrawAmmo           = false
SWEP.DrawCrosshair      = false
 

shared.lua

 
// Show debug info?
local debug = true
 
//----------------------------------------------
//Author Info
//----------------------------------------------
SWEP.Author             = "--- AUTHOR NAME ---"
SWEP.Contact            = "--- CONTACT EMAIL ---"
SWEP.Purpose            = "--- PURPOSE ---"
SWEP.Instructions       = "--- INSTRUCTIONS ---"
//----------------------------------------------
 
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
// First person Model
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
// Third Person Model
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
// Weapon Details
SWEP.Primary.Clipsize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.Clipsize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
// Sound
local ShootSound = Sound ("Metal.SawbladeStick")
 
 
//--------------------------------------------
// Called when it reloads 
//--------------------------------------------
function SWEP:Reload()
	if debug then
		print("Reload")
		// Shove your debugging code in here
	end
 
	// All reload code goes in here
end
 
 
//--------------------------------------------
// Called each frame when the Swep is active
//--------------------------------------------
function SWEP:Think()
 
end
 
 
//--------------------------------------------
// Called when the player Shoots
//--------------------------------------------
function SWEP:PrimaryAttack()
	if debug then
		print("Primary Attack")
		// Put Your debugging Code in here
	end
 
	// Any Code you want to be executed when the player uses primary attack goes in here
	self:EmitSound(ShootSound)
end
 
 
//--------------------------------------------
// Called when the player Uses secondary attack
//--------------------------------------------
function SWEP:SecondaryAttack()
	if debug then
		print("Secondary Attack")
		// Put your debugging code in here
	end
 
	// Any Code you want to my executed when the player uses secondary attack goes in here
	self:EmitSound(ShootSound)
end
 


Settings you can change are inbetween ---'s :)

I have put these into lua files and formatted them so it looks normal, instead of the weird thing that happens when you copy and paste. Download the 7z file here or the zip file here. By Lithium 12:13, 19 December 2006 (GMT Standard Time)

See: Garry's Example SWEP

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox