3 * =============================================================================
4 * SourceMod Nextmap Plugin
5 * Adds sm_nextmap cvar for changing map and nextmap chat trigger.
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
37 #include "include/nextmap.inc"
39 public Plugin:myinfo =
42 author = "AlliedModders LLC",
43 description = "Provides nextmap and sm_nextmap",
44 version = SOURCEMOD_VERSION,
45 url = "http://www.sourcemod.net/"
50 new Handle:g_MapList = INVALID_HANDLE;
51 new g_MapListSerial = -1;
53 new g_CurrentMapStartTime;
55 public OnPluginStart()
57 decl String:desc[128];
58 GetGameFolderName(desc, sizeof(desc));
60 if (StrEqual(desc, "left4dead", false))
63 LoadTranslations("common.phrases");
64 LoadTranslations("nextmap.phrases");
66 g_MapList = CreateArray(32);
68 RegAdminCmd("sm_maphistory", Command_MapHistory, ADMFLAG_CHANGEMAP, "Shows the most recent maps played");
69 RegConsoleCmd("listmaps", Command_List);
71 // Set to the current map so OnMapStart() will know what to do
72 decl String:currentMap[64];
73 GetCurrentMap(currentMap, 64);
74 SetNextMap(currentMap);
79 g_CurrentMapStartTime = GetTime();
82 public OnConfigsExecuted()
84 decl String:desc[128];
85 GetGameFolderName(desc, sizeof(desc));
87 if (StrEqual(desc, "left4dead", false))
90 decl String:lastMap[64], String:currentMap[64];
91 GetNextMap(lastMap, sizeof(lastMap));
92 GetCurrentMap(currentMap, 64);
94 // 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
95 // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map
96 // not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret
97 if (strcmp(lastMap, currentMap) == 0)
103 public Action:Command_List(client, args)
105 PrintToConsole(client, "Map Cycle:");
107 new mapCount = GetArraySize(g_MapList);
108 decl String:mapName[32];
109 for (new i = 0; i < mapCount; i++)
111 GetArrayString(g_MapList, i, mapName, sizeof(mapName));
112 PrintToConsole(client, "%s", mapName);
115 return Plugin_Handled;
120 if (ReadMapList(g_MapList,
123 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT)
126 if (g_MapListSerial == -1)
128 LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
129 SetFailState("Mapcycle Not Found");
133 new mapCount = GetArraySize(g_MapList);
134 decl String:mapName[32];
138 decl String:current[64];
139 GetCurrentMap(current, 64);
141 for (new i = 0; i < mapCount; i++)
143 GetArrayString(g_MapList, i, mapName, sizeof(mapName));
144 if (strcmp(current, mapName, false) == 0)
156 if (g_MapPos >= mapCount)
159 GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName));
163 public Action:Command_MapHistory(client, args)
165 new mapCount = GetMapHistorySize();
167 decl String:mapName[32];
168 decl String:changeReason[100];
169 decl String:timeString[100];
170 decl String:playedTime[100];
173 new lastMapStartTime = g_CurrentMapStartTime;
175 PrintToConsole(client, "Map History:\n");
176 PrintToConsole(client, "Map : Started : Played Time : Reason for ending");
178 GetCurrentMap(mapName, sizeof(mapName));
179 PrintToConsole(client, "%02i. %s (Current Map)", 0, mapName);
181 for (new i=0; i<mapCount; i++)
183 GetMapHistory(i, mapName, sizeof(mapName), changeReason, sizeof(changeReason), startTime);
185 FormatTimeDuration(timeString, sizeof(timeString), GetTime() - startTime);
186 FormatTimeDuration(playedTime, sizeof(playedTime), lastMapStartTime - startTime);
188 PrintToConsole(client, "%02i. %s : %s ago : %s : %s", i+1, mapName, timeString, playedTime, changeReason);
190 lastMapStartTime = startTime;
194 FormatTimeDuration(String:buffer[], maxlen, time)
196 new days = time / 86400;
197 new hours = (time / 3600) % 24;
198 new minutes = (time / 60) % 60;
199 new seconds = time % 60;
203 return Format(buffer, maxlen, "%id %ih %im", days, hours, (seconds >= 30) ? minutes+1 : minutes);
207 return Format(buffer, maxlen, "%ih %im", hours, (seconds >= 30) ? minutes+1 : minutes);
209 else if (minutes > 0)
211 return Format(buffer, maxlen, "%im", (seconds >= 30) ? minutes+1 : minutes);
215 return Format(buffer, maxlen, "%is", seconds);