mirror of
https://codeberg.org/spire/setteam.git
synced 2026-06-03 14:24:07 +02:00
120 lines
2.5 KiB
SourcePawn
120 lines
2.5 KiB
SourcePawn
#pragma semicolon 1
|
|
#include <sourcemod>
|
|
#include <tf2>
|
|
|
|
public Plugin:myinfo = {
|
|
name = "setteam",
|
|
author = "Icewind",
|
|
description = "Set players team",
|
|
version = "0.2",
|
|
url = "https://spire.tf"
|
|
};
|
|
|
|
KeyValues force_team;
|
|
|
|
public OnPluginStart() {
|
|
RegServerCmd("sm_setteam", SetTeam, "Set a players team");
|
|
RegServerCmd("sm_forceteam", ForceExec, "Set a players team and keep them there");
|
|
|
|
AddCommandListener(Command_JoinTeam, "jointeam");
|
|
AddCommandListener(Command_JoinTeam, "autoteam");
|
|
|
|
force_team = new KeyValues("ForceTeam");
|
|
}
|
|
|
|
int parse_team(const char[] team_str) {
|
|
int team = 0;
|
|
|
|
if (StrEqual("red", team_str)) {
|
|
team = 2;
|
|
}
|
|
if (StrEqual("blue", team_str)) {
|
|
team = 3;
|
|
}
|
|
if (StrEqual("spec", team_str)) {
|
|
team = 1;
|
|
}
|
|
|
|
return team;
|
|
}
|
|
|
|
void set_force(int client, int team) {
|
|
char authid[20];
|
|
GetClientAuthId(client, AuthId_SteamID64, authid, sizeof(authid));
|
|
if (team == 0) {
|
|
force_team.DeleteKey(authid);
|
|
} else {
|
|
force_team.SetNum(authid, team);
|
|
}
|
|
}
|
|
|
|
int get_force(int client) {
|
|
char authid[20];
|
|
GetClientAuthId(client, AuthId_SteamID64, authid, sizeof(authid));
|
|
|
|
return force_team.GetNum(authid, 0);
|
|
}
|
|
|
|
public Action:SetTeam(args) {
|
|
char player[128];
|
|
char team_str[128];
|
|
|
|
if (args != 2) {
|
|
PrintToServer("Usage: sm_setteam <player> red|blue|spec");
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
GetCmdArg(1, player, sizeof(player));
|
|
GetCmdArg(2, team_str, sizeof(team_str));
|
|
|
|
int team = parse_team(team_str);
|
|
|
|
if (team == 0) {
|
|
PrintToServer("Usage: sm_setteam <player> red|blue|spec");
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
int client = FindTarget(0, player, false, true);
|
|
|
|
set_force(client, 0);
|
|
ChangeClientTeam(client, team);
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public Action:ForceExec(args) {
|
|
char player[128];
|
|
char team_str[128];
|
|
|
|
if (args != 2) {
|
|
PrintToServer("Usage: sm_forceteam <player> red|blue|spec|free");
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
GetCmdArg(1, player, sizeof(player));
|
|
GetCmdArg(2, team_str, sizeof(team_str));
|
|
|
|
int team = parse_team(team_str);
|
|
|
|
int client = FindTarget(0, player, false, true);
|
|
|
|
if (team == 0) {
|
|
set_force(client, team);
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
ChangeClientTeam(client, team);
|
|
set_force(client, team);
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public Action:Command_JoinTeam(client, const String:command[], argc) {
|
|
if (get_force(client) > 0) {
|
|
return Plugin_Handled;
|
|
} else {
|
|
return Plugin_Continue;
|
|
}
|
|
}
|