Team swapping

This commit is contained in:
Fesiug 2023-12-21 20:40:47 -05:00
parent faac326333
commit dd680e2b4b
14 changed files with 295 additions and 157 deletions

View File

@ -9,45 +9,5 @@
"settings" "settings"
{ {
//1
//{
// "name" "cnr_roundlength"
// "text" "Round length (minutes)"
// "help" ""
// "type" "Numeric"
// "default" "3"
//}
//2
//{
// "name" "cnr_hastetime"
// "text" "Haste time (minutes)"
// "help" ""
// "type" "Numeric"
// "default" "1"
//}
//3
//{
// "name" "cnr_maxrounds"
// "text" "Game ends after X rounds"
// "help" ""
// "type" "Numeric"
// "default" "6"
//}
//4
//{
// "name" "cnr_teamswap"
// "text" "Swap teams after X rounds"
// "help" ""
// "type" "Numeric"
// "default" "2"
//}
//5
//{
// "name" "cnr_friendlyfire"
// "text" "Friendly fire"
// "help" "Enable friendly fire"
// "type" "CheckBox"
// "default" "0"
//}
} }
} }

View File

@ -9,8 +9,14 @@ function ENT:SetupDataTables()
self:NetworkVar( "Float", 2, "RoundFinishedAt" ) self:NetworkVar( "Float", 2, "RoundFinishedAt" )
self:NetworkVar( "Int", 0, "State" ) self:NetworkVar( "Int", 0, "State" )
self:NetworkVar( "Int", 1, "RoundNumber" ) self:NetworkVar( "Int", 1, "Round" )
self:NetworkVar( "Int", 2, "Money" ) self:NetworkVar( "Int", 2, "Money" )
self:NetworkVar( "Int", 3, "SwappedAtRound" )
self:NetworkVar( "Bool", 0, "TeamSwap" )
self:SetRound( 1 )
self:SetSwappedAtRound( 1 )
end end
function ENT:Initialize() function ENT:Initialize()

View File

@ -0,0 +1,35 @@
SWEP.Base = "cnr"
SWEP.PrintName = "CAL.50"
SWEP.Slot = 1
SWEP.ViewModel = "models/weapons/cstrike/c_pist_deagle.mdl"
SWEP.ViewModelFOV = 90
SWEP.WorldModel = "models/weapons/w_pist_deagle.mdl"
SWEP.ActivePos = Vector( 1, -8, -1 )
SWEP.Sound_Fire = {
"cnr/weapons/mossberg/fire-01.ogg",
"cnr/weapons/mossberg/fire-02.ogg",
"cnr/weapons/mossberg/fire-03.ogg",
}
SWEP.Primary.ClipSize = 7
SWEP.Delay = ( 60 / 200 )
SWEP.MaxBurst = 1
SWEP.DamageClose = 44
SWEP.DamageFar = 44
SWEP.BubbleSpreadUp = 0.01
SWEP.BubbleRecoilUp = 0.01
SWEP.BubbleSpreadDown = 0.75
SWEP.BubbleRecoilDown = 0.75
SWEP.SpreadStart = 0.2
SWEP.SpreadEnd = 15
SWEP.RecoilUp = 33
SWEP.RecoilSpeed = 30/0.1
SWEP.RecoilDistStart = 30
SWEP.RecoilDistEnd = 30

View File

@ -7,7 +7,7 @@ SWEP.Slot = 1
SWEP.ViewModel = "models/weapons/cstrike/c_pist_glock18.mdl" SWEP.ViewModel = "models/weapons/cstrike/c_pist_glock18.mdl"
SWEP.ViewModelFOV = 90 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, -8, -1 )
SWEP.Sound_Fire = { SWEP.Sound_Fire = {
"cnr/weapons/glock/fire-01.ogg", "cnr/weapons/glock/fire-01.ogg",

View File

@ -16,19 +16,19 @@ SWEP.Sound_Fire = {
} }
SWEP.Primary.ClipSize = 60 SWEP.Primary.ClipSize = 60
SWEP.Delay = ( 60 / 700 ) SWEP.Delay = ( 60 / 900 )
SWEP.DamageClose = 25 SWEP.DamageClose = 25
SWEP.DamageFar = 13 SWEP.DamageFar = 13
SWEP.BubbleSpreadUp = 2 SWEP.BubbleSpreadUp = 2
SWEP.BubbleRecoilUp = 2 SWEP.BubbleRecoilUp = 2
SWEP.BubbleSpreadDown = 0.4 SWEP.BubbleSpreadDown = 0.7
SWEP.BubbleRecoilDown = 0.4 SWEP.BubbleRecoilDown = 0.7
SWEP.SpreadStart = 0.1 SWEP.SpreadStart = 0.1
SWEP.SpreadEnd = 4 SWEP.SpreadEnd = 4
SWEP.RecoilUp = 33 SWEP.RecoilUp = 33
SWEP.RecoilSpeed = 60 SWEP.RecoilSpeed = 60
SWEP.RecoilDistStart = 1 SWEP.RecoilDistStart = 0.5
SWEP.RecoilDistEnd = 10 SWEP.RecoilDistEnd = 10

View File

@ -7,7 +7,7 @@ SWEP.Slot = 0
SWEP.ViewModel = "models/weapons/cstrike/c_rif_m4a1.mdl" SWEP.ViewModel = "models/weapons/cstrike/c_rif_m4a1.mdl"
SWEP.ViewModelFOV = 90 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( 0, -2, -2 )
SWEP.Sound_Fire = { SWEP.Sound_Fire = {
"cnr/weapons/m4a1/fire-01.ogg", "cnr/weapons/m4a1/fire-01.ogg",

View File

@ -16,6 +16,6 @@ SWEP.Sound_Fire = {
} }
SWEP.Primary.ClipSize = 32 SWEP.Primary.ClipSize = 32
SWEP.Delay = ( 60 / 1100 ) SWEP.Delay = ( 60 / 1600 )
SWEP.DamageClose = 25 SWEP.DamageClose = 25
SWEP.DamageFar = 13 SWEP.DamageFar = 13

View File

@ -7,7 +7,7 @@ SWEP.Slot = 1
SWEP.ViewModel = "models/weapons/cstrike/c_pist_p228.mdl" SWEP.ViewModel = "models/weapons/cstrike/c_pist_p228.mdl"
SWEP.ViewModelFOV = 90 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, -8, -1 )
SWEP.Sound_Fire = { SWEP.Sound_Fire = {
"cnr/weapons/p220/fire-01.ogg", "cnr/weapons/p220/fire-01.ogg",

View File

@ -7,7 +7,7 @@ SWEP.Slot = 1
SWEP.ViewModel = "models/weapons/cstrike/c_pist_usp.mdl" SWEP.ViewModel = "models/weapons/cstrike/c_pist_usp.mdl"
SWEP.ViewModelFOV = 90 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, -8, -1 )
SWEP.Sound_Fire = { SWEP.Sound_Fire = {
"cnr/weapons/usp/fire-01.ogg", "cnr/weapons/usp/fire-01.ogg",

View File

@ -82,9 +82,9 @@ end
local slut = { local slut = {
[0] = "UNINIT", [0] = "UNINIT",
[1] = "WAITING", [1] = "WAITING",
[2] = "PRE-GAME", [2] = "PREGAME",
[3] = "TIME", [3] = "TIME",
[4] = "POST-GAME", [4] = "POSTGAME",
} }
local gamelogic = NULL local gamelogic = NULL
@ -128,7 +128,7 @@ hook.Add("HUDPaint", "CNR_HUD", function()
local state = gamelogic:GetState() local state = gamelogic:GetState()
do do
local b_w, b_h = s(64+8), s(42) local b_w, b_h = s(64+12), 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 )
@ -142,6 +142,15 @@ hook.Add("HUDPaint", "CNR_HUD", function()
fuckhead = string.format( "%02i.%02i", fuckhead.s, fuckhead.ms ) fuckhead = string.format( "%02i.%02i", fuckhead.s, fuckhead.ms )
end end
MonoDraw( fuckhead, "CNR_HUD_4", b_x + b, b_y + s(12), color_black, false, special1 ) 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_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() .. " - " .. gamelogic:GetSwappedAtRound() .. " : " .. (gamelogic:GetTeamSwap() and "Swap" or "Not"), "CNR_HUD_4", n_x + b, n_y + s(12), color_black )
end
end end
if state == STATE_INGAME or state == STATE_POSTGAME then if state == STATE_INGAME or state == STATE_POSTGAME then

View File

@ -0,0 +1,52 @@
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:Center()
teampanel:MakePopup()
function teampanel:Paint( w, h )
surface.SetDrawColor( color_white )
surface.DrawRect( 0, 0, w, h )
return true
end
for i, v in ipairs( teams ) do
local button = teampanel:Add( "DButton" )
button:SetSize( s(320), s(32) )
button:DockMargin( 0, s(2), 0, 0 )
button:Dock( TOP )
function button:Paint( w, h )
surface.SetDrawColor( color_white )
surface.DrawRect( 0, 0, w, h )
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 )
return true
end
function button:DoClick()
RunConsoleCommand( "changeteam", v.ID )
teampanel:Remove()
end
end
end

View File

@ -54,7 +54,6 @@ if SERVER then
-- Begin round -- Begin round
state = STATE_INGAME state = STATE_INGAME
gamelogic:SetRoundStartedAt( RealTime() ) gamelogic:SetRoundStartedAt( RealTime() )
gamelogic:SetMoney( 0 )
end end
end end
@ -70,6 +69,22 @@ if SERVER then
if (gamelogic:GetRoundFinishedAt() + CONVARS["time_postgame"]:GetInt()) <= RealTime() then if (gamelogic:GetRoundFinishedAt() + CONVARS["time_postgame"]:GetInt()) <= RealTime() then
state = STATE_PREGAME state = STATE_PREGAME
gamelogic:SetPregameStartedAt( RealTime() ) gamelogic:SetPregameStartedAt( RealTime() )
-- 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
gamelogic:SetTeamSwap( !gamelogic:GetTeamSwap() )
gamelogic:SetSwappedAtRound( gamelogic:GetRound() )
end
LOGIC:SetSpawnpoints()
for i, v in player.Iterator() do
v:Spawn()
end
end end
end end
@ -106,4 +121,22 @@ function LOGIC:GetTimeLeft()
else else
return 0, 0 return 0, 0
end end
end
function LOGIC:Switcheroo( teamid )
local gamelogic = LOGIC:GetLogic()
local flipped = gamelogic:GetTeamSwap()
if teamid == TEAM_SIDEA then
return (flipped and TEAM_SIDEB or TEAM_SIDEA)
else
return (flipped and TEAM_SIDEA or TEAM_SIDEB)
end
end
function LOGIC:SetSpawnpoints()
local gamelogic = LOGIC:GetLogic()
local flipped = gamelogic:GetTeamSwap()
team.SetSpawnPoint( flipped and TEAM_SIDEB or TEAM_SIDEA, "info_player_counterterrorist" )
team.SetSpawnPoint( flipped and TEAM_SIDEA or TEAM_SIDEB, "info_player_terrorist" )
end end

View File

@ -0,0 +1,139 @@
function GM:OnDamagedByExplosion( ply, dmginfo )
-- ply:SetDSP( 35, false )
end
function GM:PlayerCanJoinTeam( ply, teamid )
if ( ply:Team() == teamid ) then
ply:ChatPrint( "You're already on that team" )
return false
end
return true
end
-- Write this so at the end of a round you can shittalk
local sv_alltalk = GetConVar( "sv_alltalk" )
function GM:PlayerCanHearPlayersVoice( pListener, pTalker )
local alltalk = sv_alltalk:GetInt()
if ( alltalk >= 1 ) then return true, alltalk == 2 end
return pListener:Team() == pTalker:Team(), false
end
function GM:PlayerShouldTaunt( ply, actid )
return false
end
function GM:AllowPlayerPickup( ply, object )
return false
end
function GM:PlayerDeathSound()
return true
end
function GM:PlayerDeathThink( pl )
if ( pl.NextSpawnTime && pl.NextSpawnTime > CurTime() ) then return end
pl:Spawn()
end
function GM:CreateTeams()
TEAM_SIDEA = 1
team.SetUp( TEAM_SIDEA, "Side A", Color( 200, 200, 255 ) )
team.SetSpawnPoint( TEAM_SIDEA, "info_player_counterterrorist" )
TEAM_SIDEB = 2
team.SetUp( TEAM_SIDEB, "Side B", Color( 255, 200, 200 ) )
team.SetSpawnPoint( TEAM_SIDEB, "info_player_terrorist" )
team.SetSpawnPoint( TEAM_SPECTATOR, "worldspawn" )
end
function GM:ScalePlayerDamage( ply, hitgroup, dmginfo )
-- More damage if we're shot in the head
if ( hitgroup == HITGROUP_HEAD ) then
dmginfo:ScaleDamage( 3 )
end
end
function GM:PlayerInitialSpawn( pl, transition )
pl:SetTeam( TEAM_UNASSIGNED )
pl:ConCommand( "gm_showteam" )
end
function GM:PlayerSpawnAsSpectator( pl )
pl:StripWeapons()
if ( pl:Team() == TEAM_UNASSIGNED ) then
pl:Spectate( OBS_MODE_FIXED )
return
end
pl:SetTeam( TEAM_SPECTATOR )
pl:Spectate( OBS_MODE_ROAMING )
end
function GM:PlayerSelectSpawn( pl, transition )
local ent = self:PlayerSelectTeamSpawn( pl:Team(), pl )
if ( IsValid( ent ) ) then return ent end
end
function GM:PlayerSelectTeamSpawn( TeamID, pl )
local gamelogic = LOGIC:GetLogic()
local SpawnPoints = team.GetSpawnPoints( LOGIC:Switcheroo( TeamID ) )
if ( !SpawnPoints || table.IsEmpty( SpawnPoints ) ) then return end
local ChosenSpawnPoint = nil
for i = 0, 6 do
ChosenSpawnPoint = table.Random( SpawnPoints )
if ( hook.Call( "IsSpawnpointSuitable", GAMEMODE, pl, ChosenSpawnPoint, i == 6 ) ) then
return ChosenSpawnPoint
end
end
return ChosenSpawnPoint
end
function GM:PlayerSpawn( p, transition )
player_manager.SetPlayerClass( p, "player_cnr" )
if ( self.TeamBased and ( p:Team() == TEAM_SPECTATOR or p:Team() == TEAM_UNASSIGNED ) ) then
self:PlayerSpawnAsSpectator( p )
return
end
p:UnSpectate()
p:SetSlowWalkSpeed( 190 )
p:SetWalkSpeed( 320 )
p:SetRunSpeed( 320 )
if ( !transition ) then
GAMEMODE:PlayerLoadout( p )
end
GAMEMODE:PlayerSetModel( p )
p:SetupHands()
end
local PT = FindMetaTable("Player")
function PT:IsCop()
return self:Team() == LOGIC:Switcheroo( TEAM_SIDEA )
end
function GM:PlayerLoadout( p )
p:StripWeapons()
if p:IsCop() then
p:Give("cnr_m4a1")
p:Give("cnr_usp")
else
p:Give("cnr_ak47")
p:Give("cnr_glock")
end
return true
end
function GM:PlayerSetModel( p )
if p:IsCop() then
p:SetModel( "models/player/combine_soldier.mdl" )
else
p:SetModel( "models/player/group03/male_07.mdl" )
end
end

View File

@ -6,8 +6,10 @@ GM.Website = "https://github.com/Fesiug/copsnrobbers"
GM.TeamBased = true GM.TeamBased = true
AddCSLuaFile("cl_hud.lua") AddCSLuaFile("cl_hud.lua")
AddCSLuaFile("cl_selectteam.lua")
if CLIENT then if CLIENT then
include ("cl_hud.lua") include ("cl_hud.lua")
include ("cl_selectteam.lua")
end end
AddCSLuaFile("player_class_cnr.lua") AddCSLuaFile("player_class_cnr.lua")
@ -16,113 +18,16 @@ AddCSLuaFile("player_class_cnr.lua")
AddCSLuaFile("logic.lua") AddCSLuaFile("logic.lua")
include ("logic.lua") include ("logic.lua")
AddCSLuaFile("playerbs.lua")
include ("playerbs.lua")
function GM:Initialize() function GM:Initialize()
-- Do stuff -- Do stuff
end end
function GM:OnDamagedByExplosion( ply, dmginfo )
-- ply:SetDSP( 35, false )
end
function GM:PlayerCanJoinTeam( ply, teamid )
local TimeBetweenSwitches = 0.5
if ( ply.LastTeamSwitch && RealTime() - ply.LastTeamSwitch < TimeBetweenSwitches ) then
ply.LastTeamSwitch = ply.LastTeamSwitch + 0.5
ply:ChatPrint( Format( "Please wait %i more seconds before trying to change team again", ( TimeBetweenSwitches - ( RealTime() - ply.LastTeamSwitch ) ) + 1 ) )
return false
end
if ( ply:Team() == teamid ) then
ply:ChatPrint( "You're already on that team" )
return false
end
return true
end
-- Write this so at the end of a round you can shittalk
local sv_alltalk = GetConVar( "sv_alltalk" )
function GM:PlayerCanHearPlayersVoice( pListener, pTalker )
local alltalk = sv_alltalk:GetInt()
if ( alltalk >= 1 ) then return true, alltalk == 2 end
return pListener:Team() == pTalker:Team(), false
end
function GM:PlayerShouldTaunt( ply, actid )
return false
end
function GM:AllowPlayerPickup( ply, object )
return false
end
function GM:PlayerDeathSound()
return true
end
function GM:CreateTeams()
TEAM_SIDEA = 1
team.SetUp( TEAM_SIDEA, "Side A", Color( 200, 200, 255 ) )
team.SetSpawnPoint( TEAM_SIDEA, "info_player_counterterrorist" )
TEAM_SIDEB = 2
team.SetUp( TEAM_SIDEB, "Side B", Color( 255, 200, 200 ) )
team.SetSpawnPoint( TEAM_SIDEB, "info_player_terrorist" )
team.SetSpawnPoint( TEAM_SPECTATOR, "worldspawn" )
end
function GM:ScalePlayerDamage( ply, hitgroup, dmginfo )
-- More damage if we're shot in the head
if ( hitgroup == HITGROUP_HEAD ) then
dmginfo:ScaleDamage( 2 )
end
end
function GM:PlayerSpawn( p, transition )
player_manager.SetPlayerClass( p, "player_cnr" )
if ( self.TeamBased and ( p:Team() == TEAM_SPECTATOR or p:Team() == TEAM_UNASSIGNED ) ) then
self:PlayerSpawnAsSpectator( p )
return
end
p:UnSpectate()
p:SetSlowWalkSpeed( 190 )
p:SetWalkSpeed( 320 )
p:SetRunSpeed( 320 )
if ( !transition ) then
GAMEMODE:PlayerLoadout( p )
end
GAMEMODE:PlayerSetModel( p )
p:SetupHands()
end
function GM:PlayerLoadout( p )
if p:Team() == TEAM_SIDEA then
p:Give("cnr_m4a1")
p:Give("cnr_usp")
elseif p:Team() == TEAM_SIDEB then
p:Give("cnr_ak47")
p:Give("cnr_glock")
end
return true
end
function GM:PlayerSetModel( p )
if p:Team() == TEAM_SIDEA then
p:SetModel( "models/player/combine_soldier.mdl" )
elseif p:Team() == TEAM_SIDEB then
p:SetModel( "models/player/group03/male_07.mdl" )
end
end
concommand.Add( "cnr_cheat_weapons", function( p ) concommand.Add( "cnr_cheat_weapons", function( p )
p:Give( "cnr_ak47" ) p:Give( "cnr_ak47" )
p:Give( "cnr_deagle" )
p:Give( "cnr_glock" ) p:Give( "cnr_glock" )
p:Give( "cnr_m4a1" ) p:Give( "cnr_m4a1" )
p:Give( "cnr_m4s90" ) p:Give( "cnr_m4s90" )
@ -134,5 +39,4 @@ concommand.Add( "cnr_cheat_weapons", function( p )
p:Give( "cnr_usp" ) p:Give( "cnr_usp" )
end) end)
-- Include module loader here -- Include module loader here