Skip to content

Commit

Permalink
0.14.1 (#1009)
Browse files Browse the repository at this point in the history
* Fix create match with current teams from menu (#1007)
* Add option to disable formatting known map names (#1008)
0.14.1
  • Loading branch information
nickdnk authored Apr 8, 2023
1 parent b13d91c commit f37aaad
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 34 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ Whenever you update your Get5 plugin, remember to **always** update the `transla
Please see the [installation instructions](https://splewis.github.io/get5/latest/installation/#installation) for
details.

# 0.14.1

#### 2023-04-08

Hotfix of stuff that should have been in 0.14.0.

1. Fixed "create match with current teams" from the `!get5` menu.
2. Add option to disable formatting known map names via [`get5_format_map_names`](https://splewis.github.io/get5/latest/configuration/#get5_format_map_names).

# 0.14.0

*Note: Removed from releases. Please use 0.14.1 instead.*

#### 2023-04-08

### Breaking Changes 🛠
Expand Down
3 changes: 3 additions & 0 deletions documentation/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ value will be used for your [backup upload HTTP request](#get5_remote_backup_url

## Formats & Paths

####`get5_format_map_names`
: Whether to format known map names in chat and menus, i.e. `de_mirage` becomes `Mirage`.<br>**`Default: 1`**

####`get5_time_format`
: Date and time format string. This determines the [`{TIME}`](#tag-time) tag.<br>**`Default: "%Y-%m-%d_%H-%M-%S"`**

Expand Down
4 changes: 3 additions & 1 deletion scripting/get5.sp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ConVar g_DamagePrintExcessCvar;
ConVar g_DamagePrintFormatCvar;
ConVar g_DemoNameFormatCvar;
ConVar g_DisplayGotvVetoCvar;
ConVar g_FormatMapNamesCvar;
ConVar g_EventLogFormatCvar;
ConVar g_EventLogRemoteURLCvar;
ConVar g_EventLogRemoteHeaderKeyCvar;
Expand Down Expand Up @@ -483,6 +484,7 @@ public void OnPluginStart() {
g_MuteAllChatDuringMapSelectionCvar = CreateConVar("get5_mute_allchat_during_map_selection", "1", "If enabled, only the team captains can type in all-chat during map selection.");
g_PauseOnVetoCvar = CreateConVar("get5_pause_on_veto", "1", "Whether the game pauses during map selection.");
g_DisplayGotvVetoCvar = CreateConVar("get5_display_gotv_veto", "0", "Whether to wait for map selection to be broadcast to GOTV before changing map.");
g_FormatMapNamesCvar = CreateConVar("get5_format_map_names", "1", "Whether to format known map names.");

// Server config
g_AutoLoadConfigCvar = CreateConVar("get5_autoload_config", "", "The path/name of a match config file to automatically load when the server loads or when the first player joins.");
Expand Down Expand Up @@ -1576,7 +1578,7 @@ static Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast
// state immediately while waiting for the restartDelay, we set it here also.
g_MapChangePending = true;
char nextMapFormatted[PLATFORM_MAX_PATH];
FormatMapName(nextMap, nextMapFormatted, sizeof(nextMapFormatted), true, true);
FormatMapName(nextMap, nextMapFormatted, sizeof(nextMapFormatted), g_FormatMapNamesCvar.BoolValue, true);
Get5_MessageToAll("%t", "NextSeriesMapInfoMessage", nextMapFormatted, timeToMapChangeFormatted);
ChangeState(Get5State_PostGame);
// Subtracting 4 seconds makes the map change 1 second before the timer expires, as there is a 3
Expand Down
31 changes: 23 additions & 8 deletions scripting/get5/get5menu.sp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ static int SetupMenuHandler(Menu menu, MenuAction action, int client, int param2
return 0;
} else if (StrEqual(infoString, SETUP_MENU_START_MATCH, true)) {
if (g_SetupMenuTeamSelection == Get5SetupMenu_TeamSelectionMode_Current &&
(GetTeamPlayerCount(Get5Team_1) != g_SetupMenuPlayersPerTeam ||
GetTeamPlayerCount(Get5Team_2) != g_SetupMenuPlayersPerTeam)) {
(GetSidePlayerCount(Get5Side_CT) != g_SetupMenuPlayersPerTeam ||
GetSidePlayerCount(Get5Side_T) != g_SetupMenuPlayersPerTeam)) {
Get5_Message(client, "Both teams must have %d player(s) when using current teams.", g_SetupMenuPlayersPerTeam);
} else if (g_SetupMenuTeamSelection == Get5SetupMenu_TeamSelectionMode_Fixed &&
(strlen(g_SetupMenuTeamForTeam1) == 0 || strlen(g_SetupMenuTeamForTeam2) == 0)) {
Expand Down Expand Up @@ -337,6 +337,16 @@ static int SetupMenuHandler(Menu menu, MenuAction action, int client, int param2
return 0;
}

static int GetSidePlayerCount(Get5Side side) {
int playerCount = 0;
LOOP_CLIENTS(i) {
if (IsPlayer(i) && view_as<Get5Side>(GetClientTeam(i)) == side) {
playerCount++;
}
}
return playerCount;
}

static void ShowSelectTeamsMenu(int client) {
Menu menu = new Menu(SelectTeamsMenuHandler);
menu.SetTitle("Select Teams");
Expand Down Expand Up @@ -555,14 +565,19 @@ static void ShowSelectMapMenu(int client) {
sortedMaps.PushString(mapName);
}

// Sorts maps based on their formatted name.
sortedMaps.SortCustom(SortMapsBasedOnFormattedName);
bool formatMapNames = g_FormatMapNamesCvar.BoolValue;
if (formatMapNames) {
// Sorts maps based on their formatted name.
sortedMaps.SortCustom(SortMapsBasedOnFormattedName);
} else {
sortedMaps.Sort(Sort_Ascending, Sort_String);
}

char formattedMapName[PLATFORM_MAX_PATH];
l = sortedMaps.Length;
for (int i = 0; i < l; i++) {
sortedMaps.GetString(i, mapName, sizeof(mapName));
FormatMapName(mapName, formattedMapName, sizeof(formattedMapName), true);
FormatMapName(mapName, formattedMapName, sizeof(formattedMapName), formatMapNames);
menu.AddItem(mapName, formattedMapName);
}
delete sortedMaps;
Expand Down Expand Up @@ -882,8 +897,8 @@ static void CreateMatch(int client) {

if (g_SetupMenuTeamSelection == Get5SetupMenu_TeamSelectionMode_Current) {

match.SetObject("team1", GetTeamObjectFromCurrentPlayers(Get5Team_1, g_SetupMenuTeam1Captain));
match.SetObject("team2", GetTeamObjectFromCurrentPlayers(Get5Team_2, g_SetupMenuTeam2Captain));
match.SetObject("team1", GetTeamObjectFromCurrentPlayers(Get5Side_CT, g_SetupMenuTeam1Captain));
match.SetObject("team2", GetTeamObjectFromCurrentPlayers(Get5Side_T, g_SetupMenuTeam2Captain));

} else if (g_SetupMenuTeamSelection == Get5SetupMenu_TeamSelectionMode_Fixed) {

Expand All @@ -897,7 +912,7 @@ static void CreateMatch(int client) {
match.SetObject("team1", g_SetupMenuAvailableTeams.GetObject(g_SetupMenuTeamForTeam1).DeepCopy());
}

JSON_Object spectators = GetTeamObjectFromCurrentPlayers(Get5Team_Spec);
JSON_Object spectators = GetTeamObjectFromCurrentPlayers(Get5Side_Spec);
if (view_as<JSON_Array>(spectators.GetObject("players")).Length > 0) {
match.SetObject("spectators", spectators);
} else {
Expand Down
2 changes: 1 addition & 1 deletion scripting/get5/maps.sp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
void ChangeMap(const char[] map, float delay = 3.0) {
char formattedMapName[64];
FormatMapName(map, formattedMapName, sizeof(formattedMapName), true, true);
FormatMapName(map, formattedMapName, sizeof(formattedMapName), g_FormatMapNamesCvar.BoolValue, true);
Get5_MessageToAll("%t", "ChangingMapInfoMessage", formattedMapName);

// pass the "true" name to a timer to changelevel
Expand Down
14 changes: 8 additions & 6 deletions scripting/get5/mapveto.sp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ static void FinishVeto() {

// If a team has a map advantage, don't print that map.
int mapNumber = Get5_GetMapNumber();
bool formatMapNames = g_FormatMapNamesCvar.BoolValue;
for (int i = mapNumber; i < g_MapsToPlay.Length; i++) {
char map[PLATFORM_MAX_PATH];
g_MapsToPlay.GetString(i, map, sizeof(map));
FormatMapName(map, map, sizeof(map), true, true);
FormatMapName(map, map, sizeof(map), formatMapNames, true);
Get5_MessageToAll("%t", "MapIsInfoMessage", i + 1 - mapNumber, map);
}

Expand Down Expand Up @@ -309,7 +310,7 @@ static void PromptForSideSelectionInChat(const Get5Team team) {
char mapName[PLATFORM_MAX_PATH];
g_MapsToPlay.GetString(g_MapsToPlay.Length - 1, mapName, sizeof(mapName));
char formattedMapName[PLATFORM_MAX_PATH];
FormatMapName(mapName, formattedMapName, sizeof(formattedMapName), true, true);
FormatMapName(mapName, formattedMapName, sizeof(formattedMapName), g_FormatMapNamesCvar.BoolValue, true);
Get5_MessageToAll("%t", "MapSelectionPickSide", g_FormattedTeamNames[team], formattedMapName);

int client = g_VetoCaptains[team];
Expand All @@ -325,9 +326,10 @@ static void PromptForSideSelectionInChat(const Get5Team team) {

void ImplodeMapArrayToString(const ArrayList mapPool, char[] buffer, const int bufferSize, bool sort) {
char[][] mapsArray = new char[mapPool.Length][PLATFORM_MAX_PATH];
bool formatMapNames = g_FormatMapNamesCvar.BoolValue;
for (int i = 0; i < mapPool.Length; i++) {
mapPool.GetString(i, mapsArray[i], PLATFORM_MAX_PATH);
FormatMapName(mapsArray[i], mapsArray[i], PLATFORM_MAX_PATH, true, false);
FormatMapName(mapsArray[i], mapsArray[i], PLATFORM_MAX_PATH, formatMapNames, false);
}
// Sort alphabetically.
if (sort) {
Expand All @@ -345,7 +347,7 @@ static bool BanMap(const char[] mapName, const Get5Team team) {
return false;
}
char mapNameFormatted[PLATFORM_MAX_PATH];
FormatMapName(mapNameFromArray, mapNameFormatted, sizeof(mapNameFormatted), true, false);
FormatMapName(mapNameFromArray, mapNameFormatted, sizeof(mapNameFormatted), g_FormatMapNamesCvar.BoolValue, false);
// Add color here as FormatMapName would make the color green.
Format(mapNameFormatted, sizeof(mapNameFormatted), "{LIGHT_RED}%s{NORMAL}", mapNameFormatted);
Get5_MessageToAll("%t", "TeamBannedMap", g_FormattedTeamNames[team], mapNameFormatted);
Expand All @@ -372,7 +374,7 @@ static bool PickMap(const char[] mapName, const Get5Team team) {
}
if (team != Get5Team_None) {
char mapNameFormatted[PLATFORM_MAX_PATH];
FormatMapName(mapNameFromArray, mapNameFormatted, sizeof(mapNameFormatted), true, true);
FormatMapName(mapNameFromArray, mapNameFormatted, sizeof(mapNameFormatted), g_FormatMapNamesCvar.BoolValue, true);
Get5_MessageToAll("%t", "TeamPickedMap", g_FormattedTeamNames[team], mapNameFormatted, g_MapsToPlay.Length + 1);
}

Expand Down Expand Up @@ -404,7 +406,7 @@ static void PickSide(const Get5Side side, const Get5Team team) {
char mapName[PLATFORM_MAX_PATH];
g_MapsToPlay.GetString(mapNumber, mapName, sizeof(mapName));
char mapNameFormatted[PLATFORM_MAX_PATH];
FormatMapName(mapName, mapNameFormatted, sizeof(mapNameFormatted), true, true);
FormatMapName(mapName, mapNameFormatted, sizeof(mapNameFormatted), g_FormatMapNamesCvar.BoolValue, true);

char sideFormatted[32];
FormatEx(sideFormatted, sizeof(sideFormatted), "{GREEN}%s{NORMAL}", side == Get5Side_CT ? "CT" : "T");
Expand Down
31 changes: 14 additions & 17 deletions scripting/get5/matchconfig.sp
Original file line number Diff line number Diff line change
Expand Up @@ -1829,8 +1829,8 @@ Action Command_CreateMatch(int client, int args) {

// If neither team is provided, use current teams.
if (!hasTeam1 && !hasTeam2) {
JSON_Object team1 = GetTeamObjectFromCurrentPlayers(Get5Team_1);
JSON_Object team2 = GetTeamObjectFromCurrentPlayers(Get5Team_2);
JSON_Object team1 = GetTeamObjectFromCurrentPlayers(Get5Side_CT);
JSON_Object team2 = GetTeamObjectFromCurrentPlayers(Get5Side_T);
int team1PlayerLength = view_as<JSON_Array>(team1.GetObject("players")).Length;
int team2PlayerLength = view_as<JSON_Array>(team2.GetObject("players")).Length;
matchConfig.SetObject("team1", team1);
Expand Down Expand Up @@ -2038,7 +2038,7 @@ Action Command_Ringer(int client, int args) {
return Plugin_Handled;
}

JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Team team, int forcedCaptainClient = 0) {
JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Side side, int forcedCaptainClient = 0) {
JSON_Object teamObject = new JSON_Object();
JSON_Array players = new JSON_Array();

Expand All @@ -2050,7 +2050,7 @@ JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Team team, int forcedCapta
if (forcedCaptainClient > 0) {
LOOP_CLIENTS(i) {
if (i == forcedCaptainClient) {
if (CheckIfClientIsOnTeam(i, team, false) && GetAuth(i, auth, sizeof(auth))) {
if (CheckIfClientIsOnSide(i, side, false) && GetAuth(i, auth, sizeof(auth))) {
SetTeamNameFromClient(i, teamName, sizeof(teamName));
players.PushString(auth);
first = false;
Expand All @@ -2064,9 +2064,9 @@ JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Team team, int forcedCapta
// Already added above.
continue;
}
if (CheckIfClientIsOnTeam(i, team, false) && GetAuth(i, auth, sizeof(auth))) {
if (CheckIfClientIsOnSide(i, side, false) && GetAuth(i, auth, sizeof(auth))) {
players.PushString(auth);
if (first && team != Get5Team_Spec) {
if (first && side != Get5Side_Spec) {
SetTeamNameFromClient(i, teamName, sizeof(teamName));
}
first = false;
Expand All @@ -2076,15 +2076,17 @@ JSON_Object GetTeamObjectFromCurrentPlayers(const Get5Team team, int forcedCapta
teamObject.SetString("name", teamName);
}
teamObject.SetObject("players", players);
AddCoachesToAuthJSON(teamObject, team);
if (side != Get5Side_Spec) {
AddCoachesToAuthJSON(teamObject, side);
}
return teamObject;
}

void AddCoachesToAuthJSON(const JSON_Object json, const Get5Team team) {
static void AddCoachesToAuthJSON(const JSON_Object json, const Get5Side side) {
JSON_Array coaches;
char auth[AUTH_LENGTH];
LOOP_CLIENTS(i) {
if (CheckIfClientIsOnTeam(i, team, true) && GetAuth(i, auth, sizeof(auth))) {
if (CheckIfClientIsOnSide(i, side, true) && GetAuth(i, auth, sizeof(auth))) {
if (coaches == null) {
coaches = new JSON_Array();
}
Expand All @@ -2100,17 +2102,12 @@ static void SetTeamNameFromClient(const int client, char[] teamName, const int t
FormatEx(teamName, teamNameLength, "team_%N", client);
}

static bool CheckIfClientIsOnTeam(const int client, const Get5Team team, const bool coaching) {
static bool CheckIfClientIsOnSide(const int client, const Get5Side side, const bool coaching) {
if (!IsAuthedPlayer(client)) {
return false;
}
Get5Side side = coaching ? GetClientCoachingSide(client) : view_as<Get5Side>(GetClientTeam(client));
if (team == Get5Team_1 && side == Get5Side_CT) {
return true;
} else if (team == Get5Team_2 && side == Get5Side_T) {
return true;
}
return false;
Get5Side currentSide = coaching ? GetClientCoachingSide(client) : view_as<Get5Side>(GetClientTeam(client));
return currentSide == side;
}

// Adds the team logos to the download table.
Expand Down
2 changes: 1 addition & 1 deletion scripting/get5/version.sp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define PLUGIN_VERSION "0.14.0-dev"
#define PLUGIN_VERSION "0.14.1-dev"
// This MUST be the latest version in x.y.z semver format followed by -dev.
// If this is not consistently applied, the update-checker might malfunction.
// In official releases, the CI flow will remove the -dev suffix when compiling the plugin.
Expand Down

0 comments on commit f37aaad

Please sign in to comment.