1.1 --- a/plugins/randomcycle.sp Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,112 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod Random Map Cycle Plugin
1.8 - * Randomly picks a map from the mapcycle.
1.9 - *
1.10 - * SourceMod (C)2004-2007 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 -#include <sourcemod>
1.39 -
1.40 -public Plugin:myinfo =
1.41 -{
1.42 - name = "RandomCycle",
1.43 - author = "AlliedModders LLC",
1.44 - description = "Randomly chooses the next map.",
1.45 - version = SOURCEMOD_VERSION,
1.46 - url = "http://www.sourcemod.net/"
1.47 -};
1.48 -
1.49 -new Handle:g_Cvar_Nextmap = INVALID_HANDLE;
1.50 -new Handle:g_Cvar_Mapfile = INVALID_HANDLE;
1.51 -new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE;
1.52 -
1.53 -new Handle:g_MapList = INVALID_HANDLE;
1.54 -new Handle:g_OldMapList = INVALID_HANDLE;
1.55 -new g_mapFileTime;
1.56 -
1.57 -public OnPluginStart()
1.58 -{
1.59 - new arraySize = ByteCountToCells(33);
1.60 - g_MapList = CreateArray(arraySize);
1.61 - g_OldMapList = CreateArray(arraySize);
1.62 -
1.63 - g_Cvar_Mapfile = CreateConVar("sm_randomcycle_file", "configs/maps.ini", "Map file to use. (Def sourcemod/configs/maps.ini)");
1.64 - g_Cvar_ExcludeMaps = CreateConVar("sm_randomcycle_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
1.65 -
1.66 - AutoExecConfig(true, "randomcycle");
1.67 -}
1.68 -
1.69 -public OnConfigsExecuted()
1.70 -{
1.71 - g_Cvar_Nextmap = FindConVar("sm_nextmap");
1.72 -
1.73 - if (g_Cvar_Nextmap == INVALID_HANDLE)
1.74 - {
1.75 - LogError("FATAL: Cannot find sm_nextmap cvar. RandomCycle not loaded.");
1.76 - SetFailState("sm_nextmap not found");
1.77 - }
1.78 -
1.79 - if (LoadMaps(g_MapList, g_mapFileTime, g_Cvar_Mapfile))
1.80 - {
1.81 - CreateTimer(5.0, Timer_RandomizeNextmap); // Small delay to give Nextmap time to complete OnMapStart()
1.82 - }
1.83 -}
1.84 -
1.85 -public Action:Timer_RandomizeNextmap(Handle:timer)
1.86 -{
1.87 - decl String:map[32];
1.88 -
1.89 - new bool:oldMaps = false;
1.90 - if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(g_MapList) > GetConVarInt(g_Cvar_ExcludeMaps))
1.91 - {
1.92 - oldMaps = true;
1.93 - }
1.94 -
1.95 - new b = GetRandomInt(0, GetArraySize(g_MapList) - 1);
1.96 - GetArrayString(g_MapList, b, map, sizeof(map));
1.97 -
1.98 - while (oldMaps && FindStringInArray(g_OldMapList, map) != -1)
1.99 - {
1.100 - b = GetRandomInt(0, GetArraySize(g_MapList) - 1);
1.101 - GetArrayString(g_MapList, b, map, sizeof(map));
1.102 - }
1.103 -
1.104 - SetConVarString(g_Cvar_Nextmap, map);
1.105 - PushArrayString(g_OldMapList, map);
1.106 -
1.107 - if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
1.108 - {
1.109 - RemoveFromArray(g_OldMapList, 0);
1.110 - }
1.111 -
1.112 - LogMessage("RandomCycle has chosen %s for the nextmap.", map);
1.113 -
1.114 - return Plugin_Stop;
1.115 -}
1.116 \ No newline at end of file