I was wondering if its possibly to have ironsight in normal weapon_base? If so how would I do this?
Someone awnser. =C
I to would like to know this, are you using that swep base on gmod.org, the one they guy wants to get 5000 downloads for?
[QUOTE=CaMpEr_DoOd;18334964]I to would like to know this, are you using that swep base on gmod.org, the one they guy wants to get 5000 downloads for?[/QUOTE]
Im unshure on what one that is. But I mean the default weapon base. The one I think is used in Half-Life 2
[QUOTE=Battlepope02;18342999]The one I think is used in Half-Life 2[/QUOTE]
Half-Life 2 doesn't use Lua for guns.
Put this in the shared.lua file somewhere.
[code]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
/*---------------------------------------------------------
DrawHUD
Just a rough mock up showing how to draw your own crosshair.
---------------------------------------------------------*/
function SWEP:DrawHUD()
// No crosshair when ironsights is on
if ( self.Weapon:GetNetworkedBool( "Ironsights" ) ) then return end
local x = ScrW() / 2.0
local y = ScrH() / 2.0
local scale = 10 * self.Primary.Cone
// Scale the size of the crosshair according to how long ago we fired our weapon
local LastShootTime = self.Weapon:GetNetworkedFloat( "LastShootTime", 0 )
scale = scale * (2 - math.Clamp( (CurTime() - LastShootTime) * 5, 0.0, 1.0 ))
surface.SetDrawColor( 0, 255, 0, 255 )
// Draw an awesome crosshair
local gap = 40 * scale
local length = gap + 20 * scale
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 )
end
/*---------------------------------------------------------
onRestore
Loaded a saved game (or changelevel)
---------------------------------------------------------*/
function SWEP:OnRestore()
self.NextSecondaryAttack = 0
self:SetIronsights( false )
end[/code]
After that, put this code somewhere.
[code]SWEP.Primary.Cone = 0.02[/code]
Then use Iron sights creator to get where the iron sight will be. Put this in the code first so it won't make a million errors.
[code]
SWEP.IronSightsPos = Vector (4.5313, -0.8637, 3.2683)
SWEP.IronSightsAng = Vector (-0.088, -0.1113, 0)[/code]
Use this to get the iron sights for the view model you are using. [url]http://www.garrysmod.org/downloads/?a=view&id=29787[/url]
[QUOTE=mescool15;18367055]Put this in the shared.lua file somewhere.[/QUOTE]
Awesome, thanks.
Sorry, you need to Log In to post a reply to this thread.