3 * =============================================================================
4 * SourceMod Nextmap Plugin
5 * Adds sm_nextmap cvar for changing map and nextmap chat trigger.
7 * SourceMod (C)2004-2007 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>.
38 public Plugin:myinfo =
41 author = "AlliedModders LLC",
42 description = "Provides nextmap and sm_nextmap",
43 version = SOURCEMOD_VERSION,
44 url = "http://www.sourcemod.net/"
47 new bool:g_IntermissionCalled;
48 new UserMsg:g_VGUIMenu;
50 new Handle:g_Cvar_Chattime;
51 new Handle:g_Cvar_Nextmap;
54 new Handle:g_MapList = INVALID_HANDLE;
55 new g_MapListSerial = -1;
57 public OnPluginStart()
59 LoadTranslations("common.phrases");
60 LoadTranslations("nextmap.phrases");
62 g_VGUIMenu = GetUserMessageId("VGUIMenu");
63 if (g_VGUIMenu == INVALID_MESSAGE_ID)
65 LogError("FATAL: Cannot find VGUIMenu user message id. Nextmap not loaded.");
66 SetFailState("VGUIMenu Not Found");
69 g_MapList = CreateArray(32);
71 HookUserMessage(g_VGUIMenu, UserMsg_VGUIMenu);
73 g_Cvar_Nextmap = CreateConVar("sm_nextmap", "", "Sets the Next Map", FCVAR_NOTIFY);
74 g_Cvar_Chattime = FindConVar("mp_chattime");
76 RegConsoleCmd("say", Command_Say);
77 RegConsoleCmd("say_team", Command_Say);
79 RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
80 RegConsoleCmd("listmaps", Command_List);
82 // Set to the current map so OnMapStart() will know what to do
83 decl String:currentMap[64];
84 GetCurrentMap(currentMap, 64);
85 SetConVarString(g_Cvar_Nextmap, currentMap);
88 public OnConfigsExecuted()
90 decl String:lastMap[64], String:currentMap[64];
91 GetConVarString(g_Cvar_Nextmap, lastMap, 64);
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)
99 if (ReadMapList(g_MapList,
102 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT)
105 if (g_MapListSerial == -1)
107 LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
108 SetFailState("Mapcycle Not Found");
118 g_IntermissionCalled = false;
121 public Action:Command_Say(client, args)
123 decl String:text[192];
124 if (GetCmdArgString(text, sizeof(text)) < 1)
126 return Plugin_Continue;
130 if (text[strlen(text)-1] == '"')
132 text[strlen(text)-1] = '\0';
136 decl String:message[8];
137 BreakString(text[startidx], message, sizeof(message));
139 if (strcmp(message, "nextmap", false) == 0)
142 GetConVarString(g_Cvar_Nextmap, map, sizeof(map));
144 PrintToChatAll("%t", "Next Map", map);
147 return Plugin_Continue;
150 public Action:Command_SetNextmap(client, args)
154 ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>");
155 return Plugin_Handled;
159 GetCmdArg(1, map, sizeof(map));
161 if (!IsMapValid(map))
163 ReplyToCommand(client, "[SM] %t", "Map was not found", map);
164 return Plugin_Handled;
167 ShowActivity(client, "%t", "Cvar changed", "sm_nextmap", map);
168 LogMessage("\"%L\" changed sm_nextmap to \"%s\"", client, map);
170 SetConVarString(g_Cvar_Nextmap, map);
172 return Plugin_Handled;
175 public Action:Command_List(client, args)
177 PrintToConsole(client, "Map Cycle:");
179 new mapCount = GetArraySize(g_MapList);
180 decl String:mapName[32];
181 for (new i = 0; i < mapCount; i++)
183 GetArrayString(g_MapList, i, mapName, sizeof(mapName));
184 PrintToConsole(client, "%s", mapName);
187 return Plugin_Handled;
190 public Action:UserMsg_VGUIMenu(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
192 if (g_IntermissionCalled)
194 return Plugin_Handled;
197 decl String:type[15];
199 /* If we don't get a valid string, bail out. */
200 if (BfReadString(bf, type, sizeof(type)) < 0)
202 return Plugin_Handled;
205 if (BfReadByte(bf) == 1 && BfReadByte(bf) == 0 && (strcmp(type, "scores", false) == 0))
207 g_IntermissionCalled = true;
210 new Float:fChatTime = GetConVarFloat(g_Cvar_Chattime);
212 GetConVarString(g_Cvar_Nextmap, map, sizeof(map));
214 if (!IsMapValid(map))
216 GetArrayString(g_MapList, g_MapPos, map, sizeof(map));
220 SetConVarFloat(g_Cvar_Chattime, 2.0);
223 CreateDataTimer(fChatTime - 1.0, Timer_ChangeMap, dp);
224 WritePackString(dp, map);
227 return Plugin_Handled;
230 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
235 ReadPackString(dp, map, sizeof(map));
237 InsertServerCommand("changelevel \"%s\"", map);
240 LogMessage("Nextmap changed map to \"%s\"", map);
247 new mapCount = GetArraySize(g_MapList);
248 decl String:mapName[32];
252 decl String:current[64];
253 GetCurrentMap(current, 64);
255 for (new i = 0; i < mapCount; i++)
257 GetArrayString(g_MapList, i, mapName, sizeof(mapName));
258 if (strcmp(current, mapName, false) == 0)
270 if (g_MapPos >= mapCount)
273 GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName));
274 SetConVarString(g_Cvar_Nextmap, mapName);