Garry's Mod

Garry's Mod

SWEP Construction Kit
Cutta 8 Mar, 2023 @ 11:37am
Ironsight Not Doing Anything (FIX)
Put This Under Your Created Swep


--------------------------------------------------------------------
--[[
IRON SIGHTS
]]

function SWEP:Deploy()
self.Weapon:SetNetworkedBool("Ironsights", false)
end

function SWEP:SetIronsights( b )
self.Weapon:SetNetworkedBool( "Ironsights", b )
end

function SWEP:GetViewModelPosition(pos, ang)
local IRONSIGHT_TIME = 0.5

if (!self.IronSightsPos) then return pos, ang end


local bmIron = self.Weapon:GetNetworkedBool("Ironsights")

if (bmIron != self.bmLastIron) then

self.bmLastIron = bmIron
self.fmIronTime = CurTime()

if (bmIron) then
self.SwayScale = -0.3
self.BobScale = 0.2
self.DrawCrosshair = false

else
self.SwayScale = -2
self.BobScale = 1.0
self.DrawCrosshair = false

end

end


local fmIronTime = self.fmIronTime or 0

if (!bmIron and fmIronTime < CurTime() - IRONSIGHT_TIME) then
return pos, ang
end

local Mul = 1.0

if (fmIronTime > CurTime() - IRONSIGHT_TIME) then

Mul = math.Clamp((CurTime() - fmIronTime) / IRONSIGHT_TIME, 0, 1)

if (!bmIron) then Mul = 1 - Mul end

end

local Offset = self.IronSightsPos

if (self.IronSightsAng) then

ang = ang * 1
ang:RotateAroundAxis(ang:Right(), self.IronSightsAng.x * Mul)
ang:RotateAroundAxis(ang:Up(), self.IronSightsAng.y * Mul)
ang:RotateAroundAxis(ang:Forward(), self.IronSightsAng.z * Mul)


end

local Right = ang:Right()
local Up = ang:Up()
local Forward = ang:Forward()



pos = pos + Offset.x * Right * Mul
pos = pos + Offset.y * Forward * Mul
pos = pos + Offset.z * Up * Mul

return pos, ang

end

SWEP.NextSecondaryAttack = 0

function SWEP:SecondaryAttack()
if ( !self.IronSightsPos ) then return end
if ( self.NextSecondaryAttack > CurTime() ) then return end

bIronsights = !self.Weapon:GetNetworkedBool( "Ironsights", false )

self:SetIronsights( bIronsights )

self.NextSecondaryAttack = CurTime() + 0.3
end

--[[
IRON SIGHTS
]]
----------------------------------------------------------------------------------