• Using SWEP:AdjustMouseSensitivity()
    2 replies, posted
Hello. So, for a sniper rifle SWEP I'm making, I've been trying to get SWEP:AdjustMouseSensitivity() to make the sensitivity lower when a player is scoping in with their weapon(code ahead), but I've had no luck. This is my current code for the whole SWEP: [code]AddCSLuaFile() --General SWEP.Base = "dm_baseweapon" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.Category = "The CyBorg SWEPs" SWEP.PrintName = "SteyrScout" --View Model SWEP.ViewModelFOV = 52 SWEP.ViewModel = "models/weapons/cstrike/c_snip_scout.mdl" SWEP.ViewModelFlip = false SWEP.UseHands = true --World Model SWEP.WorldModel = "models/weapons/w_snip_scout.mdl" SWEP.HoldType = "ar2" --Primary SWEP.Primary.FireSound = "Weapon_Scout.Single" SWEP.Primary.NumShots = 1 SWEP.Primary.Damage = 50 SWEP.Primary.Recoil = 4 SWEP.Primary.Spread = 0.01 SWEP.Primary.Delay = 1.40 SWEP.Primary.ClipSize = 10 SWEP.Primary.DefaultClip = 50 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "ar2" --Secondary SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" function SWEP:Initialize() self:SetHoldType( "ar2" ) self:SetNWBool( "Scoping", false ) end function SWEP:SetScoping( b ) self.Weapon:SetNWBool( "Scoping", b ) end SWEP.SprintPos = Vector(1.52, 0, 0.959) SWEP.SprintAng = Vector(-9.146, 4.925, 0) function SWEP:SetZoom(state) if CLIENT then return elseif IsValid(self.Owner) and self.Owner:IsPlayer() then if state then self.Owner:SetFOV(10, 0.3) else self.Owner:SetFOV(0, 0.2) end end end if CLIENT then local scope = surface.GetTextureID("sprites/scope") function SWEP:DrawHUD() if self:GetNWBool( "Scoping" ) == true 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 end end end function SWEP:Reload() self:DefaultReload( ACT_VM_RELOAD ) self:SetScoping( false ) self:SetZoom( false ) end function SWEP:Holster() self:SetScoping(false) self:SetZoom(false) return true end --Secondary Attack Function function SWEP:SecondaryAttack() local bScope = not self:GetNWBool( "Scoping", false ) self:SetScoping( bScope ) if SERVER then self:SetZoom(bScope) else self:EmitSound("Default.Zoom") end self:SetNextSecondaryFire( CurTime() + 0.3) end [/code] Yes, I did borrow some code from TTT's rifle but that's not the point. How would I go about making AdjustMouseSensitivity only adjust the mouse sensitivity when you're scoping in?
Just use this thing I made: [code] function SWEP:AdjustMouseSensitivity() if ( !self:GetZoom() ) then return nil end return self.Owner:GetFOV() / GetConVarNumber( "fov_desired" ) / 2 end[/code] Don't forget to add SWEP:GetZoom() function clientside.
Thanks! it works perfectly. [code]function SWEP:AdjustMouseSensitivity() if ( !self:GetNWBool( "Scoping" ) ) then return nil end return self.Owner:GetFOV() / GetConVarNumber( "fov_desired" ) / 2 end[/code]
Sorry, you need to Log In to post a reply to this thread.