Commit for release version 1.1

- fixed old files from wrong repo structure set up
- added new commands
This commit is contained in:
joahreason 2023-11-17 19:27:07 -05:00
parent 47fcd30365
commit dada7e074a
54 changed files with 153 additions and 415 deletions

View file

@ -2,37 +2,101 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Utils;
namespace GoSpec;
public class GoSpec : BasePlugin
{
public override string ModuleName => "GoSpec";
public override string ModuleAuthor => "cosmic sans";
public override string ModuleVersion => "1.0";
public override string ModuleVersion => "1.1";
public override void Load(bool hotReload)
{
Console.WriteLine($"{ChatColors.Blue}{ModuleName} v{ModuleVersion} by {ModuleAuthor} is active. Type !spec to switch to spec.");
Console.WriteLine($"{ModuleName} version {ModuleVersion} by {ModuleAuthor} is active.");
}
[ConsoleCommand("spec", "Moves you to spec.")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void OnSpecCommand(CCSPlayerController? caller, CommandInfo command)
{
if (caller == null) return;
if (caller.PlayerPawn.Value.TeamNum == (int)CsTeam.Spectator) return;
ChangeTeam(caller, CsTeam.Spectator);
}
caller.ChangeTeam(CsTeam.Spectator);
#region Alternate Spec Commands
[ConsoleCommand("s", "Moves you to spec.")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void OnSCommand(CCSPlayerController? caller, CommandInfo command) => OnSpecCommand(caller, command);
if (caller.PlayerPawn.Value.TeamNum != (int)CsTeam.Spectator)
[ConsoleCommand("afk", "Moves you to spec.")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void OnAFKCommand(CCSPlayerController? caller, CommandInfo command) => OnSpecCommand(caller, command);
[ConsoleCommand("brb", "Moves you to spec.")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void OnBRBCommand(CCSPlayerController? caller, CommandInfo command) => OnSpecCommand(caller, command);
#endregion
[ConsoleCommand("ct", "Joins the counterterrorist team.")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void OnJoinCTCommand(CCSPlayerController? caller, CommandInfo command)
{
ChangeTeam(caller, CsTeam.CounterTerrorist);
}
[ConsoleCommand("t", "Joins the terrorist team.")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
public void OnJoinTCommand(CCSPlayerController? caller, CommandInfo command)
{
ChangeTeam(caller, CsTeam.Terrorist);
}
private bool ChangeTeam(CCSPlayerController? caller, CsTeam moveTo)
{
if (caller == null) return false;
if(IsInSpec(caller) && moveTo == CsTeam.Spectator)
{
caller.PrintToChat($"{ChatColors.Red}Failed to move you to spec.");
return;
caller.PrintToChat($"{ChatColors.Red}You already are in spec.");
return false;
}
if (!IsInSpec(caller) && moveTo != CsTeam.Spectator)
{
caller.PrintToChat($"{ChatColors.Red}You must be in spec to use this command.");
return false;
}
Server.PrintToChatAll($"{ChatColors.Default}Moving {ChatColors.Green}{caller.PlayerName} {ChatColors.Default}to spec.");
NotifyTeamChange(caller, moveTo);
caller.ChangeTeam(moveTo);
return true;
}
private void NotifyTeamChange(CCSPlayerController caller, CsTeam team)
{
string name = caller.PlayerName ?? "Unknown";
char teamColor = ChatColors.White;
if (team != CsTeam.Spectator) teamColor = team == CsTeam.Terrorist ? ChatColors.Red : ChatColors.Blue;
string teamMsg = $"{ChatColors.Default}Moving {ChatColors.Green}{name} {ChatColors.Default}to {teamColor}{team}.";
Server.PrintToChatAll(teamMsg);
}
private int GetTeamCount(CsTeam team)
{
int count = 0;
foreach (CCSPlayerController user in Utilities.GetPlayers())
{
if (user.PlayerPawn.Value.TeamNum == (int)team) count++;
}
return count;
}
private bool IsInSpec(CCSPlayerController? caller)
{
if (caller == null) return false;
return caller.TeamNum == (int)CsTeam.Spectator;
}
}