From 7215d129ddd0635b362158497acda69123f6d0ef Mon Sep 17 00:00:00 2001 From: Fesiug Date: Fri, 22 Dec 2023 09:07:47 -0500 Subject: [PATCH] Shotgun reloading, nicer UI, mroe --- .../entities/weapons/cnr/sh_reload.lua | 20 +++-- .../entities/weapons/cnr/sh_shoot.lua | 2 +- .../entities/weapons/cnr/sh_think.lua | 18 ++++- .../entities/weapons/cnr/shared.lua | 1 + .../entities/weapons/cnr_glock.lua | 4 +- .../entities/weapons/cnr_m4s90.lua | 4 +- .../entities/weapons/cnr_mac10.lua | 4 +- .../entities/weapons/cnr_mossberg.lua | 4 +- .../copsnrobbers/entities/weapons/cnr_mp5.lua | 19 ++++- .../entities/weapons/cnr_p220.lua | 4 +- .../copsnrobbers/entities/weapons/cnr_usp.lua | 6 +- gamemodes/copsnrobbers/gamemode/cl_hud.lua | 18 ++++- .../copsnrobbers/gamemode/cl_selectteam.lua | 81 ++++++++++++++----- gamemodes/copsnrobbers/gamemode/logic.lua | 23 +++++- gamemodes/copsnrobbers/gamemode/playerbs.lua | 41 +++++++++- gamemodes/copsnrobbers/gamemode/shared.lua | 20 +++-- 16 files changed, 213 insertions(+), 56 deletions(-) diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr/sh_reload.lua b/gamemodes/copsnrobbers/entities/weapons/cnr/sh_reload.lua index adae0f8..4cb1803 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr/sh_reload.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr/sh_reload.lua @@ -6,13 +6,23 @@ function SWEP:Reload() if self:GetDelayReload() > CurTime() then return false end + if self:GetShotgunReloading() == 1 then + return false + end if self:Clip1() >= self.Primary.ClipSize then return false end - self:SendWeaponAnim( ACT_VM_RELOAD ) - self:GetOwner():GetViewModel():SetPlaybackRate( 2.5 ) - self:SetDelayReload( CurTime() + self:SequenceDuration()/2.5 ) - self:SetRefillTime( CurTime() + self:SequenceDuration()/2.5 ) - --self:SetClip1( self.Primary.ClipSize ) + + if self.ShotgunReloading then + self:SendWeaponAnim( ACT_SHOTGUN_RELOAD_START ) + self:GetOwner():GetViewModel():SetPlaybackRate( 2.5 ) + self:SetDelayReload( CurTime() + 0.1 ) + self:SetShotgunReloading( 1 ) + else + self:SendWeaponAnim( ACT_VM_RELOAD ) + self:GetOwner():GetViewModel():SetPlaybackRate( 2.5 ) + self:SetDelayReload( CurTime() + self:SequenceDuration()/2.5 ) + self:SetRefillTime( CurTime() + self:SequenceDuration()/2.5 ) + end return true end \ No newline at end of file diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr/sh_shoot.lua b/gamemodes/copsnrobbers/entities/weapons/cnr/sh_shoot.lua index 0bd7090..bf9f4ba 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr/sh_shoot.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr/sh_shoot.lua @@ -45,7 +45,7 @@ function SWEP:PrimaryAttack( mine ) self:FireBullets( { Attacker = self:GetOwner(), Tracer = 1, - Damage = 25, + Damage = self.DamageClose, Force = 1, Num = 1, Dir = newdir, diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr/sh_think.lua b/gamemodes/copsnrobbers/entities/weapons/cnr/sh_think.lua index db14560..b0cfb8b 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr/sh_think.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr/sh_think.lua @@ -45,7 +45,23 @@ function SWEP:Think() self:SetBubbleRecoil( math.Approach( self:GetBubbleRecoil(), up and 1 or 0, FrameTime()/(up and self.BubbleRecoilUp or self.BubbleRecoilDown) ) ) if self:GetRefillTime() != -1 and CurTime() >= self:GetRefillTime() then - self:SetClip1( self.Primary.ClipSize ) + self:SetClip1( self.ShotgunReloading and (self:Clip1() + 1) or self.Primary.ClipSize ) self:SetRefillTime( -1 ) end + + if self:GetShotgunReloading() == 1 then + if p:KeyDown( IN_ATTACK ) or (self:GetDelayReload() <= CurTime() and self:Clip1() == self.Primary.ClipSize) then + self:SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH ) + self:GetOwner():GetViewModel():SetPlaybackRate( 2.5 ) + self:SetRefillTime( -1 ) + self:SetShotgunReloading( 0 ) + else + if self:GetDelayReload() <= CurTime() then + self:SendWeaponAnim( ACT_VM_RELOAD ) + self:GetOwner():GetViewModel():SetPlaybackRate( 2.5 ) + self:SetDelayReload( CurTime() + 0.2 ) + self:SetRefillTime( CurTime() + 0.1 ) + end + end + end end \ No newline at end of file diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr/shared.lua b/gamemodes/copsnrobbers/entities/weapons/cnr/shared.lua index f1477cf..3108eba 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr/shared.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr/shared.lua @@ -76,6 +76,7 @@ function SWEP:SetupDataTables() self:NetworkVar( "Float", 4, "BubbleSpread" ) self:NetworkVar( "Float", 5, "BubbleRecoil" ) self:NetworkVar( "Int", 0, "BurstCount" ) + self:NetworkVar( "Int", 1, "ShotgunReloading" ) self:SetRefillTime( -1 ) end diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr_glock.lua b/gamemodes/copsnrobbers/entities/weapons/cnr_glock.lua index 0076ee9..e782dfe 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr_glock.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr_glock.lua @@ -24,7 +24,7 @@ SWEP.DamageFar = 11 SWEP.BubbleSpreadUp = 0.2 SWEP.BubbleRecoilUp = 0.2 SWEP.BubbleSpreadDown = 0.3 -SWEP.BubbleRecoilDown = 0.3 +SWEP.BubbleRecoilDown = 0.2 SWEP.SpreadStart = 1 SWEP.SpreadEnd = 3 @@ -32,4 +32,4 @@ SWEP.SpreadEnd = 3 SWEP.RecoilUp = 45 SWEP.RecoilSpeed = 40 SWEP.RecoilDistStart = 2 -SWEP.RecoilDistEnd = 3 \ No newline at end of file +SWEP.RecoilDistEnd = 5 \ No newline at end of file diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr_m4s90.lua b/gamemodes/copsnrobbers/entities/weapons/cnr_m4s90.lua index 8fe733a..da1ec78 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr_m4s90.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr_m4s90.lua @@ -19,4 +19,6 @@ SWEP.Primary.ClipSize = 5 SWEP.Delay = ( 60 / 180 ) SWEP.MaxBurst = 1 SWEP.DamageClose = 25 -SWEP.DamageFar = 13 \ No newline at end of file +SWEP.DamageFar = 13 + +SWEP.ShotgunReloading = true \ No newline at end of file diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr_mac10.lua b/gamemodes/copsnrobbers/entities/weapons/cnr_mac10.lua index f377e00..e886490 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr_mac10.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr_mac10.lua @@ -17,5 +17,5 @@ SWEP.Sound_Fire = { SWEP.Primary.ClipSize = 32 SWEP.Delay = ( 60 / 1600 ) -SWEP.DamageClose = 25 -SWEP.DamageFar = 13 \ No newline at end of file +SWEP.DamageClose = 14 +SWEP.DamageFar = 10 \ No newline at end of file diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr_mossberg.lua b/gamemodes/copsnrobbers/entities/weapons/cnr_mossberg.lua index 2ea6c7e..818b973 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr_mossberg.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr_mossberg.lua @@ -19,4 +19,6 @@ SWEP.Primary.ClipSize = 4 SWEP.Delay = ( 60 / 80 ) SWEP.MaxBurst = 1 SWEP.DamageClose = 25 -SWEP.DamageFar = 13 \ No newline at end of file +SWEP.DamageFar = 13 + +SWEP.ShotgunReloading = true \ No newline at end of file diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr_mp5.lua b/gamemodes/copsnrobbers/entities/weapons/cnr_mp5.lua index 10aaa10..7db2e91 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr_mp5.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr_mp5.lua @@ -1,7 +1,7 @@ SWEP.Base = "cnr" -SWEP.PrintName = "SWORDFISH DELUXE" +SWEP.PrintName = "SWORDFISH-5" SWEP.Slot = 0 SWEP.ViewModel = "models/weapons/cstrike/c_smg_mp5.mdl" @@ -17,5 +17,18 @@ SWEP.Sound_Fire = { SWEP.Primary.ClipSize = 30 SWEP.Delay = ( 60 / 900 ) -SWEP.DamageClose = 25 -SWEP.DamageFar = 13 \ No newline at end of file +SWEP.DamageClose = 16 +SWEP.DamageFar = 10 + +SWEP.BubbleSpreadUp = 0.8 +SWEP.BubbleRecoilUp = 0.8 +SWEP.BubbleSpreadDown = 0.2 +SWEP.BubbleRecoilDown = 0.2 + +SWEP.SpreadStart = 0 +SWEP.SpreadEnd = 10 + +SWEP.RecoilUp = 60 +SWEP.RecoilSpeed = 180 +SWEP.RecoilDistStart = 1 +SWEP.RecoilDistEnd = 5 \ No newline at end of file diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr_p220.lua b/gamemodes/copsnrobbers/entities/weapons/cnr_p220.lua index bb916a7..043c7d1 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr_p220.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr_p220.lua @@ -22,7 +22,7 @@ SWEP.DamageClose = 25 SWEP.DamageFar = 21 SWEP.BubbleSpreadUp = 0.8 -SWEP.BubbleRecoilUp = 0.8 +SWEP.BubbleRecoilUp = 0.2 SWEP.BubbleSpreadDown = 0.1 SWEP.BubbleRecoilDown = 0.1 @@ -32,4 +32,4 @@ SWEP.SpreadEnd = 4 SWEP.RecoilUp = 33 SWEP.RecoilSpeed = 60 SWEP.RecoilDistStart = 0.8 -SWEP.RecoilDistEnd = 2.2 \ No newline at end of file +SWEP.RecoilDistEnd = 4 \ No newline at end of file diff --git a/gamemodes/copsnrobbers/entities/weapons/cnr_usp.lua b/gamemodes/copsnrobbers/entities/weapons/cnr_usp.lua index 59dd813..604ef33 100644 --- a/gamemodes/copsnrobbers/entities/weapons/cnr_usp.lua +++ b/gamemodes/copsnrobbers/entities/weapons/cnr_usp.lua @@ -22,7 +22,7 @@ SWEP.DamageClose = 25 SWEP.DamageFar = 13 SWEP.BubbleSpreadUp = 0.6 -SWEP.BubbleRecoilUp = 0.6 +SWEP.BubbleRecoilUp = 0.3 SWEP.BubbleSpreadDown = 0.2 SWEP.BubbleRecoilDown = 0.2 @@ -31,5 +31,5 @@ SWEP.SpreadEnd = 5 SWEP.RecoilUp = 45 SWEP.RecoilSpeed = 60 -SWEP.RecoilDistStart = 1 -SWEP.RecoilDistEnd = 3 \ No newline at end of file +SWEP.RecoilDistStart = 2 +SWEP.RecoilDistEnd = 4 \ No newline at end of file diff --git a/gamemodes/copsnrobbers/gamemode/cl_hud.lua b/gamemodes/copsnrobbers/gamemode/cl_hud.lua index 58959b8..3bee64e 100644 --- a/gamemodes/copsnrobbers/gamemode/cl_hud.lua +++ b/gamemodes/copsnrobbers/gamemode/cl_hud.lua @@ -34,6 +34,18 @@ surface.CreateFont( "CNR_HUD_4", { weight = 0, }) +surface.CreateFont( "CNR_SEL_1", { + font = "Bahnschrift Light", + size = ScreenScaleH(18), + weight = 0, +}) + +surface.CreateFont( "CNR_SEL_2", { + font = "Bahnschrift Light", + size = ScreenScaleH(10), + weight = 0, +}) + local special1 = { normal = 12, colon = 5, @@ -147,12 +159,12 @@ hook.Add("HUDPaint", "CNR_HUD", function() MonoDraw( fuckhead, "CNR_HUD_4", b_x + b, b_y + s(12), color_black, false, special1 ) do - local n_w, n_h = s(128), s(42) + local n_w, n_h = s(56), s(42) local n_x, n_y = b_x + b + b_w, b_y surface.SetDrawColor( color_white ) surface.DrawRect( n_x, n_y, n_w, n_h ) - draw.SimpleText( "ROUND NUMBER", "CNR_HUD_3", n_x + b, n_y + s(4), color_black ) - draw.SimpleText( gamelogic:GetRound(), "CNR_HUD_4", n_x + b, n_y + s(12), color_black ) + draw.SimpleText( "ROUND", "CNR_HUD_3", n_x + b, n_y + s(4), color_black ) + draw.SimpleText( gamelogic:GetRound() .. "/" .. CONVARS["rounds_max"]:GetInt(), "CNR_HUD_4", n_x + b, n_y + s(12), color_black ) end end diff --git a/gamemodes/copsnrobbers/gamemode/cl_selectteam.lua b/gamemodes/copsnrobbers/gamemode/cl_selectteam.lua index 1a9a419..f24009a 100644 --- a/gamemodes/copsnrobbers/gamemode/cl_selectteam.lua +++ b/gamemodes/copsnrobbers/gamemode/cl_selectteam.lua @@ -1,24 +1,9 @@ -local teams = { - { - Name = "Side A", - ID = TEAM_SIDEA, - }, - { - Name = "Side B", - ID = TEAM_SIDEB, - }, - { - Name = "Spectate", - ID = TEAM_SPECTATOR, - }, -} - function GM:ShowTeam() if IsValid( teampanel ) then teampanel:Remove() return end local s = ScreenScaleH teampanel = vgui.Create( "DFrame" ) - teampanel:SetSize( s(320), s(160) ) + teampanel:SetSize( s(320), s(240) ) teampanel:Center() teampanel:MakePopup() @@ -27,10 +12,30 @@ function GM:ShowTeam() surface.DrawRect( 0, 0, w, h ) return true end + + -- the ids are undefined pretty early and whatever + local teams = { + { + Name = "Side A", + ID = TEAM_SIDEA, + }, + { + Name = "Side B", + ID = TEAM_SIDEB, + }, + { + Name = "Spectate", + ID = TEAM_SPECTATOR, + }, + { + Name = "Auto-Select", + ID = true, + }, + } for i, v in ipairs( teams ) do local button = teampanel:Add( "DButton" ) - button:SetSize( s(320), s(32) ) + button:SetSize( s(320), s(48) ) button:DockMargin( 0, s(2), 0, 0 ) button:Dock( TOP ) @@ -40,12 +45,50 @@ function GM:ShowTeam() surface.SetDrawColor( color_black ) surface.DrawOutlinedRect( 0, 0, w, h, s(1) ) - draw.SimpleText( v.Name, "CNR_HUD_1", s(4), s(4), color_black ) + draw.SimpleText( v.Name, "CNR_SEL_1", s(4), s(4), color_black ) + + local plys = team.GetPlayers( v.ID ) + local mew = { [1] = {} } + local curr = 1 + + for _, v in ipairs( plys ) do + local concat = "" + local nick = v:Nick() + if #nick > 8 then + nick = nick:Left(8) .. ".." + end + concat = concat .. nick + --if i!= #plys then + -- concat = concat .. ", " + --end + if #mew[curr] > 5 then + curr = curr + 1 + end + if !mew[curr] then + mew[curr] = {} + end + table.insert( mew[curr], concat ) + end + + local bump = 0 + for _, row in ipairs( mew ) do + bump = 0 + for i, v in ipairs( row ) do + local tada = v .. ((i!=#row) and ", " or "") + draw.SimpleText( tada, "CNR_SEL_2", s(4)+bump, s(4+16 + s((_-1)*4)), color_black ) + surface.SetFont( "CNR_SEL_2" ) + bump = bump + surface.GetTextSize( tada ) + end + end return true end function button:DoClick() - RunConsoleCommand( "changeteam", v.ID ) + if v.ID == true then + RunConsoleCommand( "changeteam", team.BestAutoJoinTeam() ) + else + RunConsoleCommand( "changeteam", v.ID ) + end teampanel:Remove() end end diff --git a/gamemodes/copsnrobbers/gamemode/logic.lua b/gamemodes/copsnrobbers/gamemode/logic.lua index f3cbf5d..1e18c67 100644 --- a/gamemodes/copsnrobbers/gamemode/logic.lua +++ b/gamemodes/copsnrobbers/gamemode/logic.lua @@ -45,6 +45,23 @@ if SERVER then -- Begin pregame state = STATE_PREGAME gamelogic:SetPregameStartedAt( RealTime() ) + net.Start( "CNR_Logic_Pregame" ) + net.Broadcast() + + -- Begin preparations for a new round + gamelogic:SetMoney( 0 ) + + -- Swap teams + if CONVARS["rounds_swap"]:GetBool() and gamelogic:GetRound() > (gamelogic:GetSwappedAtRound()-1)+CONVARS["rounds_swap"]:GetInt() then + gamelogic:SetTeamSwap( !gamelogic:GetTeamSwap() ) + gamelogic:SetSwappedAtRound( gamelogic:GetRound() ) + end + + LOGIC:SetSpawnpoints() + + for i, v in player.Iterator() do + v:Spawn() + end end end @@ -69,6 +86,7 @@ if SERVER then gamelogic:SetRoundFinishedAt( RealTime() ) net.Start( "CNR_Logic_Postgame" ) net.Broadcast() + gamelogic:SetRound( gamelogic:GetRound() + 1 ) end end @@ -76,10 +94,11 @@ if SERVER then if (gamelogic:GetRoundFinishedAt() + CONVARS["time_postgame"]:GetInt()) <= RealTime() then state = STATE_PREGAME gamelogic:SetPregameStartedAt( RealTime() ) + net.Start( "CNR_Logic_Pregame" ) + net.Broadcast() -- Begin preparations for a new round gamelogic:SetMoney( 0 ) - gamelogic:SetRound( gamelogic:GetRound() + 1 ) -- Swap teams if CONVARS["rounds_swap"]:GetBool() and gamelogic:GetRound() > (gamelogic:GetSwappedAtRound()-1)+CONVARS["rounds_swap"]:GetInt() then @@ -92,8 +111,6 @@ if SERVER then for i, v in player.Iterator() do v:Spawn() end - net.Start( "CNR_Logic_Pregame" ) - net.Broadcast() end end diff --git a/gamemodes/copsnrobbers/gamemode/playerbs.lua b/gamemodes/copsnrobbers/gamemode/playerbs.lua index b554ae6..aafa836 100644 --- a/gamemodes/copsnrobbers/gamemode/playerbs.lua +++ b/gamemodes/copsnrobbers/gamemode/playerbs.lua @@ -58,8 +58,12 @@ function GM:ScalePlayerDamage( ply, hitgroup, dmginfo ) end function GM:PlayerInitialSpawn( pl, transition ) - pl:SetTeam( TEAM_UNASSIGNED ) - pl:ConCommand( "gm_showteam" ) + if pl:IsBot() then + pl:SetTeam( team.BestAutoJoinTeam() ) + else + pl:SetTeam( TEAM_UNASSIGNED ) + pl:ConCommand( "gm_showteam" ) + end end function GM:PlayerSpawnAsSpectator( pl ) pl:StripWeapons() @@ -155,4 +159,35 @@ hook.Add( "Move", "CNR_Move", function( ply, mv ) mv:SetMaxClientSpeed( 0 ) mv:SetMaxSpeed( 0 ) end -end) \ No newline at end of file +end) + +if SERVER then + util.AddNetworkString( "CNR_Kill" ) + + function GM:DoPlayerDeath( ply, attacker, dmginfo ) + ply:CreateRagdoll() + ply:AddDeaths( 1 ) + if ( attacker:IsValid() && attacker:IsPlayer() ) then + if ( attacker == ply ) then + attacker:AddFrags( -1 ) + else + attacker:AddFrags( 1 ) + end + end + net.Start( "CNR_Kill" ) + net.WriteEntity( ply ) + net.WriteEntity( attacker ) + net.WriteEntity( dmginfo:GetInflictor() ) + net.Broadcast() + end +else + local c_attacker = Color( 255, 100, 100 ) + local c_victim = Color( 100, 100, 255 ) + net.Receive( "CNR_Kill", function() + local victim = net.ReadEntity() + local attacker = net.ReadEntity() + local inflictor = net.ReadEntity() + + chat.AddText( c_attacker, attacker:Nick(), color_white, " [", inflictor:GetPrintName(), "] ", c_victim, victim:Nick(), color_white ) + end) +end \ No newline at end of file diff --git a/gamemodes/copsnrobbers/gamemode/shared.lua b/gamemodes/copsnrobbers/gamemode/shared.lua index e42158f..a0a4759 100644 --- a/gamemodes/copsnrobbers/gamemode/shared.lua +++ b/gamemodes/copsnrobbers/gamemode/shared.lua @@ -5,13 +5,6 @@ GM.Email = "publicfesiug@outlook.com" GM.Website = "https://github.com/Fesiug/copsnrobbers" GM.TeamBased = true -AddCSLuaFile("cl_hud.lua") -AddCSLuaFile("cl_selectteam.lua") -if CLIENT then - include ("cl_hud.lua") - include ("cl_selectteam.lua") -end - AddCSLuaFile("player_class_cnr.lua") include ("player_class_cnr.lua") @@ -21,6 +14,13 @@ AddCSLuaFile("logic.lua") AddCSLuaFile("playerbs.lua") include ("playerbs.lua") +AddCSLuaFile("cl_hud.lua") +AddCSLuaFile("cl_selectteam.lua") +if CLIENT then + include ("cl_hud.lua") + include ("cl_selectteam.lua") +end + function GM:Initialize() -- Do stuff end @@ -39,4 +39,10 @@ concommand.Add( "cnr_cheat_weapons", function( p ) p:Give( "cnr_usp" ) end) +if SERVER then + function GM:ShowTeam( ply ) + ply:SendLua( "GAMEMODE:ShowTeam()" ) + end +end + -- Include module loader here \ No newline at end of file