From a43b4af77b61301f32a6259d28ea580048e38bc3 Mon Sep 17 00:00:00 2001 From: destoer Date: Fri, 1 Dec 2023 20:48:50 +0000 Subject: [PATCH] impl team bal, add riot lr, move lr weapon restrict over to dropping --- src/Jail.cs | 9 ++++ src/LastRequest/LRBase.cs | 3 ++ src/LastRequest/LastRequest.cs | 92 +++++++++++++++++++++++++++++----- src/LastRequest/Stats.cs | 7 +-- src/Lib.cs | 10 ++++ src/Warden/Warden.cs | 14 ++++-- 6 files changed, 112 insertions(+), 23 deletions(-) diff --git a/src/Jail.cs b/src/Jail.cs index cdb3b2d..03a2104 100644 --- a/src/Jail.cs +++ b/src/Jail.cs @@ -31,6 +31,13 @@ public class JailConfig : BasePluginConfig [JsonPropertyName("database")] public String database { get; set; } = "cs2_jail"; + + // ratio of t to CT + [JsonPropertyName("bal_guards")] + public int bal_guards { get; set; } = 0; + + [JsonPropertyName("enable_riot")] + public bool riot_enable { get; set; } = false; } // main plugin file, controls central hooking @@ -104,6 +111,8 @@ public void OnConfigParsed(JailConfig config) this.Config = config; lr.lr_stats.config = config; + lr.config = config; + warden.config = config; var database = lr.lr_stats.connect_db(); diff --git a/src/LastRequest/LRBase.cs b/src/LastRequest/LRBase.cs index 8a74b52..065be02 100644 --- a/src/LastRequest/LRBase.cs +++ b/src/LastRequest/LRBase.cs @@ -68,6 +68,9 @@ public void cleanup() } + // make sure our weapons dont get taken off + weapon_restrict = ""; + // restore hp player.set_health(100); diff --git a/src/LastRequest/LastRequest.cs b/src/LastRequest/LastRequest.cs index e2e622a..1fc575a 100644 --- a/src/LastRequest/LastRequest.cs +++ b/src/LastRequest/LastRequest.cs @@ -246,9 +246,8 @@ public void purge_lr() { end_lr(l); } - - rebel_active = false; - knife_rebel_active = false; + + rebel_type = RebelType.NONE; } public void round_start() @@ -369,7 +368,7 @@ public void weapon_equip(CCSPlayerController? player,String name) return; } - if(knife_rebel_active && !name.Contains("knife")) + if(rebel_type == RebelType.KNIFE && !name.Contains("knife")) { player.strip_weapons(); return; @@ -405,9 +404,11 @@ public void weapon_equip(CCSPlayerController? player,String name) var weapon_name = weapon.DesignerName; - if(!lr.weapon_equip(weapon_name) && !weapon_name.Contains("knife")) + // TODO: Ideally we should just deny the equip all together but this works well enough + if(!lr.weapon_equip(weapon_name)) { - weapon.Remove(); + //Server.PrintToChatAll($"drop player gun: {player.PlayerName} : {weapon_name}"); + player.DropActiveWeapon(); } } } @@ -745,7 +746,7 @@ public void rebel_guns(CCSPlayerController player, ChatMenuOption option) return; } - if(!can_rebel()) + if(!can_rebel() || rebel_type != RebelType.KNIFE) { player.PrintToChat($"{LR_PREFIX} You must be the last player alive to rebel"); return; @@ -760,7 +761,7 @@ public void rebel_guns(CCSPlayerController player, ChatMenuOption option) player.set_health(Lib.alive_ct_count() * 100); - rebel_active = true; + rebel_type = RebelType.REBEL; Lib.announce(LR_PREFIX,$"{player.PlayerName} is a rebel!"); } @@ -788,8 +789,7 @@ public void start_knife_rebel(CCSPlayerController? rebel, ChatMenuOption option) return; } - knife_rebel_active = true; - rebel_active = true; + rebel_type = RebelType.KNIFE; Lib.announce(LR_PREFIX,$"{rebel.PlayerName} is knife a rebel!"); rebel.set_health(Lib.alive_ct_count() * 100); @@ -803,6 +803,58 @@ public void start_knife_rebel(CCSPlayerController? rebel, ChatMenuOption option) } } + public void riot_respawn() + { + // riot cancelled in mean time + if(rebel_type != RebelType.RIOT) + { + return; + } + + + Lib.announce(LR_PREFIX,"Riot active"); + + foreach(CCSPlayerController? player in Utilities.GetPlayers()) + { + if(player != null && player.is_valid() && !player.is_valid_alive()) + { + Server.PrintToChatAll($"Respawn {player.PlayerName}"); + player.Respawn(); + } + + else + { + Server.PrintToChatAll("could not respawn"); + } + } + } + + + public void start_riot(CCSPlayerController? rebel, ChatMenuOption option) + { + if(rebel == null || !rebel.is_valid()) + { + return; + } + + if(!can_rebel()) + { + rebel.PrintToChat($"{LR_PREFIX} You must be the last player alive to rebel"); + return; + } + + + rebel_type = RebelType.RIOT; + + Lib.announce(LR_PREFIX,"A riot has started CT's have 15 seconds to hide"); + + if(JailPlugin.global_ctx != null) + { + JailPlugin.global_ctx.AddTimer(15.0f,riot_respawn,CSTimer.TimerFlags.STOP_ON_MAPCHANGE); + } + } + + public void lr_cmd_internal(CCSPlayerController? player,bool bypass, CommandInfo command) { int? player_slot_opt = player.slot(); @@ -810,7 +862,7 @@ public void lr_cmd_internal(CCSPlayerController? player,bool bypass, CommandInfo // check player can start lr // NOTE: higher level function checks its valid to start an lr // so we can do a bypass for debugging - if(player == null || !player.is_valid() || player_slot_opt == null || rebel_active) + if(player == null || !player.is_valid() || player_slot_opt == null || rebel_type != RebelType.NONE) { return; } @@ -832,6 +884,11 @@ public void lr_cmd_internal(CCSPlayerController? player,bool bypass, CommandInfo { lr_menu.AddMenuOption("Knife rebel",start_knife_rebel); lr_menu.AddMenuOption("Rebel",start_rebel); + + if(config.riot_enable) + { + lr_menu.AddMenuOption("Riot",start_riot); + } } ChatMenus.OpenMenu(player, lr_menu); @@ -943,8 +1000,17 @@ internal class LRChoice public bool bypass = false; } - bool rebel_active = false; - bool knife_rebel_active = false; + enum RebelType + { + NONE, + REBEL, + KNIFE, + RIOT, + }; + + RebelType rebel_type = RebelType.NONE; + + public JailConfig config = new JailConfig(); LRChoice[] lr_choice = new LRChoice[64]; public LRStats lr_stats = new LRStats(); diff --git a/src/LastRequest/Stats.cs b/src/LastRequest/Stats.cs index 93e9e20..fddec2b 100644 --- a/src/LastRequest/Stats.cs +++ b/src/LastRequest/Stats.cs @@ -305,11 +305,6 @@ public void setup_db(MySqlConnection? database) public MySqlConnection? connect_db() { - if(config == null) - { - return null; - } - try { @@ -328,7 +323,7 @@ public void setup_db(MySqlConnection? database) } } - public JailConfig? config = null; + public JailConfig config = new JailConfig(); PlayerStat[] lr_players = new PlayerStat[64]; } \ No newline at end of file diff --git a/src/Lib.cs b/src/Lib.cs index 3d0e8c0..e5d81ad 100644 --- a/src/Lib.cs +++ b/src/Lib.cs @@ -275,6 +275,16 @@ static public void draw_laser(Vector start, Vector end, float life, float width, } } + static public void play_sound(this CCSPlayerController? player, String sound) + { + if(player == null || !player.is_valid()) + { + return; + } + + player.ExecuteClientCommand($"play {sound}"); + } + static public CCSPlayerController? player(this CEntityInstance? instance) { if(instance == null) diff --git a/src/Warden/Warden.cs b/src/Warden/Warden.cs index 0a4e35d..139e3a1 100644 --- a/src/Warden/Warden.cs +++ b/src/Warden/Warden.cs @@ -440,9 +440,11 @@ public void join_team(CCSPlayerController? invoke, CommandInfo command) case Lib.TEAM_CT: { int ct_count = Lib.ct_count(); + int t_count = Lib.t_count(); - // check CT aint full - if((ct_count * 2) < Lib.t_count() || ct_count == 0) + // check CT aint full + // i.e at a suitable raito or either team is empty + if((ct_count * config.bal_guards) < t_count || ct_count == 0 || t_count == 0) { invoke.SwitchTeam(CsTeam.CounterTerrorist); } @@ -451,12 +453,13 @@ public void join_team(CCSPlayerController? invoke, CommandInfo command) else { invoke.SwitchTeam(CsTeam.Terrorist); - invoke.announce(TEAM_PREFIX,"Sorry CT has too many players"); + invoke.announce(TEAM_PREFIX,$"Sorry, CT has too many players {config.bal_guards}:1 ratio maximum"); + invoke.play_sound("sounds/ui/counter_beep.vsnd"); // update to actual switch team = Lib.TEAM_T; } - + break; } @@ -477,6 +480,7 @@ public void join_team(CCSPlayerController? invoke, CommandInfo command) { invoke.SwitchTeam(CsTeam.Terrorist); invoke.announce(TEAM_PREFIX,"You cannot join that team"); + invoke.play_sound("sounds/ui/counter_beep.vsnd"); break; } } @@ -573,6 +577,8 @@ public void weapon_fire(CCSPlayerController? player, String name) CSTimer.Timer? start_timer = null; + public JailConfig config = new JailConfig(); + JailPlayer[] jail_players = new JailPlayer[64]; public Warday warday = new Warday();