Skip to content

Commit

Permalink
Update coach targets based on join and .coach.
Browse files Browse the repository at this point in the history
Only one person can coach per match, no more swapping.

Backups store coaches as well so this will be stored and updated on match restore.
  • Loading branch information
PhlexPlexico committed Jun 26, 2022
1 parent 4d8be39 commit a32b867
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
18 changes: 14 additions & 4 deletions scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ static void AddTeamBackupData(KeyValues kv, MatchTeam team) {
kv.SetString("flag", g_TeamFlags[team]);
kv.SetString("logo", g_TeamLogos[team]);
kv.SetString("matchtext", g_TeamMatchTexts[team]);
kv.SetString("coach", g_TeamCoaches[team]);
if (!StrEqual(g_TeamCoaches[team], "")) {
kv.JumpToKey("coach", true);
kv.SetString(g_TeamCoaches[team], KEYVALUE_STRING_PLACEHOLDER);
kv.GoBack();
}
}
}

Expand Down Expand Up @@ -610,8 +614,14 @@ static void LoadTeamData(KeyValues kv, MatchTeam matchTeam) {
kv.GetString("flag", g_TeamFlags[matchTeam], MAX_CVAR_LENGTH, "");
kv.GetString("logo", g_TeamLogos[matchTeam], MAX_CVAR_LENGTH, "");
kv.GetString("matchtext", g_TeamMatchTexts[matchTeam], MAX_CVAR_LENGTH, "");
kv.GetString("coach", tmpCoach, AUTH_LENGTH, "");
ConvertAuthToSteam64(tmpCoach, g_TeamCoaches[matchTeam]);
if (kv.JumpToKey("coach")) {
if(kv.GotoFirstSubKey(false)) {
kv.GetSectionName(tmpCoach, AUTH_LENGTH);
ConvertAuthToSteam64(tmpCoach, g_TeamCoaches[matchTeam]);
kv.GoBack();
}
kv.GoBack();
}
} else {
KeyValues fromfilekv = new KeyValues("team");
if (fromfilekv.ImportFromFile(fromfile)) {
Expand Down Expand Up @@ -848,7 +858,7 @@ public Action Command_AddCoach(int client, int args) {
return Plugin_Handled;
}

if (strcmp(g_TeamCoaches[team], "") != 0) {
if (!StrEqual(g_TeamCoaches[team], "")) {
ReplyToCommand(client, "There is already a coach on that team.");
return Plugin_Handled;
}
Expand Down
14 changes: 12 additions & 2 deletions scripting/get5/teamlogic.sp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void CheckClientTeam(int client) {
} else if (GetAuth(client, auth, sizeof(auth))) {
char steam64[AUTH_LENGTH];
ConvertAuthToSteam64(auth, steam64);
if (strcmp(g_TeamCoaches[csTeam], steam64) == 0) {
if (StrEqual(g_TeamCoaches[csTeam], steam64)) {
UpdateCoachTarget(client, csTeam);
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public Action Command_JoinTeam(int client, const char[] command, int argc) {
KickClient(client, "%t", "TeamIsFullInfoMessage");
} else {
// Only attempt swapping if the coach slot is empty.
if (strcmp(g_TeamCoaches[correctTeam], "") == 0) {
if (StrEqual(g_TeamCoaches[correctTeam], "")) {
LogDebug("Forcing player %N to coach", client);
MoveClientToCoach(client);
Get5_Message(client, "%t", "MoveToCoachInfoMessage");
Expand Down Expand Up @@ -160,6 +160,7 @@ public void MoveClientToCoach(int client) {
}

public Action Command_SmCoach(int client, int args) {
char auth[AUTH_LENGTH];
if (g_GameState == Get5State_None) {
return Plugin_Continue;
}
Expand All @@ -168,11 +169,20 @@ public Action Command_SmCoach(int client, int args) {
return Plugin_Handled;
}

GetAuth(client, auth, sizeof(auth));
MatchTeam matchTeam = GetClientMatchTeam(client);
// Don't allow a new coach if one is already selected.
LogDebug("Attempting to get auth %s to coach when coach is %s", auth, g_TeamCoaches[matchTeam]);
if (!StrEqual(g_TeamCoaches[matchTeam], auth)) {
return Plugin_Stop;
}

MoveClientToCoach(client);
return Plugin_Handled;
}

public Action Command_Coach(int client, const char[] command, int argc) {

if (g_GameState == Get5State_None) {
return Plugin_Continue;
}
Expand Down

0 comments on commit a32b867

Please sign in to comment.