Skip to content

Commit

Permalink
0.10.2 (#876)
Browse files Browse the repository at this point in the history
Rename GetTeamAuths to GetTeamPlayers for consistency
Rename GetAuthMatchTeam to GetMatchTeamFromAuth
Rename IsAuthOnTeam to IsAuthOnTeamPlayer
Rename g_TeamAuths to g_TeamPlayers
GetMatchTeamFromAuth should check for spectator, then coach, then player
Properly handle spectator team assignment in CheckClientTeam
RemovePlayerFromTeams should always remove from both coaches and players array
Adjust docs to explain team assignment priority
Allow spectators in scrim template
Elaborate on !ringer targeting
Reset coach array when loading team data
Reset spectator array when loading spectators from json
Merge GetPlayerStat and SetPlayerStat calls
Bump version to 0.10.2
  • Loading branch information
nickdnk authored Sep 15, 2022
1 parent eece770 commit b22ce41
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 109 deletions.
8 changes: 5 additions & 3 deletions documentation/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,16 @@ from the server immediately.

####`get5_ringer <target>` {: #get5_ringer }
: Adds/removes a ringer to/from the home scrim team. `target` is the name of the player, their user ID or their Steam
ID. Similar to [`!ringer`](../commands/#ringer) in chat.
ID. Similar to [`!ringer`](../commands/#ringer) in chat. To target a user or Steam ID, prefix it with a `#`, i.e.
`get5_ringer #43` to target user ID 43.
See [this article](https://wiki.alliedmods.net/Admin_Commands_(SourceMod)#How_to_Target) for details.

!!! example "User ID vs client index"

To view user IDs, type `users` in console. In this example, `3` is the user ID and `1` is the client index:
To view user IDs, type `users` in console. In this example, `43` is the user ID and `1` is the client index:
```
> users
1:3:"Quinn"
1:43:"Quinn"
```

####`get5_debuginfo [file]` {: #get5_debuginfo }
Expand Down
18 changes: 17 additions & 1 deletion documentation/docs/match_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,29 @@ interface Get5Match {
point to must be in the same format as the main file, so pointing to a `.cfg` file when the main file is `.json`
will **not** work.
29. _Optional_<br>The name of the spectator team.<br><br>**`Default: "casters"`**
30. _Optional_<br>The spectator/caster Steam IDs and names.
30. _Optional_<br>The spectator/caster Steam IDs and names. Setting a Steam ID as spectator takes precedence over being
set as a player or coach.
31. _Optional_<br>Determines the starting sides for each map. If this array is shorter than `num_maps`, `side_type` will
determine the side-behavior of the remaining maps. Ignored if `skip_veto` is `false`.
<br><br>**`Default: undefined`**
32. _Optional_<br>If `false`, the entire map list will be played, regardless of score. If `true`, a series will be won
when the series score for a team exceeds the number of maps divided by two.<br><br>**`Default: true`**

!!! info "Team assignment priority"

If you define a Steam ID in more than one location in your match configuration, it will be evaluated in this order
to determine where to put the player:

1. Spectator
2. Coach for `team1`
3. Coach for `team2`
4. Player for `team1`
5. Player for `team2`

If a player's Steam ID was not found in any of these locations, they will be
[removed from the server](../configuration/#get5_check_auths) unless you are
in [scrim mode](../getting_started/#scrims).

## Examples {: #example }

These examples are identical in the way they would work if loaded.
Expand Down
6 changes: 3 additions & 3 deletions scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int g_MapNumber = 0; // the current map number, starting at 0.
int g_NumberOfMapsInSeries = 0; // the number of maps to play in the series.
char g_MatchID[MATCH_ID_LENGTH];
ArrayList g_MapPoolList = null;
ArrayList g_TeamAuths[MATCHTEAM_COUNT];
ArrayList g_TeamPlayers[MATCHTEAM_COUNT];
ArrayList g_TeamCoaches[MATCHTEAM_COUNT];
StringMap g_PlayerNames;
char g_TeamNames[MATCHTEAM_COUNT][MAX_CVAR_LENGTH];
Expand Down Expand Up @@ -571,8 +571,8 @@ public void OnPluginStart() {
g_CvarValues = new ArrayList(MAX_CVAR_LENGTH);
g_TeamScoresPerMap = new ArrayList(MATCHTEAM_COUNT);

for (int i = 0; i < sizeof(g_TeamAuths); i++) {
g_TeamAuths[i] = new ArrayList(AUTH_LENGTH);
for (int i = 0; i < sizeof(g_TeamPlayers); i++) {
g_TeamPlayers[i] = new ArrayList(AUTH_LENGTH);
// Same length.
g_TeamCoaches[i] = new ArrayList(AUTH_LENGTH);
}
Expand Down
2 changes: 1 addition & 1 deletion scripting/get5/debug.sp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static void AddGlobalStateInfo(File f) {
GetTeamString(team, buffer, sizeof(buffer));
f.WriteLine("Team info for %s (%d):", buffer, team);
f.WriteLine("g_TeamNames = %s", g_TeamNames[team]);
WriteArrayList(f, "g_TeamAuths", g_TeamAuths[team]);
WriteArrayList(f, "g_TeamPlayers", g_TeamPlayers[team]);
f.WriteLine("g_TeamTags = %s", g_TeamTags[team]);
f.WriteLine("g_FormattedTeamNames = %s", g_FormattedTeamNames[team]);
f.WriteLine("g_TeamFlags = %s", g_TeamFlags[team]);
Expand Down
38 changes: 25 additions & 13 deletions scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool LoadMatchConfig(const char[] config, bool restoreBackup = false) {
g_TechnicalPausesUsed[team] = 0;
}
ClearArray(GetTeamCoaches(team));
ClearArray(GetTeamAuths(team));
ClearArray(GetTeamPlayers(team));
}

g_MatchID = "";
Expand Down Expand Up @@ -149,7 +149,7 @@ bool LoadMatchConfig(const char[] config, bool restoreBackup = false) {
EventLogger_LogAndDeleteEvent(startEvent);

if (!g_CheckAuthsCvar.BoolValue &&
(GetTeamAuths(Get5Team_1).Length != 0 || GetTeamAuths(Get5Team_2).Length != 0 ||
(GetTeamPlayers(Get5Team_1).Length != 0 || GetTeamPlayers(Get5Team_2).Length != 0 ||
GetTeamCoaches(Get5Team_1).Length != 0 || GetTeamCoaches(Get5Team_2).Length != 0)) {
LogError(
"Setting player auths in the \"players\" or \"coaches\" section has no impact with get5_check_auths 0");
Expand Down Expand Up @@ -371,8 +371,8 @@ static void AddTeamBackupData(KeyValues kv, Get5Team team) {
kv.JumpToKey("players", true);
char auth[AUTH_LENGTH];
char name[MAX_NAME_LENGTH];
for (int i = 0; i < GetTeamAuths(team).Length; i++) {
GetTeamAuths(team).GetString(i, auth, sizeof(auth));
for (int i = 0; i < GetTeamPlayers(team).Length; i++) {
GetTeamPlayers(team).GetString(i, auth, sizeof(auth));
if (!g_PlayerNames.GetString(auth, name, sizeof(name))) {
strcopy(name, sizeof(name), KEYVALUE_STRING_PLACEHOLDER);
}
Expand Down Expand Up @@ -429,9 +429,9 @@ static bool LoadMatchFromKv(KeyValues kv) {
g_FavoredTeamPercentage = kv.GetNum("favored_percentage_team1", 0);
kv.GetString("favored_percentage_text", g_FavoredTeamText, sizeof(g_FavoredTeamText));

GetTeamAuths(Get5Team_Spec).Clear();
GetTeamPlayers(Get5Team_Spec).Clear();
if (kv.JumpToKey("spectators")) {
AddSubsectionAuthsToList(kv, "players", GetTeamAuths(Get5Team_Spec));
AddSubsectionAuthsToList(kv, "players", GetTeamPlayers(Get5Team_Spec));
kv.GetString("name", g_TeamNames[Get5Team_Spec], MAX_CVAR_LENGTH,
CONFIG_SPECTATORSNAME_DEFAULT);
kv.GoBack();
Expand Down Expand Up @@ -531,11 +531,12 @@ static bool LoadMatchFromJson(JSON_Object json) {
sizeof(g_FavoredTeamText));
g_FavoredTeamPercentage = json_object_get_int_safe(json, "favored_percentage_team1", 0);

GetTeamPlayers(Get5Team_Spec).Clear();
JSON_Object spec = json.GetObject("spectators");
if (spec != null) {
json_object_get_string_safe(spec, "name", g_TeamNames[Get5Team_Spec], MAX_CVAR_LENGTH,
CONFIG_SPECTATORSNAME_DEFAULT);
AddJsonAuthsToList(spec, "players", GetTeamAuths(Get5Team_Spec), AUTH_LENGTH);
AddJsonAuthsToList(spec, "players", GetTeamPlayers(Get5Team_Spec), AUTH_LENGTH);
FormatTeamName(Get5Team_Spec);
}

Expand Down Expand Up @@ -596,15 +597,16 @@ static bool LoadMatchFromJson(JSON_Object json) {
}

static void LoadTeamDataJson(JSON_Object json, Get5Team matchTeam) {
GetTeamAuths(matchTeam).Clear();
GetTeamPlayers(matchTeam).Clear();
GetTeamCoaches(matchTeam).Clear();

char fromfile[PLATFORM_MAX_PATH];
json_object_get_string_safe(json, "fromfile", fromfile, sizeof(fromfile));

if (StrEqual(fromfile, "")) {
// TODO: this needs to support both an array and a dictionary
// For now, it only supports an array
AddJsonAuthsToList(json, "players", GetTeamAuths(matchTeam), AUTH_LENGTH);
AddJsonAuthsToList(json, "players", GetTeamPlayers(matchTeam), AUTH_LENGTH);
JSON_Object coaches = json.GetObject("coaches");
if (coaches != null) {
AddJsonAuthsToList(json, "coaches", GetTeamCoaches(matchTeam), AUTH_LENGTH);
Expand All @@ -629,12 +631,13 @@ static void LoadTeamDataJson(JSON_Object json, Get5Team matchTeam) {
}

static void LoadTeamData(KeyValues kv, Get5Team matchTeam) {
GetTeamAuths(matchTeam).Clear();
GetTeamPlayers(matchTeam).Clear();
GetTeamCoaches(matchTeam).Clear();
char fromfile[PLATFORM_MAX_PATH];
kv.GetString("fromfile", fromfile, sizeof(fromfile));

if (StrEqual(fromfile, "")) {
AddSubsectionAuthsToList(kv, "players", GetTeamAuths(matchTeam));
AddSubsectionAuthsToList(kv, "players", GetTeamPlayers(matchTeam));
AddSubsectionAuthsToList(kv, "coaches", GetTeamCoaches(matchTeam));
kv.GetString("name", g_TeamNames[matchTeam], MAX_CVAR_LENGTH, "");
kv.GetString("tag", g_TeamTags[matchTeam], MAX_CVAR_LENGTH, "");
Expand Down Expand Up @@ -909,9 +912,9 @@ Action Command_AddCoach(int client, int args) {
if (AddCoachToTeam(auth, team, name)) {
// If the player is already on the team as a regular player, remove them when adding to
// coaches.
int index = GetTeamAuths(team).FindString(auth);
int index = GetTeamPlayers(team).FindString(auth);
if (index >= 0) {
GetTeamAuths(team).Erase(index);
GetTeamPlayers(team).Erase(index);
}

ReplyToCommand(client, "Successfully added player %s as coach for %s.", auth, teamString);
Expand Down Expand Up @@ -1176,6 +1179,15 @@ Action Command_CreateScrim(int client, int args) {
return Plugin_Handled;
}

// Allow spectators in scrim template.
if (kv.JumpToKey("spectators") && kv.JumpToKey("players") && kv.GotoFirstSubKey(false)) {
char name[MAX_NAME_LENGTH];
do {
WritePlaceholderInsteadOfEmptyString(kv, name, sizeof(name));
} while (kv.GotoNextKey(false));
kv.Rewind();
}

// Also ensure empty string values in cvars get printed to the match config.
if (kv.JumpToKey("cvars")) {
if (kv.GotoFirstSubKey(false)) {
Expand Down
6 changes: 3 additions & 3 deletions scripting/get5/natives.sp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ public int Native_GetPlayerTeam(Handle plugin, int numParams) {
GetNativeString(1, auth, sizeof(auth));

char steam64Auth[AUTH_LENGTH];
Get5Team team = Get5Team_None;
if (ConvertAuthToSteam64(auth, steam64Auth, false)) {
return view_as<int>(GetAuthMatchTeam(steam64Auth));
} else {
return view_as<int>(Get5Team_None);
team = GetMatchTeamFromAuth(steam64Auth);
}
return view_as<int>(team);
}

public int Native_CSTeamToGet5Team(Handle plugin, int numParams) {
Expand Down
14 changes: 4 additions & 10 deletions scripting/get5/stats.sp
Original file line number Diff line number Diff line change
Expand Up @@ -932,15 +932,10 @@ static Action Stats_RoundMVPEvent(Event event, const char[] name, bool dontBroad
}
}

static int GetPlayerStat(int client, const char[] field) {
GoToPlayer(client);
int value = g_StatsKv.GetNum(field);
GoBackFromPlayer();
return value;
}

static int SetPlayerStat(int client, const char[] field, int newValue) {
static int IncrementPlayerStatByValue(int client, const char[] field, int incrementBy) {
GoToPlayer(client);
int current = g_StatsKv.GetNum(field, 0);
int newValue = current + incrementBy;
g_StatsKv.SetNum(field, newValue);
GoBackFromPlayer();
return newValue;
Expand Down Expand Up @@ -1015,8 +1010,7 @@ int AddToPlayerStat(int client, const char[] field, int delta) {
return 0;
}
LogDebug("Updating player stat %s for %L", field, client);
int value = GetPlayerStat(client, field);
return SetPlayerStat(client, field, value + delta);
return IncrementPlayerStatByValue(client, field, delta);
}

static int IncrementPlayerStat(int client, const char[] field) {
Expand Down
Loading

0 comments on commit b22ce41

Please sign in to comment.