Sound system and recoil

This commit is contained in:
Fesiug 2023-12-21 16:15:25 -05:00
parent 3282cb3a7f
commit 164119295f
45 changed files with 179 additions and 31 deletions

View File

@ -3,12 +3,15 @@ function SWEP:Reload()
if self:GetDelay() > CurTime() then if self:GetDelay() > CurTime() then
return false return false
end end
if self:GetDelayReload() > CurTime() then
return false
end
if self:Clip1() >= self.Primary.ClipSize then if self:Clip1() >= self.Primary.ClipSize then
return false return false
end end
self:SendWeaponAnim( ACT_VM_RELOAD ) self:SendWeaponAnim( ACT_VM_RELOAD )
self:GetOwner():GetViewModel():SetPlaybackRate( 2.5 ) self:GetOwner():GetViewModel():SetPlaybackRate( 2.5 )
self:SetDelay( CurTime() + self:SequenceDuration()/2.5 ) self:SetDelayReload( CurTime() + self:SequenceDuration()/2.5 )
self:SetClip1( self.Primary.ClipSize ) self:SetClip1( self.Primary.ClipSize )
return true return true
end end

View File

@ -1,6 +1,6 @@
function SWEP:Spread() function SWEP:Spread()
local spread = math.Clamp( math.TimeFraction( self.SpreadBurstStart, self.SpreadBurstEnd, self:GetBurstCount() ), 0, 1 ) local spread = self:GetBubbleSpread()
spread = Lerp( spread, self.SpreadStart, self.SpreadEnd ) spread = Lerp( spread, self.SpreadStart, self.SpreadEnd )
return spread return spread
end end
@ -9,6 +9,9 @@ function SWEP:PrimaryAttack( mine )
if self:GetDelay() > CurTime() then if self:GetDelay() > CurTime() then
return false return false
end end
if self:GetDelayReload() > CurTime() then
return false
end
if self:Clip1() == 0 then if self:Clip1() == 0 then
self:EmitSound( "weapons/clipempty_rifle.wav", 90, 100, 1, CHAN_STATIC ) self:EmitSound( "weapons/clipempty_rifle.wav", 90, 100, 1, CHAN_STATIC )
self:SetDelay( CurTime() + self.Delay ) self:SetDelay( CurTime() + self.Delay )
@ -24,22 +27,48 @@ function SWEP:PrimaryAttack( mine )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self:SetClip1( self:Clip1() - 1 ) self:SetClip1( self:Clip1() - 1 )
self:EmitSound( self.Sound_Shoot, 90, 100, 1, CHAN_WEAPON ) self:EmitSound( self.Sound_Fire[ math.random( 1, #self.Sound_Fire ) ], 90, 100, 1, CHAN_STATIC )
self:EmitSound( self.Sound_Mech[ math.random( 1, #self.Sound_Mech ) ], 90, 100, 0.125, 255+2 )
local dir = self:GetOwner():EyeAngles()
local newdir = Vector()
local spread = math.rad( self:Spread() ) local spread = math.rad( self:Spread() )
do
local radius = util.SharedRandom("CNR_WepRand1_" .. 1, 0, 1 )
local theta = util.SharedRandom("CNR_WepRand2_" .. 1, 0, math.rad(360) )
local x = radius * math.sin(theta)
local y = radius * math.cos(theta)
newdir:Set( dir:Forward() + (dir:Right() * spread * x) + (dir:Up() * spread * y) )
end
self:FireBullets( { self:FireBullets( {
Attacker = self:GetOwner(), Attacker = self:GetOwner(),
Tracer = 1, Tracer = 1,
Damage = 25, Damage = 25,
Force = 1, Force = 1,
Num = 1, Num = 1,
Dir = self:GetOwner():EyeAngles():Forward(), Dir = newdir,
Spread = Vector( spread, spread, 0 ), Spread = vector_origin,
Src = self:GetOwner():EyePos(), Src = self:GetOwner():EyePos(),
Callback = function( attacker, tr, dmginfo ) Callback = function( attacker, tr, dmginfo )
end end
}) })
do
if ( !game.SinglePlayer() and CLIENT and IsFirstTimePredicted() ) then
local recoil = {}
recoil.up = util.SharedRandom( "CNR_WepRecoil", -1, 1 ) * self.RecoilUp
recoil.speed = math.max( 1, self.RecoilSpeed ) -- how much to move in a second
recoil.dist = Lerp( self:GetBubbleRecoil(), self.RecoilDistStart, self.RecoilDistEnd ) -- total distance to travel
table.insert( self.RecoilTable, recoil )
end
end
return true return true
end end

View File

@ -5,12 +5,27 @@ function SWEP:Think()
local p = self:GetOwner() local p = self:GetOwner()
if CLIENT and IsFirstTimePredicted() then if CLIENT and IsFirstTimePredicted() then
for i, v in pairs( self.RecoilTable ) do for i, data in pairs( self.RecoilTable ) do
local ft = FrameTime()
local fp = ft * data.speed
data.dist = math.Approach( data.dist, 0, fp )
local m_p, m_y = math.cos(math.rad(data.up)), math.sin(math.rad(data.up))
local p_p, p_y = m_p * fp, m_y * fp
p:SetEyeAngles( p:EyeAngles() - Angle( p_p, p_y, 0 ) )
if data.dist == 0 then
self.RecoilTable[i] = nil
end
end end
end end
if !p:KeyDown( IN_ATTACK ) then if !p:KeyDown( IN_ATTACK ) then
self:SetBurstCount( 0 ) self:SetBurstCount( 0 )
end end
local up = self:GetDelay() > CurTime()-engine.TickInterval()
self:SetBubbleSpread( math.Approach( self:GetBubbleSpread(), up and 1 or 0, FrameTime()/(up and self.BubbleSpreadUp or self.BubbleSpreadDown) ) )
self:SetBubbleRecoil( math.Approach( self:GetBubbleRecoil(), up and 1 or 0, FrameTime()/(up and self.BubbleRecoilUp or self.BubbleRecoilDown) ) )
end end

View File

@ -9,16 +9,37 @@ SWEP.ViewModelFOV = 90
SWEP.UseHands = true SWEP.UseHands = true
SWEP.WorldModel = "models/weapons/w_rif_ak47.mdl" SWEP.WorldModel = "models/weapons/w_rif_ak47.mdl"
SWEP.Sound_Shoot = "weapons/m4a1/m4a1_unsil-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/m4a1/fire-01.ogg",
"cnr/weapons/m4a1/fire-02.ogg",
"cnr/weapons/m4a1/fire-03.ogg",
}
SWEP.Sound_Mech = {
"cnr/weapons/mech-01.ogg",
"cnr/weapons/mech-02.ogg",
"cnr/weapons/mech-03.ogg",
"cnr/weapons/mech-04.ogg",
"cnr/weapons/mech-05.ogg",
"cnr/weapons/mech-06.ogg",
}
SWEP.Delay = ( 60 / 900 ) SWEP.Delay = ( 60 / 900 )
SWEP.MaxBurst = math.huge SWEP.MaxBurst = math.huge
SWEP.ActivePos = Vector( 2, -2, -2 ) SWEP.ActivePos = Vector( 2, -2, -2 )
SWEP.SpreadStart = 1 SWEP.BubbleSpreadUp = 0.8
SWEP.BubbleRecoilUp = 0.8
SWEP.BubbleSpreadDown = 0.2
SWEP.BubbleRecoilDown = 0.2
SWEP.SpreadStart = 0
SWEP.SpreadEnd = 10 SWEP.SpreadEnd = 10
SWEP.SpreadBurstStart = 3
SWEP.SpreadBurstEnd = 10 SWEP.RecoilUp = 33
SWEP.RecoilSpeed = 90
SWEP.RecoilDistStart = 0
SWEP.RecoilDistEnd = 10
SWEP.RecoilDistFunc = math.ease.InExpo
SWEP.Primary.Ammo = "pistol" SWEP.Primary.Ammo = "pistol"
SWEP.Primary.ClipSize = 0 SWEP.Primary.ClipSize = 0
@ -49,6 +70,11 @@ end
function SWEP:SetupDataTables() function SWEP:SetupDataTables()
self:NetworkVar( "Float", 0, "Delay" ) self:NetworkVar( "Float", 0, "Delay" )
self:NetworkVar( "Float", 1, "DelayReload" )
self:NetworkVar( "Float", 2, "DelayDeploy" )
self:NetworkVar( "Float", 3, "RefillTime" )
self:NetworkVar( "Float", 4, "BubbleSpread" )
self:NetworkVar( "Float", 5, "BubbleRecoil" )
self:NetworkVar( "Int", 0, "BurstCount" ) self:NetworkVar( "Int", 0, "BurstCount" )
end end

View File

@ -9,7 +9,11 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_rif_ak47.mdl" SWEP.WorldModel = "models/weapons/w_rif_ak47.mdl"
SWEP.ActivePos = Vector( 1, -8, -1 ) SWEP.ActivePos = Vector( 1, -8, -1 )
SWEP.Sound_Shoot = "weapons/ak47/ak47-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/ak47/fire-01.ogg",
"cnr/weapons/ak47/fire-02.ogg",
"cnr/weapons/ak47/fire-03.ogg",
}
SWEP.Primary.ClipSize = 30 SWEP.Primary.ClipSize = 30
SWEP.Delay = ( 60 / 700 ) SWEP.Delay = ( 60 / 700 )

View File

@ -9,10 +9,27 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_pist_glock18.mdl" SWEP.WorldModel = "models/weapons/w_pist_glock18.mdl"
SWEP.ActivePos = Vector( 1, -6, -1 ) SWEP.ActivePos = Vector( 1, -6, -1 )
SWEP.Sound_Shoot = "weapons/glock/glock18-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/glock/fire-01.ogg",
"cnr/weapons/glock/fire-02.ogg",
"cnr/weapons/glock/fire-03.ogg",
}
SWEP.Primary.ClipSize = 17 SWEP.Primary.ClipSize = 17
SWEP.Delay = ( 60 / 500 ) SWEP.Delay = ( 60 / 500 )
SWEP.MaxBurst = 1 SWEP.MaxBurst = 1
SWEP.DamageClose = 22 SWEP.DamageClose = 22
SWEP.DamageFar = 11 SWEP.DamageFar = 11
SWEP.BubbleSpreadUp = 0.2
SWEP.BubbleRecoilUp = 0.2
SWEP.BubbleSpreadDown = 0.3
SWEP.BubbleRecoilDown = 0.3
SWEP.SpreadStart = 1
SWEP.SpreadEnd = 3
SWEP.RecoilUp = 45
SWEP.RecoilSpeed = 40
SWEP.RecoilDistStart = 1
SWEP.RecoilDistEnd = 3

View File

@ -9,7 +9,11 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_mach_m249para.mdl" SWEP.WorldModel = "models/weapons/w_mach_m249para.mdl"
SWEP.ActivePos = Vector( 2, -2, -2 ) SWEP.ActivePos = Vector( 2, -2, -2 )
SWEP.Sound_Shoot = "weapons/p90/p90-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/m249/fire-01.ogg",
"cnr/weapons/m249/fire-02.ogg",
"cnr/weapons/m249/fire-03.ogg",
}
SWEP.Primary.ClipSize = 60 SWEP.Primary.ClipSize = 60
SWEP.Delay = ( 60 / 700 ) SWEP.Delay = ( 60 / 700 )

View File

@ -9,7 +9,11 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_rif_m4a1.mdl" SWEP.WorldModel = "models/weapons/w_rif_m4a1.mdl"
SWEP.ActivePos = Vector( 2, -2, -2 ) SWEP.ActivePos = Vector( 2, -2, -2 )
SWEP.Sound_Shoot = "weapons/m4a1/m4a1_unsil-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/m4a1/fire-01.ogg",
"cnr/weapons/m4a1/fire-02.ogg",
"cnr/weapons/m4a1/fire-03.ogg",
}
SWEP.Primary.ClipSize = 30 SWEP.Primary.ClipSize = 30
SWEP.Delay = ( 60 / 900 ) SWEP.Delay = ( 60 / 900 )

View File

@ -9,7 +9,11 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_shot_xm1014.mdl" SWEP.WorldModel = "models/weapons/w_shot_xm1014.mdl"
SWEP.ActivePos = Vector( 2, -2, -2 ) SWEP.ActivePos = Vector( 2, -2, -2 )
SWEP.Sound_Shoot = "weapons/xm1014/xm1014-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/m4s90/fire-01.ogg",
"cnr/weapons/m4s90/fire-02.ogg",
"cnr/weapons/m4s90/fire-03.ogg",
}
SWEP.Primary.ClipSize = 5 SWEP.Primary.ClipSize = 5
SWEP.Delay = ( 60 / 300 ) SWEP.Delay = ( 60 / 300 )

View File

@ -1,7 +1,7 @@
SWEP.Base = "cnr" SWEP.Base = "cnr"
SWEP.PrintName = "SPITFIRE" SWEP.PrintName = "SPITFIRE 45A"
SWEP.Slot = 0 SWEP.Slot = 0
SWEP.ViewModel = "models/weapons/cstrike/c_smg_mac10.mdl" SWEP.ViewModel = "models/weapons/cstrike/c_smg_mac10.mdl"
@ -9,7 +9,11 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_smg_mac10.mdl" SWEP.WorldModel = "models/weapons/w_smg_mac10.mdl"
SWEP.ActivePos = Vector( 2, -2, -2 ) SWEP.ActivePos = Vector( 2, -2, -2 )
SWEP.Sound_Shoot = "weapons/mac10/mac10-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/mp5/fire-01.ogg",
"cnr/weapons/mp5/fire-02.ogg",
"cnr/weapons/mp5/fire-03.ogg",
}
SWEP.Primary.ClipSize = 32 SWEP.Primary.ClipSize = 32
SWEP.Delay = ( 60 / 1100 ) SWEP.Delay = ( 60 / 1100 )

View File

@ -1,7 +1,7 @@
SWEP.Base = "cnr" SWEP.Base = "cnr"
SWEP.PrintName = "SLIMLINE" SWEP.PrintName = "SLIMLINE 12G"
SWEP.Slot = 0 SWEP.Slot = 0
SWEP.ViewModel = "models/weapons/cstrike/c_shot_m3super90.mdl" SWEP.ViewModel = "models/weapons/cstrike/c_shot_m3super90.mdl"

View File

@ -9,7 +9,11 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_smg_mp5.mdl" SWEP.WorldModel = "models/weapons/w_smg_mp5.mdl"
SWEP.ActivePos = Vector( 2, -2, -2 ) SWEP.ActivePos = Vector( 2, -2, -2 )
SWEP.Sound_Shoot = "weapons/mp5navy/mp5-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/mp5/fire-01.ogg",
"cnr/weapons/mp5/fire-02.ogg",
"cnr/weapons/mp5/fire-03.ogg",
}
SWEP.Primary.ClipSize = 30 SWEP.Primary.ClipSize = 30
SWEP.Delay = ( 60 / 900 ) SWEP.Delay = ( 60 / 900 )

View File

@ -9,10 +9,27 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_pist_p228.mdl" SWEP.WorldModel = "models/weapons/w_pist_p228.mdl"
SWEP.ActivePos = Vector( 1, -6, -1 ) SWEP.ActivePos = Vector( 1, -6, -1 )
SWEP.Sound_Shoot = "weapons/p228/p228-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/p220/fire-01.ogg",
"cnr/weapons/p220/fire-02.ogg",
"cnr/weapons/p220/fire-03.ogg",
}
SWEP.Primary.ClipSize = 13 SWEP.Primary.ClipSize = 13
SWEP.Delay = ( 60 / 400 ) SWEP.Delay = ( 60 / 400 )
SWEP.MaxBurst = 1 SWEP.MaxBurst = 1
SWEP.DamageClose = 25 SWEP.DamageClose = 25
SWEP.DamageFar = 13 SWEP.DamageFar = 13
SWEP.BubbleSpreadUp = 0.8
SWEP.BubbleRecoilUp = 0.8
SWEP.BubbleSpreadDown = 0.1
SWEP.BubbleRecoilDown = 0.1
SWEP.SpreadStart = 0.1
SWEP.SpreadEnd = 4
SWEP.RecoilUp = 33
SWEP.RecoilSpeed = 60
SWEP.RecoilDistStart = 0.8
SWEP.RecoilDistEnd = 2.2

View File

@ -9,10 +9,27 @@ SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_pist_usp.mdl" SWEP.WorldModel = "models/weapons/w_pist_usp.mdl"
SWEP.ActivePos = Vector( 1, -6, -1 ) SWEP.ActivePos = Vector( 1, -6, -1 )
SWEP.Sound_Shoot = "weapons/usp/usp_unsil-1.wav" SWEP.Sound_Fire = {
"cnr/weapons/usp/fire-01.ogg",
"cnr/weapons/usp/fire-02.ogg",
"cnr/weapons/usp/fire-03.ogg",
}
SWEP.Primary.ClipSize = 12 SWEP.Primary.ClipSize = 12
SWEP.Delay = ( 60 / 400 ) SWEP.Delay = ( 60 / 400 )
SWEP.MaxBurst = 1 SWEP.MaxBurst = 1
SWEP.DamageClose = 25 SWEP.DamageClose = 25
SWEP.DamageFar = 13 SWEP.DamageFar = 13
SWEP.BubbleSpreadUp = 0.6
SWEP.BubbleRecoilUp = 0.6
SWEP.BubbleSpreadDown = 0.2
SWEP.BubbleRecoilDown = 0.2
SWEP.SpreadStart = 0.1
SWEP.SpreadEnd = 5
SWEP.RecoilUp = 45
SWEP.RecoilSpeed = 60
SWEP.RecoilDistStart = 1
SWEP.RecoilDistEnd = 3

View File

@ -25,12 +25,12 @@ surface.CreateFont( "CNR_HUD_2", {
surface.CreateFont( "CNR_HUD_3", { surface.CreateFont( "CNR_HUD_3", {
font = "Bahnschrift Light", font = "Bahnschrift Light",
size = ScreenScaleH(16), size = ScreenScaleH(14),
weight = 0, weight = 0,
}) })
surface.CreateFont( "CNR_HUD_4", { surface.CreateFont( "CNR_HUD_4", {
font = "Bahnschrift Bold", font = "Bahnschrift Bold",
size = ScreenScaleH(32), size = ScreenScaleH(28),
weight = 0, weight = 0,
}) })
@ -64,20 +64,20 @@ hook.Add("HUDPaint", "CNR_HUD", function()
end end
do do
local b_w, b_h = s(82), s(48) local b_w, b_h = s(64+8), s(42)
local b_x, b_y = c1, s(16) local b_x, b_y = c1, s(16)
surface.SetDrawColor( color_white ) surface.SetDrawColor( color_white )
surface.DrawRect( b_x, b_y, b_w, b_h ) surface.DrawRect( b_x, b_y, b_w, b_h )
draw.SimpleText( "TIME", "CNR_HUD_3", b_x + b, b_y + s(4), color_black, TEXT_ALIGN_LEFT ) draw.SimpleText( "TIME", "CNR_HUD_3", b_x + b, b_y + s(4), color_black, TEXT_ALIGN_LEFT )
draw.SimpleText( string.FormattedTime( -CurTime(), "%02i:%02i"), "CNR_HUD_4", b_x + b, b_y + s(12), color_black, TEXT_ALIGN_LEFT ) draw.SimpleText( string.FormattedTime( -CurTime()*1000, "%02i:%02i"), "CNR_HUD_4", b_x + b, b_y + s(12), color_black, TEXT_ALIGN_LEFT )
end end
do do
local b_w, b_h = s(182), s(32) local b_w, b_h = s(172), s(30)
local b_x, b_y = c1, s(16+16) + b + b_h local b_x, b_y = c1, s(16) + b + s(42)
surface.SetDrawColor( color_white ) surface.SetDrawColor( color_white )
surface.DrawRect( b_x, b_y, b_w, b_h ) surface.DrawRect( b_x, b_y, b_w, b_h )
draw.SimpleText( "$", "CNR_HUD_4", b_x + b, b_y, color_black, TEXT_ALIGN_LEFT ) draw.SimpleText( "$", "CNR_HUD_3", b_x + b, b_y + s(8), color_black, TEXT_ALIGN_LEFT )
draw.SimpleText( "100,000,000", "CNR_HUD_4", b_x + b_w - b, b_y, color_black, TEXT_ALIGN_RIGHT ) draw.SimpleText( "100,000,000", "CNR_HUD_4", b_x + b_w - b, b_y, color_black, TEXT_ALIGN_RIGHT )
end end
end) end)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.