Update NextMap, Nominations, RandomCycle, and RockTheVote with newer MethodMap stuff

This commit is contained in:
Ross Bemrose 2014-12-16 14:16:06 -05:00
parent bc4d6b7104
commit 1b79252947
4 changed files with 86 additions and 82 deletions

View File

@ -47,7 +47,7 @@ public Plugin myinfo =
}; };
int g_MapPos = -1; int g_MapPos = -1;
Handle g_MapList = null; ArrayList g_MapList = null;
int g_MapListSerial = -1; int g_MapListSerial = -1;
int g_CurrentMapStartTime; int g_CurrentMapStartTime;
@ -78,14 +78,15 @@ public void OnPluginStart()
LoadTranslations("common.phrases"); LoadTranslations("common.phrases");
LoadTranslations("nextmap.phrases"); LoadTranslations("nextmap.phrases");
g_MapList = CreateArray(32); int size = ByteCountToCells(PLATFORM_MAX_PATH);
g_MapList = new ArrayList(size);
RegAdminCmd("sm_maphistory", Command_MapHistory, ADMFLAG_CHANGEMAP, "Shows the most recent maps played"); RegAdminCmd("sm_maphistory", Command_MapHistory, ADMFLAG_CHANGEMAP, "Shows the most recent maps played");
RegConsoleCmd("listmaps", Command_List); RegConsoleCmd("listmaps", Command_List);
// Set to the current map so OnMapStart() will know what to do // Set to the current map so OnMapStart() will know what to do
char currentMap[64]; char currentMap[PLATFORM_MAX_PATH];
GetCurrentMap(currentMap, 64); GetCurrentMap(currentMap, sizeof(currentMap));
SetNextMap(currentMap); SetNextMap(currentMap);
} }
@ -96,9 +97,9 @@ public void OnMapStart()
public void OnConfigsExecuted() public void OnConfigsExecuted()
{ {
char lastMap[64], currentMap[64]; char lastMap[PLATFORM_MAX_PATH], currentMap[PLATFORM_MAX_PATH];
GetNextMap(lastMap, sizeof(lastMap)); GetNextMap(lastMap, sizeof(lastMap));
GetCurrentMap(currentMap, 64); GetCurrentMap(currentMap, sizeof(currentMap));
// Why am I doing this? If we switched to a new map, but it wasn't what we expected (Due to sm_map, sm_votemap, or // Why am I doing this? If we switched to a new map, but it wasn't what we expected (Due to sm_map, sm_votemap, or
// some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map
@ -113,11 +114,11 @@ public Action Command_List(int client, int args)
{ {
PrintToConsole(client, "Map Cycle:"); PrintToConsole(client, "Map Cycle:");
int mapCount = GetArraySize(g_MapList); int mapCount = g_MapList.Length;
char mapName[32]; char mapName[PLATFORM_MAX_PATH];
for (int i = 0; i < mapCount; i++) for (int i = 0; i < mapCount; i++)
{ {
GetArrayString(g_MapList, i, mapName, sizeof(mapName)); g_MapList.GetString(i, mapName, sizeof(mapName));
PrintToConsole(client, "%s", mapName); PrintToConsole(client, "%s", mapName);
} }
@ -139,17 +140,17 @@ void FindAndSetNextMap()
} }
} }
int mapCount = GetArraySize(g_MapList); int mapCount = g_MapList.Length;
char mapName[32]; char mapName[PLATFORM_MAX_PATH];
if (g_MapPos == -1) if (g_MapPos == -1)
{ {
char current[64]; char current[PLATFORM_MAX_PATH];
GetCurrentMap(current, 64); GetCurrentMap(current, sizeof(current));
for (int i = 0; i < mapCount; i++) for (int i = 0; i < mapCount; i++)
{ {
GetArrayString(g_MapList, i, mapName, sizeof(mapName)); g_MapList.GetString(i, mapName, sizeof(mapName));
if (strcmp(current, mapName, false) == 0) if (strcmp(current, mapName, false) == 0)
{ {
g_MapPos = i; g_MapPos = i;
@ -165,7 +166,7 @@ void FindAndSetNextMap()
if (g_MapPos >= mapCount) if (g_MapPos >= mapCount)
g_MapPos = 0; g_MapPos = 0;
GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName)); g_MapList.GetString(g_MapPos, mapName, sizeof(mapName));
SetNextMap(mapName); SetNextMap(mapName);
} }
@ -173,7 +174,7 @@ public Action Command_MapHistory(int client, int args)
{ {
int mapCount = GetMapHistorySize(); int mapCount = GetMapHistorySize();
char mapName[32]; char mapName[PLATFORM_MAX_PATH];
char changeReason[100]; char changeReason[100];
char timeString[100]; char timeString[100];
char playedTime[100]; char playedTime[100];

View File

@ -50,7 +50,7 @@ ConVar g_Cvar_ExcludeOld;
ConVar g_Cvar_ExcludeCurrent; ConVar g_Cvar_ExcludeCurrent;
Menu g_MapMenu = null; Menu g_MapMenu = null;
Handle g_MapList = null; ArrayList g_MapList = null;
int g_mapFileSerial = -1; int g_mapFileSerial = -1;
#define MAPSTATUS_ENABLED (1<<0) #define MAPSTATUS_ENABLED (1<<0)
@ -66,8 +66,8 @@ public void OnPluginStart()
LoadTranslations("common.phrases"); LoadTranslations("common.phrases");
LoadTranslations("nominations.phrases"); LoadTranslations("nominations.phrases");
int arraySize = ByteCountToCells(33); int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
g_MapList = CreateArray(arraySize); g_MapList = new ArrayList(arraySize);
g_Cvar_ExcludeOld = CreateConVar("sm_nominate_excludeold", "1", "Specifies if the current map should be excluded from the Nominations list", 0, true, 0.00, true, 1.0); g_Cvar_ExcludeOld = CreateConVar("sm_nominate_excludeold", "1", "Specifies if the current map should be excluded from the Nominations list", 0, true, 0.00, true, 1.0);
g_Cvar_ExcludeCurrent = CreateConVar("sm_nominate_excludecurrent", "1", "Specifies if the MapChooser excluded maps should also be excluded from Nominations", 0, true, 0.00, true, 1.0); g_Cvar_ExcludeCurrent = CreateConVar("sm_nominate_excludecurrent", "1", "Specifies if the MapChooser excluded maps should also be excluded from Nominations", 0, true, 0.00, true, 1.0);
@ -123,7 +123,7 @@ public Action Command_Addmap(int client, int args)
return Plugin_Handled; return Plugin_Handled;
} }
char mapname[64]; char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname)); GetCmdArg(1, mapname, sizeof(mapname));
@ -184,7 +184,7 @@ public Action Command_Nominate(int client, int args)
return Plugin_Handled; return Plugin_Handled;
} }
char mapname[64]; char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname)); GetCmdArg(1, mapname, sizeof(mapname));
int status; int status;
@ -234,7 +234,7 @@ public Action Command_Nominate(int client, int args)
g_mapTrie.SetValue(mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); g_mapTrie.SetValue(mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
char name[64]; char name[MAX_NAME_LENGTH+1];
GetClientName(client, name, sizeof(name)); GetClientName(client, name, sizeof(name));
PrintToChatAll("[SM] %t", "Map Nominated", name, mapname); PrintToChatAll("[SM] %t", "Map Nominated", name, mapname);
@ -257,14 +257,14 @@ void BuildMapMenu()
g_MapMenu = new Menu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); g_MapMenu = new Menu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
char map[64]; char map[PLATFORM_MAX_PATH];
ArrayList excludeMaps; ArrayList excludeMaps;
char currentMap[32]; char currentMap[PLATFORM_MAX_PATH];
if (g_Cvar_ExcludeOld.BoolValue) if (g_Cvar_ExcludeOld.BoolValue)
{ {
excludeMaps = new ArrayList(ByteCountToCells(33)); excludeMaps = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH));
GetExcludeMapList(excludeMaps); GetExcludeMapList(excludeMaps);
} }
@ -274,11 +274,11 @@ void BuildMapMenu()
} }
for (int i = 0; i < GetArraySize(g_MapList); i++) for (int i = 0; i < g_MapList.Length; i++)
{ {
int status = MAPSTATUS_ENABLED; int status = MAPSTATUS_ENABLED;
GetArrayString(g_MapList, i, map, sizeof(map)); g_MapList.GetString(i, map, sizeof(map));
if (g_Cvar_ExcludeCurrent.BoolValue) if (g_Cvar_ExcludeCurrent.BoolValue)
{ {
@ -312,10 +312,10 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
{ {
case MenuAction_Select: case MenuAction_Select:
{ {
char map[64], name[64]; char map[PLATFORM_MAX_PATH], name[MAX_NAME_LENGTH+1];
menu.GetItem(param2, map, sizeof(map)); menu.GetItem(param2, map, sizeof(map));
GetClientName(param1, name, 64); GetClientName(param1, name, sizeof(name));
NominateResult result = NominateMap(map, false, param1); NominateResult result = NominateMap(map, false, param1);
@ -344,7 +344,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
case MenuAction_DrawItem: case MenuAction_DrawItem:
{ {
char map[64]; char map[PLATFORM_MAX_PATH];
menu.GetItem(param2, map, sizeof(map)); menu.GetItem(param2, map, sizeof(map));
int status; int status;
@ -366,7 +366,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
case MenuAction_DisplayItem: case MenuAction_DisplayItem:
{ {
char map[64]; char map[PLATFORM_MAX_PATH];
menu.GetItem(param2, map, sizeof(map)); menu.GetItem(param2, map, sizeof(map));
int status; int status;
@ -377,7 +377,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
return 0; return 0;
} }
char display[100]; char display[PLATFORM_MAX_PATH + 64];
if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{ {

View File

@ -34,7 +34,9 @@
#pragma semicolon 1 #pragma semicolon 1
#include <sourcemod> #include <sourcemod>
public Plugin:myinfo = #pragma newdecls required
public Plugin myinfo =
{ {
name = "RandomCycle", name = "RandomCycle",
author = "AlliedModders LLC", author = "AlliedModders LLC",
@ -45,22 +47,22 @@ public Plugin:myinfo =
ConVar g_Cvar_ExcludeMaps; ConVar g_Cvar_ExcludeMaps;
new Handle:g_MapList = null; ArrayList g_MapList = null;
new Handle:g_OldMapList = null; ArrayList g_OldMapList = null;
new g_mapListSerial = -1; int g_mapListSerial = -1;
public OnPluginStart() public void OnPluginStart()
{ {
new arraySize = ByteCountToCells(33); int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
g_MapList = CreateArray(arraySize); g_MapList = new ArrayList(arraySize);
g_OldMapList = CreateArray(arraySize); g_OldMapList = new ArrayList(arraySize);
g_Cvar_ExcludeMaps = CreateConVar("sm_randomcycle_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0); g_Cvar_ExcludeMaps = CreateConVar("sm_randomcycle_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
AutoExecConfig(true, "randomcycle"); AutoExecConfig(true, "randomcycle");
} }
public OnConfigsExecuted() public void OnConfigsExecuted()
{ {
if (ReadMapList(g_MapList, if (ReadMapList(g_MapList,
g_mapListSerial, g_mapListSerial,
@ -77,31 +79,31 @@ public OnConfigsExecuted()
CreateTimer(5.0, Timer_RandomizeNextmap); // Small delay to give Nextmap time to complete OnMapStart() CreateTimer(5.0, Timer_RandomizeNextmap); // Small delay to give Nextmap time to complete OnMapStart()
} }
public Action:Timer_RandomizeNextmap(Handle:timer) public Action Timer_RandomizeNextmap(Handle timer)
{ {
decl String:map[32]; char map[PLATFORM_MAX_PATH];
new bool:oldMaps = false; bool oldMaps = false;
if (g_Cvar_ExcludeMaps.IntValue && GetArraySize(g_MapList) > g_Cvar_ExcludeMaps.IntValue) if (g_Cvar_ExcludeMaps.IntValue && g_MapList.Length > g_Cvar_ExcludeMaps.IntValue)
{ {
oldMaps = true; oldMaps = true;
} }
new b = GetRandomInt(0, GetArraySize(g_MapList) - 1); int b = GetRandomInt(0, g_MapList.Length - 1);
GetArrayString(g_MapList, b, map, sizeof(map)); g_MapList.GetString(b, map, sizeof(map));
while (oldMaps && FindStringInArray(g_OldMapList, map) != -1) while (oldMaps && g_OldMapList.FindString(map) != -1)
{ {
b = GetRandomInt(0, GetArraySize(g_MapList) - 1); b = GetRandomInt(0, g_MapList.Length - 1);
GetArrayString(g_MapList, b, map, sizeof(map)); g_MapList.GetString(b, map, sizeof(map));
} }
PushArrayString(g_OldMapList, map); g_OldMapList.PushString(map);
SetNextMap(map); SetNextMap(map);
if (GetArraySize(g_OldMapList) > g_Cvar_ExcludeMaps.IntValue) if (g_OldMapList.Length > g_Cvar_ExcludeMaps.IntValue)
{ {
RemoveFromArray(g_OldMapList, 0); g_OldMapList.Erase(0);
} }
LogAction(-1, -1, "RandomCycle has chosen %s for the nextmap.", map); LogAction(-1, -1, "RandomCycle has chosen %s for the nextmap.", map);

View File

@ -36,8 +36,9 @@
#include <nextmap> #include <nextmap>
#pragma semicolon 1 #pragma semicolon 1
#pragma newdecls required
public Plugin:myinfo = public Plugin myinfo =
{ {
name = "Rock The Vote", name = "Rock The Vote",
author = "AlliedModders LLC", author = "AlliedModders LLC",
@ -53,16 +54,16 @@ ConVar g_Cvar_Interval;
ConVar g_Cvar_ChangeTime; ConVar g_Cvar_ChangeTime;
ConVar g_Cvar_RTVPostVoteAction; ConVar g_Cvar_RTVPostVoteAction;
new bool:g_CanRTV = false; // True if RTV loaded maps and is active. bool g_CanRTV = false; // True if RTV loaded maps and is active.
new bool:g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes. bool g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes.
new g_Voters = 0; // Total voters connected. Doesn't include fake clients. int g_Voters = 0; // Total voters connected. Doesn't include fake clients.
new g_Votes = 0; // Total number of "say rtv" votes int g_Votes = 0; // Total number of "say rtv" votes
new g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed) int g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed)
new bool:g_Voted[MAXPLAYERS+1] = {false, ...}; bool g_Voted[MAXPLAYERS+1] = {false, ...};
new bool:g_InChange = false; bool g_InChange = false;
public OnPluginStart() public void OnPluginStart()
{ {
LoadTranslations("common.phrases"); LoadTranslations("common.phrases");
LoadTranslations("rockthevote.phrases"); LoadTranslations("rockthevote.phrases");
@ -79,7 +80,7 @@ public OnPluginStart()
AutoExecConfig(true, "rtv"); AutoExecConfig(true, "rtv");
} }
public OnMapStart() public void OnMapStart()
{ {
g_Voters = 0; g_Voters = 0;
g_Votes = 0; g_Votes = 0;
@ -87,7 +88,7 @@ public OnMapStart()
g_InChange = false; g_InChange = false;
/* Handle late load */ /* Handle late load */
for (new i=1; i<=MaxClients; i++) for (int i=1; i<=MaxClients; i++)
{ {
if (IsClientConnected(i)) if (IsClientConnected(i))
{ {
@ -96,20 +97,20 @@ public OnMapStart()
} }
} }
public OnMapEnd() public void OnMapEnd()
{ {
g_CanRTV = false; g_CanRTV = false;
g_RTVAllowed = false; g_RTVAllowed = false;
} }
public OnConfigsExecuted() public void OnConfigsExecuted()
{ {
g_CanRTV = true; g_CanRTV = true;
g_RTVAllowed = false; g_RTVAllowed = false;
CreateTimer(g_Cvar_InitialDelay.FloatValue, Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE); CreateTimer(g_Cvar_InitialDelay.FloatValue, Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE);
} }
public OnClientConnected(client) public void OnClientConnected(int client)
{ {
if(IsFakeClient(client)) if(IsFakeClient(client))
return; return;
@ -122,7 +123,7 @@ public OnClientConnected(client)
return; return;
} }
public OnClientDisconnect(client) public void OnClientDisconnect(int client)
{ {
if(IsFakeClient(client)) if(IsFakeClient(client))
return; return;
@ -155,7 +156,7 @@ public OnClientDisconnect(client)
} }
} }
public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[]) public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
{ {
if (!g_CanRTV || !client) if (!g_CanRTV || !client)
{ {
@ -164,7 +165,7 @@ public OnClientSayCommand_Post(client, const String:command[], const String:sArg
if (strcmp(sArgs, "rtv", false) == 0 || strcmp(sArgs, "rockthevote", false) == 0) if (strcmp(sArgs, "rtv", false) == 0 || strcmp(sArgs, "rockthevote", false) == 0)
{ {
new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT); ReplySource old = SetCmdReplySource(SM_REPLY_TO_CHAT);
AttemptRTV(client); AttemptRTV(client);
@ -172,7 +173,7 @@ public OnClientSayCommand_Post(client, const String:command[], const String:sArg
} }
} }
public Action:Command_RTV(client, args) public Action Command_RTV(int client, int args)
{ {
if (!g_CanRTV || !client) if (!g_CanRTV || !client)
{ {
@ -184,7 +185,7 @@ public Action:Command_RTV(client, args)
return Plugin_Handled; return Plugin_Handled;
} }
AttemptRTV(client) void AttemptRTV(int client)
{ {
if (!g_RTVAllowed || (g_Cvar_RTVPostVoteAction.IntValue == 1 && HasEndOfMapVoteFinished())) if (!g_RTVAllowed || (g_Cvar_RTVPostVoteAction.IntValue == 1 && HasEndOfMapVoteFinished()))
{ {
@ -210,7 +211,7 @@ AttemptRTV(client)
return; return;
} }
new String:name[64]; char name[MAX_NAME_LENGTH+1];
GetClientName(client, name, sizeof(name)); GetClientName(client, name, sizeof(name));
g_Votes++; g_Votes++;
@ -224,12 +225,12 @@ AttemptRTV(client)
} }
} }
public Action:Timer_DelayRTV(Handle:timer) public Action Timer_DelayRTV(Handle timer)
{ {
g_RTVAllowed = true; g_RTVAllowed = true;
} }
StartRTV() void StartRTV()
{ {
if (g_InChange) if (g_InChange)
{ {
@ -239,7 +240,7 @@ StartRTV()
if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished()) if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished())
{ {
/* Change right now then */ /* Change right now then */
new String:map[65]; char map[PLATFORM_MAX_PATH];
if (GetNextMap(map, sizeof(map))) if (GetNextMap(map, sizeof(map)))
{ {
PrintToChatAll("[SM] %t", "Changing Maps", map); PrintToChatAll("[SM] %t", "Changing Maps", map);
@ -255,7 +256,7 @@ StartRTV()
if (CanMapChooserStartVote()) if (CanMapChooserStartVote())
{ {
new MapChange:when = MapChange:g_Cvar_ChangeTime.IntValue; MapChange when = view_as<MapChange>(g_Cvar_ChangeTime.IntValue);
InitiateMapChooserVote(when); InitiateMapChooserVote(when);
ResetRTV(); ResetRTV();
@ -265,23 +266,23 @@ StartRTV()
} }
} }
ResetRTV() void ResetRTV()
{ {
g_Votes = 0; g_Votes = 0;
for (new i=1; i<=MAXPLAYERS; i++) for (int i=1; i<=MAXPLAYERS; i++)
{ {
g_Voted[i] = false; g_Voted[i] = false;
} }
} }
public Action:Timer_ChangeMap(Handle:hTimer) public Action Timer_ChangeMap(Handle hTimer)
{ {
g_InChange = false; g_InChange = false;
LogMessage("RTV changing map manually"); LogMessage("RTV changing map manually");
new String:map[65]; char map[PLATFORM_MAX_PATH];
if (GetNextMap(map, sizeof(map))) if (GetNextMap(map, sizeof(map)))
{ {
ForceChangeLevel(map, "RTV after mapvote"); ForceChangeLevel(map, "RTV after mapvote");