Skip to content

Commit

Permalink
save result of ct gun menu
Browse files Browse the repository at this point in the history
  • Loading branch information
destoer committed Jan 18, 2024
1 parent c64a563 commit 0829584
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/Warden/JailPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void setup_db()
{
"ALTER TABLE config ADD COLUMN laser_colour varchar(64) DEFAULT 'Cyan'",
"ALTER TABLE config ADD COLUMN marker_colour varchar(64) DEFAULT 'Cyan'",
"ALTER TABLE config ADD COLUMN ct_gun varchar(64) DEFAULT 'M4'",
};


Expand Down Expand Up @@ -124,13 +125,14 @@ async Task load_player_db(String steam_id)
query_steam_id.CommandText = "SELECT * FROM config WHERE steam_id = @steam_id";
query_steam_id.Parameters.AddWithValue("@steam_id",steam_id);

using var reader = await query_steam_id.ExecuteReaderAsync();
using var reader = await query_steam_id.ExecuteReaderAsync();

if(reader.Read())
{
// just override this
laser_colour = Lib.LASER_CONFIG_MAP[(String)reader["laser_colour"]];
marker_colour = Lib.LASER_CONFIG_MAP[(String)reader["marker_colour"]];
ct_gun = (String)reader["ct_gun"];

// don't try reloading the player
cached = true;
Expand Down Expand Up @@ -159,6 +161,8 @@ public void load_player(CCSPlayerController? player)
return;
}

// The database has allready been read before
// there is not need to do it again
if(cached)
{
return;
Expand Down Expand Up @@ -229,6 +233,7 @@ public void reset()
// TODO: reset client specific settings
laser_colour = Lib.CYAN;
marker_colour = Lib.CYAN;
ct_gun = "M4";
}

public void set_rebel(CCSPlayerController? player)
Expand All @@ -239,14 +244,11 @@ public void set_rebel(CCSPlayerController? player)
}

// ignore if they are in lr
if(JailPlugin.global_ctx != null)
if(JailPlugin.lr.in_lr(player))
{
if(JailPlugin.lr.in_lr(player))
{
return;
}
return;
}

// dont care if player is invalid
if(!player.is_valid() || player == null)
{
Expand Down Expand Up @@ -327,5 +329,7 @@ public void player_hurt(CCSPlayerController? player, CCSPlayerController? attack
public Color marker_colour { get; private set; } = Lib.CYAN;
bool cached = false;

public String ct_gun = "M4";

public bool is_rebel = false;
};
16 changes: 15 additions & 1 deletion src/Warden/Warden.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,14 @@ public void setup_player_guns(CCSPlayerController? player)
{
if(config.ct_guns)
{
var jail_player = jail_player_from_player(player);

player.GiveNamedItem("weapon_deagle");
player.GiveNamedItem("weapon_m4a1");

if(jail_player != null)
{
player.GiveNamedItem("weapon_" + Lib.gun_give_name(jail_player.ct_gun));
}
}

if(config.ct_armour)
Expand Down Expand Up @@ -526,6 +532,14 @@ public void ct_guns(CCSPlayerController player, ChatMenuOption option)

player.strip_weapons();


var jail_player = jail_player_from_player(player);

if(jail_player != null)
{
jail_player.update_player(player, "ct_gun", option.Text);
jail_player.ct_gun = option.Text;
}

player.GiveNamedItem("weapon_" + Lib.gun_give_name(option.Text));
player.GiveNamedItem("weapon_deagle");
Expand Down

0 comments on commit 0829584

Please sign in to comment.