force team by steamid

This commit is contained in:
Robin Appelman 2026-03-28 23:52:58 +01:00
commit 280932c389

View file

@ -6,11 +6,11 @@ public Plugin:myinfo = {
name = "setteam", name = "setteam",
author = "Icewind", author = "Icewind",
description = "Set players team", description = "Set players team",
version = "0.1", version = "0.2",
url = "https://spire.tf" url = "https://spire.tf"
}; };
int force_team[MAXPLAYERS+1]; KeyValues force_team;
public OnPluginStart() { public OnPluginStart() {
RegServerCmd("sm_setteam", SetTeam, "Set a players team"); RegServerCmd("sm_setteam", SetTeam, "Set a players team");
@ -18,6 +18,8 @@ public OnPluginStart() {
AddCommandListener(Command_JoinTeam, "jointeam"); AddCommandListener(Command_JoinTeam, "jointeam");
AddCommandListener(Command_JoinTeam, "autoteam"); AddCommandListener(Command_JoinTeam, "autoteam");
force_team = new KeyValues("ForceTeam");
} }
int parse_team(const char[] team_str) { int parse_team(const char[] team_str) {
@ -36,6 +38,23 @@ int parse_team(const char[] team_str) {
return team; 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) { public Action:SetTeam(args) {
char player[128]; char player[128];
char team_str[128]; char team_str[128];
@ -58,7 +77,7 @@ public Action:SetTeam(args) {
int client = FindTarget(0, player, false, true); int client = FindTarget(0, player, false, true);
force_team[client] = 0; set_force(client, 0);
ChangeClientTeam(client, team); ChangeClientTeam(client, team);
return Plugin_Handled; return Plugin_Handled;
@ -81,35 +100,21 @@ public Action:ForceExec(args) {
int client = FindTarget(0, player, false, true); int client = FindTarget(0, player, false, true);
if (team == 0) { if (team == 0) {
force_team[client] = team; set_force(client, team);
return Plugin_Handled; return Plugin_Handled;
} }
ChangeClientTeam(client, team); ChangeClientTeam(client, team);
force_team[client] = team; set_force(client, team);
return Plugin_Handled; return Plugin_Handled;
} }
public Action:Command_JoinTeam(client, const String:command[], argc) { public Action:Command_JoinTeam(client, const String:command[], argc) {
if (force_team[client] > 0) { if (get_force(client) > 0) {
return Plugin_Handled; return Plugin_Handled;
} else { } else {
return Plugin_Continue; return Plugin_Continue;
} }
} }
public void OnClientConnected(client) {
force_team[client] = 0;
}
public void OnClientDisconnect(client) {
force_team[client] = 0;
}
public OnMapStart() {
for (int i = 0; i < MAXPLAYERS; i++) {
force_team[i] = 0;
}
}