ferret99gt@1175: /**
ds@1330: * vim: set ts=4 :
ds@1330: * =============================================================================
ds@1330: * SourceMod Nextmap Plugin
ds@1330: * Adds sm_nextmap cvar for changing map and nextmap chat trigger.
ds@1330: *
ds@1947: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
ds@1330: * =============================================================================
ferret99gt@1175: *
ds@1330: * This program is free software; you can redistribute it and/or modify it under
ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330: * Free Software Foundation.
ds@1330: *
ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1330: * details.
ferret99gt@1175: *
ds@1330: * You should have received a copy of the GNU General Public License along with
ds@1330: * this program. If not, see .
ds@1330: *
ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1330: * this exception to all derivative works. AlliedModders LLC defines further
ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330: * or .
ferret99gt@1175: *
ferret99gt@1175: * Version: $Id$
ferret99gt@1175: */
ds@1330:
ds@1330: #pragma semicolon 1
ds@1330:
ferret99gt@1175: #include
pred@2077: #include "include/nextmap.inc"
pred@2077:
ferret99gt@1175: public Plugin:myinfo =
ferret99gt@1175: {
ferret99gt@1175: name = "Nextmap",
ferret99gt@1175: author = "AlliedModders LLC",
ferret99gt@1175: description = "Provides nextmap and sm_nextmap",
ferret99gt@1175: version = SOURCEMOD_VERSION,
ferret99gt@1175: url = "http://www.sourcemod.net/"
ferret99gt@1175: };
ferret99gt@1175:
ferret99gt@1175:
ferret99gt@1175: new g_MapPos = -1;
ferret99gt@1175: new Handle:g_MapList = INVALID_HANDLE;
dvander@1744: new g_MapListSerial = -1;
pred@2203:
pred@2203: new g_CurrentMapStartTime;
fyrenmoo@2676:
fyrenmoo@2676: public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
ferret99gt@1175: {
fyrenmoo@2692: decl String:game[128];
fyrenmoo@2692: GetGameFolderName(game, sizeof(game));
rbutler14@2470:
fyrenmoo@2692: if (StrEqual(game, "left4dead", false)
fyrenmoo@2692: || StrEqual(game, "dystopia", false)
fyrenmoo@2692: || StrEqual(game, "synergy", false))
fyrenmoo@2676: {
fyrenmoo@2676: strcopy(error, err_max, "Nextmap is incompatible with this game");
fyrenmoo@2676: return APLRes_SilentFailure;
fyrenmoo@2676: }
fyrenmoo@2676:
fyrenmoo@2676: return APLRes_Success;
fyrenmoo@2676: }
fyrenmoo@2676:
fyrenmoo@2676:
ferret99gt@1175: public OnPluginStart()
ferret99gt@1175: {
rbutler14@2470:
ferret99gt@1366: LoadTranslations("common.phrases");
ferret99gt@1187: LoadTranslations("nextmap.phrases");
ferret99gt@1175:
ferret99gt@1175: g_MapList = CreateArray(32);
ferret99gt@1439:
pred@2203: RegAdminCmd("sm_maphistory", Command_MapHistory, ADMFLAG_CHANGEMAP, "Shows the most recent maps played");
ferret99gt@1175: RegConsoleCmd("listmaps", Command_List);
ferret99gt@1366:
ferret99gt@1366: // Set to the current map so OnMapStart() will know what to do
ferret99gt@1175: decl String:currentMap[64];
ferret99gt@1175: GetCurrentMap(currentMap, 64);
pred@2077: SetNextMap(currentMap);
ds@1952: }
pred@2203:
pred@2203: public OnMapStart()
pred@2203: {
pred@2203: g_CurrentMapStartTime = GetTime();
ferret99gt@1175: }
ferret99gt@1175:
dvander@1744: public OnConfigsExecuted()
ferret99gt@1175: {
ferret99gt@1175: decl String:lastMap[64], String:currentMap[64];
pred@2077: GetNextMap(lastMap, sizeof(lastMap));
ferret99gt@1175: GetCurrentMap(currentMap, 64);
ferret99gt@1175:
ferret99gt@1175: // 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
ferret99gt@1175: // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map
ferret99gt@1175: // not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret
ferret99gt@1175: if (strcmp(lastMap, currentMap) == 0)
ferret99gt@1175: {
ferret99gt@1175: FindAndSetNextMap();
ferret99gt@1175: }
ferret99gt@1175: }
ferret99gt@1366:
ferret99gt@1366: public Action:Command_List(client, args)
ferret99gt@1366: {
ferret99gt@1366: PrintToConsole(client, "Map Cycle:");
ferret99gt@1366:
ferret99gt@1366: new mapCount = GetArraySize(g_MapList);
ferret99gt@1366: decl String:mapName[32];
ferret99gt@1366: for (new i = 0; i < mapCount; i++)
ferret99gt@1366: {
ferret99gt@1366: GetArrayString(g_MapList, i, mapName, sizeof(mapName));
ferret99gt@1366: PrintToConsole(client, "%s", mapName);
ferret99gt@1366: }
ferret99gt@1366:
ferret99gt@1366: return Plugin_Handled;
ferret99gt@1366: }
pred@2206:
ferret99gt@1175: FindAndSetNextMap()
ferret99gt@1175: {
dvander@1783: if (ReadMapList(g_MapList,
dvander@1783: g_MapListSerial,
dvander@1783: "mapcyclefile",
dvander@1783: MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT)
dvander@1783: == INVALID_HANDLE)
dvander@1783: {
dvander@1783: if (g_MapListSerial == -1)
dvander@1783: {
dvander@1783: LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
dvander@1783: SetFailState("Mapcycle Not Found");
dvander@1783: }
dvander@1783: }
dvander@1783:
ferret99gt@1175: new mapCount = GetArraySize(g_MapList);
ferret99gt@1175: decl String:mapName[32];
ferret99gt@1175:
ferret99gt@1175: if (g_MapPos == -1)
ferret99gt@1175: {
ferret99gt@1175: decl String:current[64];
ferret99gt@1175: GetCurrentMap(current, 64);
ferret99gt@1175:
ferret99gt@1175: for (new i = 0; i < mapCount; i++)
ferret99gt@1175: {
ferret99gt@1175: GetArrayString(g_MapList, i, mapName, sizeof(mapName));
ferret99gt@1175: if (strcmp(current, mapName, false) == 0)
ferret99gt@1175: {
ferret99gt@1175: g_MapPos = i;
ferret99gt@1175: break;
ferret99gt@1175: }
ferret99gt@1175: }
ferret99gt@1175:
ferret99gt@1175: if (g_MapPos == -1)
ferret99gt@1175: g_MapPos = 0;
ferret99gt@1175: }
ferret99gt@1175:
ferret99gt@1175: g_MapPos++;
ferret99gt@1175: if (g_MapPos >= mapCount)
ferret99gt@1175: g_MapPos = 0;
ferret99gt@1175:
ferret99gt@1175: GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName));
pred@2077: SetNextMap(mapName);
dvander@1422: }
pred@2203:
pred@2203: public Action:Command_MapHistory(client, args)
pred@2203: {
pred@2203: new mapCount = GetMapHistorySize();
pred@2203:
pred@2203: decl String:mapName[32];
pred@2203: decl String:changeReason[100];
pred@2203: decl String:timeString[100];
pred@2203: decl String:playedTime[100];
pred@2203: new startTime;
pred@2203:
pred@2203: new lastMapStartTime = g_CurrentMapStartTime;
pred@2203:
pred@2203: PrintToConsole(client, "Map History:\n");
pred@2203: PrintToConsole(client, "Map : Started : Played Time : Reason for ending");
pred@2203:
pred@2203: GetCurrentMap(mapName, sizeof(mapName));
pred@2203: PrintToConsole(client, "%02i. %s (Current Map)", 0, mapName);
pred@2203:
pred@2203: for (new i=0; i 0)
pred@2203: {
pred@2215: return Format(buffer, maxlen, "%id %ih %im", days, hours, (seconds >= 30) ? minutes+1 : minutes);
pred@2203: }
pred@2203: else if (hours > 0)
pred@2203: {
pred@2215: return Format(buffer, maxlen, "%ih %im", hours, (seconds >= 30) ? minutes+1 : minutes);
pred@2203: }
pred@2203: else if (minutes > 0)
pred@2203: {
pred@2215: return Format(buffer, maxlen, "%im", (seconds >= 30) ? minutes+1 : minutes);
pred@2203: }
pred@2203: else
pred@2203: {
pred@2215: return Format(buffer, maxlen, "%is", seconds);
pred@2203: }
pred@2215: }