Skip to content

Commit

Permalink
Add {nextmap} variable with MapChooser support
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMinekus committed Oct 19, 2020
1 parent a4bd145 commit 23ffa4d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addons/sourcemod/configs/advertisements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
"3"
{
"menu" "Next map is {sm_nextmap} in {timeleft} minutes."
"menu" "Next map is {nextmap} in {timeleft} minutes."
"flags" "cft"
}
"4"
Expand Down
23 changes: 23 additions & 0 deletions addons/sourcemod/scripting/advertisements.sp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <sourcemod>
#undef REQUIRE_PLUGIN
#include <mapchooser>
#include <updater>
#include "advertisements/chatcolors.sp"
#include "advertisements/topcolors.sp"
Expand Down Expand Up @@ -36,6 +37,7 @@ enum struct Advertisement
/**
* Globals
*/
bool g_bMapChooser;
bool g_bSayText2;
int g_iCurrentAd;
ArrayList g_hAdvertisements;
Expand All @@ -60,6 +62,7 @@ public void OnPluginStart()
g_hFile.AddChangeHook(ConVarChange_File);
g_hInterval.AddChangeHook(ConVarChange_Interval);

g_bMapChooser = LibraryExists("mapchooser");
g_bSayText2 = GetUserMessageId("SayText2") != INVALID_MESSAGE_ID;
g_hAdvertisements = new ArrayList(sizeof(Advertisement));

Expand All @@ -81,11 +84,21 @@ public void OnConfigsExecuted()

public void OnLibraryAdded(const char[] name)
{
if (StrEqual(name, "mapchooser")) {
g_bMapChooser = true;
}
if (StrEqual(name, "updater")) {
Updater_AddPlugin(UPDATE_URL);
}
}

public void OnLibraryRemoved(const char[] name)
{
if (StrEqual(name, "mapchooser")) {
g_bMapChooser = false;
}
}

public void ConVarChange_File(ConVar convar, const char[] oldValue, const char[] newValue)
{
ParseAds();
Expand Down Expand Up @@ -303,8 +316,18 @@ void ProcessVariables(const char[] message, char[] buffer, int maxlength)

if (StrEqual(name, "currentmap", false)) {
GetCurrentMap(value, sizeof(value));
GetMapDisplayName(value, value, sizeof(value));
buf_idx += strcopy(buffer[buf_idx], maxlength - buf_idx, value);
}
else if (StrEqual(name, "nextmap", false)) {
if (g_bMapChooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished()) {
buf_idx += strcopy(buffer[buf_idx], maxlength - buf_idx, "Pending Vote");
} else {
GetNextMap(value, sizeof(value));
GetMapDisplayName(value, value, sizeof(value));
buf_idx += strcopy(buffer[buf_idx], maxlength - buf_idx, value);
}
}
else if (StrEqual(name, "date", false)) {
FormatTime(value, sizeof(value), "%m/%d/%Y");
buf_idx += strcopy(buffer[buf_idx], maxlength - buf_idx, value);
Expand Down

0 comments on commit 23ffa4d

Please sign in to comment.