• TTT custom sniper cone spread bug
    2 replies, posted
Hello Facepunch forums! So I've created a sniper in ttt where when scoped it has 0.0001 spread while the hipfire has 0.5 as its spread. However when I drop the weapon while scoped and pick it up again, the hipfire has the spread as if I was aiming down the scope. I've added self.Primary.Cone = 0.5 under the PreDrop function but that dosen't seem to do anything. But when I put self.Primary.Cone = 0.5 under the reload function it worked just fine whenever I reloaded. Here is the code for the sniper: AddCSLuaFile() SWEP.HoldType              = "ar2" if CLIENT then    SWEP.PrintName          = "Barret-M82"    SWEP.Slot               = 2    SWEP.ViewModelFlip      = true    SWEP.ViewModelFOV       = 70 end SWEP.Base                  = "weapon_tttbase" SWEP.Kind                  = WEAPON_HEAVY SWEP.WeaponID              = AMMO_RIFLE SWEP.Primary.Delay         = 1.6 SWEP.Primary.Recoil        = 8.4 SWEP.Primary.Automatic     = false SWEP.Primary.Ammo          = "357" SWEP.Primary.Damage        = 80 SWEP.Primary.Cone          = 0.5 SWEP.Primary.ClipSize      = 10 SWEP.Primary.DefaultClip   = 10 SWEP.Primary.AmmoMax       = 20 SWEP.Primary.Sound         = Sound( "BarretM82.Single" ) SWEP.HeadshotMultiplier    = 4 SWEP.Secondary.Sound       = Sound("Default.Zoom") SWEP.AutoSpawnable         = true SWEP.Spawnable             = true SWEP.AmmoEnt               = "item_ammo_357_ttt" SWEP.UseHands              = true SWEP.ViewModel             = "models/weapons/v_50calm82.mdl" SWEP.WorldModel            = "models/weapons/w_barret_m82.mdl" SWEP.IronSightsPos      = Vector( 5, -15, -2 ) SWEP.IronSightsAng      = Vector( 2.6, 1.37, 3.5 ) --SWEP.IronSightsPos = Vector (2.894, 0, -3) --SWEP.IronSightsAng = Vector (0, 0, 0) --SWEP.SightsPos = Vector (2.894, 0, 1.7624) --SWEP.SightsAng = Vector (0, 0, 0) --SWEP.RunSightsPos = Vector (-2.3095, -3.0514, 2.3965) --SWEP.RunSightsAng = Vector (-19.8471, -33.9181, 10) function SWEP:SetZoom(state)    if IsValid(self:GetOwner()) and self:GetOwner():IsPlayer() then       if state then          self:GetOwner():SetFOV(20, 0.3)          self.Primary.Cone = 0.0001       else          self:GetOwner():SetFOV(0, 0.2)          self.Primary.Cone = 0.5       end    end end function SWEP:PrimaryAttack( worldsnd )    self.BaseClass.PrimaryAttack( self.Weapon, worldsnd )    self:SetNextSecondaryFire( CurTime() + 0 ) end -- Add some zoom to ironsights for this gun function SWEP:SecondaryAttack()    if not self.IronSightsPos then return end    if self:GetNextSecondaryFire() > CurTime() then return end    local bIronsights = not self:GetIronsights()    self:SetIronsights( bIronsights )    self:SetZoom(bIronsights)    if (CLIENT) then       self:EmitSound(self.Secondary.Sound)    end    self:SetNextSecondaryFire( CurTime() + 0) end function SWEP:PreDrop()    self:SetZoom(false)    self:SetIronsights(false)    self.Primary.Cone = 0.5    return self.BaseClass.PreDrop(self) end function SWEP:Reload()  if ( self:Clip1() == self.Primary.ClipSize or self:GetOwner():GetAmmoCount( self.Primary.Ammo ) <= 0 ) then return end    self:DefaultReload( ACT_VM_RELOAD )    self:SetIronsights( false )    self:SetZoom( false )    self.Primary.Cone = 0.5 end function SWEP:Holster()    self:SetIronsights(false)    self:SetZoom(false)    self.Primary.Cone = 0.5    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 scrW = ScrW()          local scrH = ScrH()          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)                   -- cover gaps on top and bottom of screen          surface.DrawLine( 0, 0, scrW, 0 )          surface.DrawLine( 0, scrH - 1, scrW, scrH - 1 )          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
This is a very bad way. Just override this.
Thanks man! after putting that function in the swep and changing around some things I got it to work very nicely!
Sorry, you need to Log In to post a reply to this thread.