Skip to content

Commit

Permalink
Merge pull request #22 from destoer/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
destoer authored Feb 25, 2024
2 parents 3bddb23 + c03650d commit b3e0940
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"jail.kill_cmd": "{0} slayed themself",

"warden.remove": "Warden Removed",
"warden.warden_command_desc": "!w - take warden",
"warden.warday_command_desc": "!wd - start a warday",
Expand Down
27 changes: 26 additions & 1 deletion src/Jail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static void PurgePlayerStats(CCSPlayerController? player)

public override string ModuleName => "CS2 Jailbreak - destoer";

public override string ModuleVersion => "v0.3.8";
public override string ModuleVersion => "v0.3.9";

public override void Load(bool hotReload)
{
Expand Down Expand Up @@ -265,8 +265,19 @@ void AddLocalizedCmd(String base_name,String desc,CommandInfo.CommandCallback ca
AddCommand("css_" + Localizer[base_name],desc,callback);
}

public static void KillCmd(CCSPlayerController? invoke, CommandInfo command)
{
if(invoke.IsLegalAlive())
{
Chat.LocalizeAnnounce("","jail.kill_cmd",invoke.PlayerName);
invoke.Slay();
}
}

void RegisterCommands()
{
AddCommand("kill","kill self",KillCmd);

// reg warden comamnds
AddLocalizedCmd("warden.take_warden_cmd", "take warden", warden.TakeWardenCmd);
AddLocalizedCmd("warden.leave_warden_cmd", "leave warden", warden.LeaveWardenCmd);
Expand Down Expand Up @@ -383,9 +394,23 @@ void RegisterHooks()
AddCommandListener("jointeam",JoinTeam);
AddCommandListener("player_ping",PlayerPingCmd);

AddCommandListener("say", OnPlayerChat);

// TODO: need to hook weapon drop
}


public HookResult OnPlayerChat(CCSPlayerController? invoke, CommandInfo command)
{
// dont print chat, warden is handling it
if(!warden.PlayerChat(invoke,command))
{
return HookResult.Handled;
}

return HookResult.Continue;
}

public HookResult PlayerPingCmd(CCSPlayerController? invoke, CommandInfo command)
{
// if player is not warden ignore the ping
Expand Down
3 changes: 3 additions & 0 deletions src/LastRequest/GunToss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public override void InitPlayer(CCSPlayerController player)

if(deagle != null)
{
// colour gun to player team!
deagle.SetColour(player.IsT()? Lib.RED : Lib.CYAN);

deagle.SetAmmo(0,0);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/LastRequest/NoScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ void GiveWeapon(CCSPlayerController? player)
}
}

public override void WeaponFire(String name)
{
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);

var weapon = player.FindWeapon(name);
weapon.SetAmmo(5,-1);
}

public override void InitPlayer(CCSPlayerController player)
{
GiveWeapon(player);
Expand Down
12 changes: 6 additions & 6 deletions src/LastRequest/War.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public override void InitPlayer(CCSPlayerController player)
player.GiveWeapon(weaponRestrict);

player.SetHealth(1000);
}

public override void WeaponFire(String name)
{
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);

var shotgun = player.FindWeapon(weaponRestrict);

if(shotgun != null)
{
shotgun.SetAmmo(999,999);
}
var weapon = player.FindWeapon(name);
weapon.SetAmmo(999,999);
}
}
27 changes: 22 additions & 5 deletions src/Lib/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Menu;
using CSTimer = CounterStrikeSharp.API.Modules.Timers;
using System.Drawing;
using System.Diagnostics.CodeAnalysis;

public static class Weapon
{
static public bool IsLegal(this CBasePlayerWeapon? weapon)
static public bool IsLegal([NotNullWhen(true)] this CBasePlayerWeapon? weapon)
{
return weapon != null && weapon.IsValid;
}


static public void SetColour(this CBasePlayerWeapon? weapon, Color colour)
{
if(weapon.IsLegal())
{
weapon.RenderMode = RenderMode_t.kRenderTransColor;
weapon.Render = colour;
Utilities.SetStateChanged(weapon,"CBaseModelEntity","m_clrRender");
}
}

static public CBasePlayerWeapon? FindWeapon(this CCSPlayerController? player, String name)
{
// only care if player is alive
Expand Down Expand Up @@ -57,7 +70,7 @@ static public bool IsLegal(this CBasePlayerWeapon? weapon)

static public void SetAmmo(this CBasePlayerWeapon? weapon, int clip, int reserve)
{
if(weapon == null || !weapon.IsLegal())
if(!weapon.IsLegal())
{
return;
}
Expand All @@ -66,15 +79,19 @@ static public void SetAmmo(this CBasePlayerWeapon? weapon, int clip, int reserve
// setting "infinite ammo"
// thanks 1Mack
CCSWeaponBaseVData? weaponData = weapon.As<CCSWeaponBase>().VData;



if(weaponData != null)
{
// TODO: this overide it for every gun the player has...
// when not a map gun, this is not a big deal
// for the reserve ammo it is for the clip though
/*
if(clip > weaponData.MaxClip1)
{
weaponData.MaxClip1 = clip;
weaponData.DefaultClip1 = clip;
}

*/
if(reserve > weaponData.PrimaryReserveAmmoMax)
{
weaponData.PrimaryReserveAmmoMax = reserve;
Expand Down
8 changes: 7 additions & 1 deletion src/Warden/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@ public bool JoinTeam(CCSPlayerController? invoke, CommandInfo command)

default:
{
invoke.Announce(TEAM_PREFIX,$"Invalid team swap team");
if(!invoke.IsLegalAlive())
{
invoke.SwitchTeam(CsTeam.Terrorist);
}

invoke.Announce(TEAM_PREFIX,$"Invalid team swap {team}");
invoke.PlaySound("sounds/ui/counter_beep.vsnd");

return false;
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/Warden/Warden.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ public void RemoveIfWarden(CCSPlayerController? player)
}


public bool PlayerChat(CCSPlayerController? player, CommandInfo info)
{
String text = info.GetArg(1);

if(text.StartsWith("/") || text.StartsWith("!") || String.IsNullOrWhiteSpace(text))
{
return true;
}

if(player.IsLegalAlive() && IsWarden(player))
{
Server.PrintToChatAll($"{WARDEN_PREFIX} {player.PlayerName}: {text}");
return false;
}

return true;
}

// reset variables for a new round
void PurgeRound()
{
Expand Down

0 comments on commit b3e0940

Please sign in to comment.