• IronSights?
    6 replies, posted
Hey guys, Yes...I have a SWEP question...I know I know, don't go all crazy. But, I just need help with this one tiny thing. I've been trying to add ironsights to something, but it just does not work. I use: [CODE]SWEP.IronSightsPos = Vector(0, 0, 0) SWEP.IronSightsAng = Vector(0, 0, 0)[/CODE] But, nope. Does not work. Any ideas guys?
they dont do anything on a standard swep, you need to utilize them on your own. the client side of a swep has a function called GetViewModelPosition(pos, ang) return the position and angle you want the view model to be at
[lua]local IRONSIGHT_TIME = 0.25 /*--------------------------------------------------------- Name: GetViewModelPosition Desc: Allows you to re-position the view model ---------------------------------------------------------*/ function SWEP:GetViewModelPosition( pos, ang ) if ( !self.IronSightsPos ) then return pos, ang end local bIron = self.Weapon:GetNetworkedBool( "Ironsights" ) if ( bIron != self.bLastIron ) then self.bLastIron = bIron self.fIronTime = CurTime() if ( bIron ) then self.SwayScale = 0.3 self.BobScale = 0.1 else self.SwayScale = 1.0 self.BobScale = 1.0 end end local fIronTime = self.fIronTime or 0 if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then return pos, ang end local Mul = 1.0 if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 ) if (!bIron) 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 /*--------------------------------------------------------- SetIronsights ---------------------------------------------------------*/ function SWEP:SetIronsights( b ) self.Weapon:SetNetworkedBool( "Ironsights", b ) end SWEP.NextSecondaryAttack = 0 /*--------------------------------------------------------- SecondaryAttack ---------------------------------------------------------*/ 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[/lua] I think this is the simplest one out there. Straight from Gmod 12 CS:S sweps.
Hm alright I'll try both of these. The only thing that I think may happen is. If I make a secondary attack the ironsights. I'm wondering if it will later not let me use the primary fire.
It doesn't affect PrimaryAttack function in any way.
Sorry for being a pain. But, it still doesn't work.
Copypaste the code here or PM it to me.
Sorry, you need to Log In to post a reply to this thread.