Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Last active March 23, 2018 22:57
Show Gist options
  • Save CapsAdmin/b036f1913dbaec0e69434c3a0eedff36 to your computer and use it in GitHub Desktop.
Save CapsAdmin/b036f1913dbaec0e69434c3a0eedff36 to your computer and use it in GitHub Desktop.
local SWEP = weapons.Get("gmod_tool")
local TOOL = getmetatable(SWEP.Tool.weld):Create()
TOOL.Mode = "test"
do
-- Remove this to add it to the menu
TOOL.AddToMenu = true
-- Define these!
TOOL.Category = "My Category" -- Name of the category
TOOL.Name = "#tool.example.name" -- Name to display. # means it will be translated ( see below )
--if ( true ) then return end -- Don't actually run anything below, remove this to make everything below functional
if ( CLIENT ) then -- We can only use language.Add on client
language.Add( "tool.example.name", "My example tool" ) -- Add translation
end
-- An example clientside convar
TOOL.ClientConVar[ "CLIENTSIDE" ] = "default"
-- An example serverside convar
TOOL.ServerConVar[ "SERVERSIDE" ] = "default"
-- This function/hook is called when the player presses their left click
function TOOL:LeftClick( trace )
Msg( "PRIMARY FIRE\n" )
end
-- This function/hook is called when the player presses their right click
function TOOL:RightClick( trace )
Msg( "ALT FIRE\n" )
end
-- This function/hook is called when the player presses their reload key
function TOOL:Reload( trace )
-- The SWEP doesn't reload so this does nothing :(
Msg( "RELOAD\n" )
end
-- This function/hook is called every frame on client and every tick on the server
function TOOL:Think()
end
end
TOOL:CreateConVars()
SWEP.Tool[ TOOL.Mode ] = TOOL
for _, wep in pairs(ents.FindByClass("gmod_tool")) do
wep.Tool[TOOL.Mode] = table.Copy(TOOL)
wep.Tool[TOOL.Mode].SWEP = wep
wep.Tool[TOOL.Mode].Owner = wep:GetOwner()
wep.Tool[TOOL.Mode].Weapon = wep
wep.Tool[TOOL.Mode]:Init()
end
if SERVER then
if not me:HasWeapon("gmod_tool") then
me:Give("gmod_tool")
end
me:SelectWeapon("gmod_tool")
local wep = me:GetActiveWeapon()
if wep:IsValid() then
if wep.Holster then
wep:Holster()
end
wep.Mode = TOOL.Mode
if wep.Deploy then
wep:Deploy()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment