TTT Silenced Sniper

So I’ve made this TTT Silenced Sniper basing on other SWEP, although, while weapon works, it allows you to have two weapons on third slot. Dunno really what’s the problem, so maybe you guys could help me out?


if SERVER then

   AddCSLuaFile( "shared.lua" )   
   resource.AddFile("materials/VGUI/ttt/icon_snajperka.png")
end

SWEP.HoldType           = "ar2"

if CLIENT then
   
   SWEP.PrintName          = "Silenced Sniper"           
   SWEP.Slot               = 2
   SWEP.Icon = "VGUI/ttt/icon_g3sg1"    
   SWEP.EquipMenuData = {
          type = "item_weapon",
          desc = [[A silenced sniper. Because what's better than 
		  killing someone and getting away with it?]]
       };
end


SWEP.Base               = "weapon_tttbase"
SWEP.Kind = WEAPON_HEAVY
SWEP.WeaponID = AMMO_RIFLE
SWEP.Primary.Delay          = 2
SWEP.Primary.Recoil         = 4
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "snajperka"
SWEP.Primary.Damage = 80
SWEP.Primary.Cone = 0.006
SWEP.Primary.ClipSize = 3
SWEP.Primary.ClipMax = 3 -- keep mirrored to ammo
SWEP.Primary.DefaultClip = 3
SWEP.HeadshotMultiplier = 5
SWEP.LimitedStock = true
SWEP.IsSilent = true
SWEP.AllowDrop = true
SWEP.AutoSpawnable = false
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR}
SWEP.ViewModel = "models/weapons/v_snip_g3sg1.mdl"
SWEP.WorldModel = "models/weapons/w_snip_g3sg1.mdl"
SWEP.Icon = "VGUI/ttt/icon_snajperka"
SWEP.Primary.Sound = Sound ("Weapon_M4A1.Silenced")


SWEP.Secondary.Sound = Sound("Default.Zoom")

SWEP.IronSightsPos      = Vector( 5, -15, -2 )
SWEP.IronSightsAng      = Vector( 2.6, 1.37, 3.5 )

function SWEP:SetZoom(state)
    if CLIENT then 
       return
    else
       if state then
          self.Owner:SetFOV(20, 0.3)
       else
          self.Owner:SetFOV(0, 0.2)
       end
    end
end

-- Add some zoom to ironsights for this gun
function SWEP:SecondaryAttack()
    if not self.IronSightsPos then return end
    if self.Weapon:GetNextSecondaryFire() > CurTime() then return end
    
    bIronsights = not self:GetIronsights()
    
    self:SetIronsights( bIronsights )
    
    if SERVER then
        self:SetZoom(bIronsights)
     else
        self:EmitSound(self.Secondary.Sound)
    end
    
    self.Weapon:SetNextSecondaryFire( CurTime() + 0.3)
end

function SWEP:PreDrop()
    self:SetZoom(false)
    self:SetIronsights(false)
    return self.BaseClass.PreDrop(self)
end

function SWEP:Reload()
    self.Weapon:DefaultReload( ACT_VM_RELOAD );
    self:SetIronsights( false )
    self:SetZoom(false)
end


function SWEP:Holster()
    self:SetIronsights(false)
    self:SetZoom(false)
    return true
end

if CLIENT then
   local scope = surface.GetTextureID("sprites/scope")
   function SWEP:DrawHUD()
      if self:GetIronsights() then
         surface.SetDrawColor( 0, 0, 0, 255 )
         
         local x = ScrW() / 2.0
         local y = ScrH() / 2.0
         local scope_size = ScrH()

         -- crosshair
         local gap = 80
         local length = scope_size
         surface.DrawLine( x - length, y, x - gap, y )
         surface.DrawLine( x + length, y, x + gap, y )
         surface.DrawLine( x, y - length, x, y - gap )
         surface.DrawLine( x, y + length, x, y + gap )

         gap = 0
         length = 50
         surface.DrawLine( x - length, y, x - gap, y )
         surface.DrawLine( x + length, y, x + gap, y )
         surface.DrawLine( x, y - length, x, y - gap )
         surface.DrawLine( x, y + length, x, y + gap )


         -- cover edges
         local sh = scope_size / 2
         local w = (x - sh) + 2
         surface.DrawRect(0, 0, w, scope_size)
         surface.DrawRect(x + sh - 2, 0, w, scope_size)

         surface.SetDrawColor(255, 0, 0, 255)
         surface.DrawLine(x, y, x + 1, y + 1)

         -- scope
         surface.SetTexture(scope)
         surface.SetDrawColor(255, 255, 255, 255)

         surface.DrawTexturedRectRotated(x, y, scope_size, scope_size, 0)

      else
         return self.BaseClass.DrawHUD(self)
      end
   end

   function SWEP:AdjustMouseSensitivity()
      return (self:GetIronsights() and 0.2) or nil
   end
end

Make it for Slot 7 or 8 like all Traitor weapons are supposed to be, preferably slot 7.

The gamemode allows you to have 2 weapons in slot 3 because when you buy the weapon from the Traitor store, it equips the gun right away, which results in you having 2 guns in your third slot, because you have the slot in the traitor weapon set as slot 3.

In your code you have set SWEP.Kind twice, once on line 23 and again on line 39.

I would suggest he cleans up his code before asking any more questions. You can see he has a duplicate of declaring the icon too.

I’ve created a Slot 3 Traitor Weapon, but it doesn’t do that.

Just tried it with the silenced pistol set to slot 3.

Yes it does.

I wouldn’t do this either way because it conflicts with other weapons that are slot 3 that you can automatically pick up.

If you still want to have your weapon in slot 3, change SWEP.Kind to equal “WEAPON_HEAVY”.

Hmm, never did that with mine

Changed to WEAPON_EQUIP but still does the sae.

hey i made one of these and it used to do that.
but this is my code and it works like intended now


if SERVER then
   AddCSLuaFile( "shared.lua" )
   resource.AddFile("materials/vgui/ttt/icon_herottt_sirifle2.vmt");
   resource.AddFile("materials/vgui/ttt/icon_herottt_sirifle2.vtf");
end

SWEP.HoldType           = "ar2"

if CLIENT then
   SWEP.PrintName          = "Silenced Rifle"
   SWEP.Slot               = 2
   
      SWEP.EquipMenuData = {
      type = "item_weapon",
      desc = "Low body damage, 10x headshot multiplier"
   };

   SWEP.Icon = "vgui/ttt/icon_herottt_sirifle2"
end


SWEP.Base               = "weapon_tttbase"

SWEP.Kind = WEAPON_HEAVY
SWEP.CanBuy = {ROLE_TRAITOR}

SWEP.Primary.Delay          = 1.5
SWEP.Primary.Recoil         = 7
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "357"
SWEP.Primary.Damage = 35
SWEP.Primary.Cone = 0.005
SWEP.Primary.ClipSize = 6
SWEP.Primary.ClipMax = 12 -- keep mirrored to ammo
SWEP.Primary.DefaultClip = 6

SWEP.HeadshotMultiplier = 10

SWEP.AmmoEnt = "item_ammo_357_ttt"

SWEP.IsSilent = true

SWEP.UseHands			= true
SWEP.ViewModelFlip		= false
SWEP.ViewModelFOV		= 54
SWEP.ViewModel          = Model("models/weapons/cstrike/c_snip_scout.mdl")
SWEP.WorldModel         = Model("models/weapons/w_snip_scout.mdl")

SWEP.Primary.Sound = Sound("weapons/usp/usp1.wav")
SWEP.Primary.SoundLevel = 50

SWEP.Secondary.Sound = Sound("Default.Zoom")

SWEP.IronSightsPos      = Vector( 5, -15, -2 )
SWEP.IronSightsAng      = Vector( 2.6, 1.37, 3.5 )

function SWEP:SetZoom(state)
    if CLIENT then 
       return
    elseif IsValid(self.Owner) and self.Owner:IsPlayer() then
       if state then
          self.Owner:SetFOV(20, 0.3)
       else
          self.Owner:SetFOV(0, 0.2)
       end
    end
end

-- Add some zoom to ironsights for this gun
function SWEP:SecondaryAttack()
    if not self.IronSightsPos then return end
    if self.Weapon:GetNextSecondaryFire() > CurTime() then return end
    
    bIronsights = not self:GetIronsights()
    
    self:SetIronsights( bIronsights )
    
    if SERVER then
        self:SetZoom(bIronsights)
     else
        self:EmitSound(self.Secondary.Sound)
    end
    
    self.Weapon:SetNextSecondaryFire( CurTime() + 0.3)
end

function SWEP:PreDrop()
    self:SetZoom(false)
    self:SetIronsights(false)
    return self.BaseClass.PreDrop(self)
end

function SWEP:Reload()
    self.Weapon:DefaultReload( ACT_VM_RELOAD );
    self:SetIronsights( false )
    self:SetZoom(false)
end


function SWEP:Holster()
    self:SetIronsights(false)
    self:SetZoom(false)
    return true
end

if CLIENT then
   local scope = surface.GetTextureID("sprites/scope")
   function SWEP:DrawHUD()
      if self:GetIronsights() then
         surface.SetDrawColor( 0, 0, 0, 255 )
         
         local x = ScrW() / 2.0
         local y = ScrH() / 2.0
         local scope_size = ScrH()

         -- crosshair
         local gap = 80
         local length = scope_size
         surface.DrawLine( x - length, y, x - gap, y )
         surface.DrawLine( x + length, y, x + gap, y )
         surface.DrawLine( x, y - length, x, y - gap )
         surface.DrawLine( x, y + length, x, y + gap )

         gap = 0
         length = 50
         surface.DrawLine( x - length, y, x - gap, y )
         surface.DrawLine( x + length, y, x + gap, y )
         surface.DrawLine( x, y - length, x, y - gap )
         surface.DrawLine( x, y + length, x, y + gap )


         -- cover edges
         local sh = scope_size / 2
         local w = (x - sh) + 2
         surface.DrawRect(0, 0, w, scope_size)
         surface.DrawRect(x + sh - 2, 0, w, scope_size)

         surface.SetDrawColor(255, 0, 0, 255)
         surface.DrawLine(x, y, x + 1, y + 1)

         -- scope
         surface.SetTexture(scope)
         surface.SetDrawColor(255, 255, 255, 255)

         surface.DrawTexturedRectRotated(x, y, scope_size, scope_size, 0)

      else
         return self.BaseClass.DrawHUD(self)
      end
   end

   function SWEP:AdjustMouseSensitivity()
      return (self:GetIronsights() and 0.2) or nil
   end
end


edit the icons of course for you personally and make any adjustments :smiley: