1.1 --- a/plugins/nextmap.sp Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,213 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod Nextmap Plugin
1.8 - * Adds sm_nextmap cvar for changing map and nextmap chat trigger.
1.9 - *
1.10 - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.11 - * =============================================================================
1.12 - *
1.13 - * This program is free software; you can redistribute it and/or modify it under
1.14 - * the terms of the GNU General Public License, version 3.0, as published by the
1.15 - * Free Software Foundation.
1.16 - *
1.17 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.18 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.19 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.20 - * details.
1.21 - *
1.22 - * You should have received a copy of the GNU General Public License along with
1.23 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.24 - *
1.25 - * As a special exception, AlliedModders LLC gives you permission to link the
1.26 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.27 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.28 - * by the Valve Corporation. You must obey the GNU General Public License in
1.29 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.30 - * this exception to all derivative works. AlliedModders LLC defines further
1.31 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.32 - * or <http://www.sourcemod.net/license.php>.
1.33 - *
1.34 - * Version: $Id$
1.35 - */
1.36 -
1.37 -#pragma semicolon 1
1.38 -
1.39 -#include <sourcemod>
1.40 -#include "include/nextmap.inc"
1.41 -
1.42 -
1.43 -public Plugin:myinfo =
1.44 -{
1.45 - name = "Nextmap",
1.46 - author = "AlliedModders LLC",
1.47 - description = "Provides nextmap and sm_nextmap",
1.48 - version = SOURCEMOD_VERSION,
1.49 - url = "http://www.sourcemod.net/"
1.50 -};
1.51 -
1.52 -
1.53 -new g_MapPos = -1;
1.54 -new Handle:g_MapList = INVALID_HANDLE;
1.55 -new g_MapListSerial = -1;
1.56 -
1.57 -public OnPluginStart()
1.58 -{
1.59 - LoadTranslations("common.phrases");
1.60 - LoadTranslations("nextmap.phrases");
1.61 -
1.62 - g_MapList = CreateArray(32);
1.63 -
1.64 - RegConsoleCmd("say", Command_Say);
1.65 - RegConsoleCmd("say_team", Command_Say);
1.66 -
1.67 - RegConsoleCmd("nextmap", Command_Nextmap);
1.68 -
1.69 - RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
1.70 - RegConsoleCmd("listmaps", Command_List);
1.71 -
1.72 - // Set to the current map so OnMapStart() will know what to do
1.73 - decl String:currentMap[64];
1.74 - GetCurrentMap(currentMap, 64);
1.75 - SetNextMap(currentMap);
1.76 -}
1.77 -
1.78 -public OnConfigsExecuted()
1.79 -{
1.80 - decl String:lastMap[64], String:currentMap[64];
1.81 - GetNextMap(lastMap, sizeof(lastMap));
1.82 - GetCurrentMap(currentMap, 64);
1.83 -
1.84 - // 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
1.85 - // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map
1.86 - // not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret
1.87 - if (strcmp(lastMap, currentMap) == 0)
1.88 - {
1.89 - FindAndSetNextMap();
1.90 - }
1.91 -}
1.92 -
1.93 -public Action:Command_Say(client, args)
1.94 -{
1.95 - decl String:text[192];
1.96 - if (GetCmdArgString(text, sizeof(text)) < 1)
1.97 - {
1.98 - return Plugin_Continue;
1.99 - }
1.100 -
1.101 - new startidx;
1.102 - if (text[strlen(text)-1] == '"')
1.103 - {
1.104 - text[strlen(text)-1] = '\0';
1.105 - startidx = 1;
1.106 - }
1.107 -
1.108 - decl String:message[8];
1.109 - BreakString(text[startidx], message, sizeof(message));
1.110 -
1.111 - if (strcmp(message, "nextmap", false) == 0)
1.112 - {
1.113 - decl String:map[32];
1.114 - GetNextMap(map, sizeof(map));
1.115 -
1.116 - PrintToChat(client, "[SM] %t", "Next Map", map);
1.117 - }
1.118 -
1.119 - return Plugin_Continue;
1.120 -}
1.121 -
1.122 -public Action:Command_SetNextmap(client, args)
1.123 -{
1.124 - if (args < 1)
1.125 - {
1.126 - ReplyToCommand(client, "[SM] Usage: sm_setnextmap <map>");
1.127 - return Plugin_Handled;
1.128 - }
1.129 -
1.130 - decl String:map[64];
1.131 - GetCmdArg(1, map, sizeof(map));
1.132 -
1.133 - if (!IsMapValid(map))
1.134 - {
1.135 - ReplyToCommand(client, "[SM] %t", "Map was not found", map);
1.136 - return Plugin_Handled;
1.137 - }
1.138 -
1.139 - ShowActivity(client, "%t", "Changed Next Map", map);
1.140 - LogMessage("\"%L\" changed nextmap to \"%s\"", client, map);
1.141 -
1.142 - SetNextMap(map);
1.143 -
1.144 - return Plugin_Handled;
1.145 -}
1.146 -
1.147 -public Action:Command_List(client, args)
1.148 -{
1.149 - PrintToConsole(client, "Map Cycle:");
1.150 -
1.151 - new mapCount = GetArraySize(g_MapList);
1.152 - decl String:mapName[32];
1.153 - for (new i = 0; i < mapCount; i++)
1.154 - {
1.155 - GetArrayString(g_MapList, i, mapName, sizeof(mapName));
1.156 - PrintToConsole(client, "%s", mapName);
1.157 - }
1.158 -
1.159 - return Plugin_Handled;
1.160 -}
1.161 -
1.162 -public Action:Command_Nextmap(client, args)
1.163 -{
1.164 - decl String:map[64];
1.165 -
1.166 - GetNextMap(map, sizeof(map));
1.167 -
1.168 - ReplyToCommand(client, "[SM] %t", "Next Map", map);
1.169 -
1.170 - return Plugin_Handled;
1.171 -}
1.172 -
1.173 -FindAndSetNextMap()
1.174 -{
1.175 - if (ReadMapList(g_MapList,
1.176 - g_MapListSerial,
1.177 - "mapcyclefile",
1.178 - MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT)
1.179 - == INVALID_HANDLE)
1.180 - {
1.181 - if (g_MapListSerial == -1)
1.182 - {
1.183 - LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
1.184 - SetFailState("Mapcycle Not Found");
1.185 - }
1.186 - }
1.187 -
1.188 - new mapCount = GetArraySize(g_MapList);
1.189 - decl String:mapName[32];
1.190 -
1.191 - if (g_MapPos == -1)
1.192 - {
1.193 - decl String:current[64];
1.194 - GetCurrentMap(current, 64);
1.195 -
1.196 - for (new i = 0; i < mapCount; i++)
1.197 - {
1.198 - GetArrayString(g_MapList, i, mapName, sizeof(mapName));
1.199 - if (strcmp(current, mapName, false) == 0)
1.200 - {
1.201 - g_MapPos = i;
1.202 - break;
1.203 - }
1.204 - }
1.205 -
1.206 - if (g_MapPos == -1)
1.207 - g_MapPos = 0;
1.208 - }
1.209 -
1.210 - g_MapPos++;
1.211 - if (g_MapPos >= mapCount)
1.212 - g_MapPos = 0;
1.213 -
1.214 - GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName));
1.215 - SetNextMap(mapName);
1.216 -}