Skip to content

Commit

Permalink
impl team bal, add riot lr, move lr weapon restrict over to dropping
Browse files Browse the repository at this point in the history
  • Loading branch information
destoer committed Dec 1, 2023
1 parent 24543b8 commit a43b4af
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 23 deletions.
9 changes: 9 additions & 0 deletions src/Jail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions src/LastRequest/LRBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public void cleanup()
}


// make sure our weapons dont get taken off
weapon_restrict = "";

// restore hp
player.set_health(100);

Expand Down
92 changes: 79 additions & 13 deletions src/LastRequest/LastRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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!");
}
Expand Down Expand Up @@ -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);
Expand All @@ -803,14 +803,66 @@ 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();

// 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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 1 addition & 6 deletions src/LastRequest/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,6 @@ public void setup_db(MySqlConnection? database)

public MySqlConnection? connect_db()
{
if(config == null)
{
return null;
}

try
{

Expand All @@ -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];
}
10 changes: 10 additions & 0 deletions src/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions src/Warden/Warden.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a43b4af

Please sign in to comment.