extensions now use the repository build number intsead of their local commit number
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"
40 public Plugin:myinfo =
43 author = "AlliedModders LLC",
44 description = "Provides nextmap and sm_nextmap",
45 version = SOURCEMOD_VERSION,
46 url = "http://www.sourcemod.net/"
51 new Handle:g_MapList = INVALID_HANDLE;
52 new g_MapListSerial = -1;
54 public OnPluginStart()
56 LoadTranslations("common.phrases");
57 LoadTranslations("nextmap.phrases");
59 g_MapList = CreateArray(32);
61 RegConsoleCmd("say", Command_Say);
62 RegConsoleCmd("say_team", Command_Say);
64 RegConsoleCmd("nextmap", Command_Nextmap);
66 RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
67 RegConsoleCmd("listmaps", Command_List);
69 // Set to the current map so OnMapStart() will know what to do
70 decl String:currentMap[64];
71 GetCurrentMap(currentMap, 64);
72 SetNextMap(currentMap);
75 public OnConfigsExecuted()
77 decl String:lastMap[64], String:currentMap[64];
78 GetNextMap(lastMap, sizeof(lastMap));
79 GetCurrentMap(currentMap, 64);
81 // 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
82 // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map
83 // not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret
84 if (strcmp(lastMap, currentMap) == 0)
90 public Action:Command_Say(client, args)
92 decl String:text[192];
93 if (GetCmdArgString(text, sizeof(text)) < 1)
95 return Plugin_Continue;
99 if (text[strlen(text)-1] == '"')
101 text[strlen(text)-1] = '\0';
105 decl String:message[8];
106 BreakString(text[startidx], message, sizeof(message));
108 if (strcmp(message, "nextmap", false) == 0)
111 GetNextMap(map, sizeof(map));
113 PrintToChat(client, "[SM] %t", "Next Map", map);
116 return Plugin_Continue;
119 public Action:Command_SetNextmap(client, args)
123 ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>");
124 return Plugin_Handled;
128 GetCmdArg(1, map, sizeof(map));
130 if (!IsMapValid(map))
132 ReplyToCommand(client, "[SM] %t", "Map was not found", map);
133 return Plugin_Handled;
136 ShowActivity(client, "%t", "Changed Next Map", map);
137 LogMessage("\"%L\" changed nextmap to \"%s\"", client, map);
141 return Plugin_Handled;
144 public Action:Command_List(client, args)
146 PrintToConsole(client, "Map Cycle:");
148 new mapCount = GetArraySize(g_MapList);
149 decl String:mapName[32];
150 for (new i = 0; i < mapCount; i++)
152 GetArrayString(g_MapList, i, mapName, sizeof(mapName));
153 PrintToConsole(client, "%s", mapName);
156 return Plugin_Handled;
159 public Action:Command_Nextmap(client, args)
163 GetNextMap(map, sizeof(map));
165 ReplyToCommand(client, "[SM] %t", "Next Map", map);
167 return Plugin_Handled;
172 if (ReadMapList(g_MapList,
175 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT)
178 if (g_MapListSerial == -1)
180 LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
181 SetFailState("Mapcycle Not Found");
185 new mapCount = GetArraySize(g_MapList);
186 decl String:mapName[32];
190 decl String:current[64];
191 GetCurrentMap(current, 64);
193 for (new i = 0; i < mapCount; i++)
195 GetArrayString(g_MapList, i, mapName, sizeof(mapName));
196 if (strcmp(current, mapName, false) == 0)
208 if (g_MapPos >= mapCount)
211 GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName));