Updated license headers on virtually all files with extremely minor changes in the name of some sort of strange consistency.
All plugin and include file headers also have been changed to say about GPL3 instead of GPL2.
(This day shall henceforth be known as the Eighty Column Massacre of '07)
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;
52 new Handle:g_Cvar_Mapcycle;
55 new Handle:g_MapList = INVALID_HANDLE;
58 new bool:g_INS = false;
61 public OnPluginStart()
63 LoadTranslations("nextmap.phrases");
65 g_VGUIMenu = GetUserMessageId("VGUIMenu");
66 if (g_VGUIMenu == INVALID_MESSAGE_ID)
68 LogMessage("FATAL: Cannot find VGUIMenu user message id. Nextmap not loaded.");
72 g_Cvar_Chattime = FindConVar("mp_chattime");
73 g_Cvar_Mapcycle = FindConVar("mapcyclefile");
75 g_MapList = CreateArray(32);
77 decl String:mapCycle[64];
78 GetConVarString(g_Cvar_Mapcycle, mapCycle, 64);
79 if (LoadMaps(mapCycle) == 0)
81 LogMessage("FATAL: Cannot load map cycle. Nextmap not loaded.");
85 HookUserMessage(g_VGUIMenu, UserMsg_VGUIMenu);
86 HookConVarChange(g_Cvar_Mapcycle, ConVarChange_Mapcyclefile);
88 g_Cvar_Nextmap = CreateConVar("sm_nextmap", "", "Sets the Next Map", FCVAR_NOTIFY);
90 RegConsoleCmd("say", Command_Say);
91 RegConsoleCmd("say_team", Command_Say);
94 decl String:modname[64];
95 GetGameFolderName(modname, sizeof(modname));
97 if (strcmp(modname, "ins") == 0)
99 RegConsoleCmd("say2", Command_SayChat);
104 RegConsoleCmd("listmaps", Command_List);
106 /* Set to the current map so OnMapStart() will know what to do */
107 decl String:currentMap[64];
108 GetCurrentMap(currentMap, 64);
109 SetConVarString(g_Cvar_Nextmap, currentMap);
114 decl String:lastMap[64], String:currentMap[64];
115 GetConVarString(g_Cvar_Nextmap, lastMap, 64);
116 GetCurrentMap(currentMap, 64);
118 // 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
119 // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map
120 // not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret
121 if (strcmp(lastMap, currentMap) == 0)
129 g_IntermissionCalled = false;
132 public ConVarChange_Mapcyclefile(Handle:convar, const String:oldValue[], const String:newValue[])
134 if (strcmp(oldValue, newValue, false) != 0)
140 public Action:Command_Say(client, args)
142 decl String:text[192];
143 GetCmdArgString(text, sizeof(text));
146 if (text[strlen(text)-1] == '"')
148 text[strlen(text)-1] = '\0';
159 decl String:message[8];
160 BreakString(text[startidx], message, sizeof(message));
162 if (strcmp(message, "nextmap", false) == 0)
165 GetConVarString(g_Cvar_Nextmap, map, sizeof(map));
167 PrintToChatAll("%t", "Next Map", map);
170 return Plugin_Continue;
173 public Action:UserMsg_VGUIMenu(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
175 if (g_IntermissionCalled)
177 return Plugin_Handled;
180 decl String:type[15];
181 BfReadString(bf, type, sizeof(type));
183 if (BfReadByte(bf) == 1 && BfReadByte(bf) == 0 && (strcmp(type, "scores", false) == 0))
185 g_IntermissionCalled = true;
188 new Float:fChatTime = GetConVarFloat(g_Cvar_Chattime);
190 GetConVarString(g_Cvar_Nextmap, map, sizeof(map));
193 SetConVarFloat(g_Cvar_Chattime, 2.0);
196 CreateDataTimer(fChatTime - 1.0, Timer_ChangeMap, dp);
197 WritePackString(dp, map);
200 return Plugin_Handled;
203 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
208 ReadPackString(dp, map, sizeof(map));
210 InsertServerCommand("changelevel \"%s\"", map);
213 LogMessage("Nextmap changed map to \"%s\"", map);
218 public Action:Command_List(client, args)
220 PrintToConsole(client, "Map Cycle:");
222 new mapCount = GetArraySize(g_MapList);
223 decl String:mapName[32];
224 for (new i = 0; i < mapCount; i++)
226 GetArrayString(g_MapList, i, mapName, sizeof(mapName));
227 PrintToConsole(client, "%s", mapName);
230 return Plugin_Handled;
233 LoadMaps(const String:path[])
235 if (!FileExists(path))
240 new Handle:file = OpenFile(path, "r");
242 if (file == INVALID_HANDLE)
244 LogError("[SM] Could not open file: %s", path);
248 ClearArray(g_MapList);
251 decl String:buffer[255];
252 while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
255 if (buffer[0] == '\0' || buffer[0] == ';')
260 if (IsMapValid(buffer))
262 PushArrayString(g_MapList, buffer);
268 return GetArraySize(g_MapList);
273 new mapCount = GetArraySize(g_MapList);
274 decl String:mapName[32];
278 decl String:current[64];
279 GetCurrentMap(current, 64);
282 for (new i = 0; i < mapCount; i++)
284 GetArrayString(g_MapList, i, mapName, sizeof(mapName));
285 if (strcmp(current, mapName, false) == 0)
297 if (g_MapPos >= mapCount)
300 GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName));
301 SetConVarString(g_Cvar_Nextmap, mapName);