extensions now use the repository build number intsead of their local commit number
3 * =============================================================================
4 * SourceMod Random Map Cycle Plugin
5 * Randomly picks a map from the mapcycle.
7 * SourceMod (C)2004-2008 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>.
37 public Plugin:myinfo =
40 author = "AlliedModders LLC",
41 description = "Randomly chooses the next map.",
42 version = SOURCEMOD_VERSION,
43 url = "http://www.sourcemod.net/"
46 new Handle:g_Cvar_Nextmap = INVALID_HANDLE;
47 new Handle:g_Cvar_ExcludeMaps = INVALID_HANDLE;
49 new Handle:g_MapList = INVALID_HANDLE;
50 new Handle:g_OldMapList = INVALID_HANDLE;
51 new g_mapListSerial = -1;
53 public OnPluginStart()
55 new arraySize = ByteCountToCells(33);
56 g_MapList = CreateArray(arraySize);
57 g_OldMapList = CreateArray(arraySize);
59 g_Cvar_ExcludeMaps = CreateConVar("sm_randomcycle_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
61 AutoExecConfig(true, "randomcycle");
64 public OnConfigsExecuted()
66 g_Cvar_Nextmap = FindConVar("sm_nextmap");
68 if (g_Cvar_Nextmap == INVALID_HANDLE)
70 LogError("FATAL: Cannot find sm_nextmap cvar. RandomCycle not loaded.");
71 SetFailState("sm_nextmap not found");
74 if (ReadMapList(g_MapList,
77 MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
80 if (g_mapListSerial == -1)
82 LogError("Unable to create a valid map list.");
86 CreateTimer(5.0, Timer_RandomizeNextmap); // Small delay to give Nextmap time to complete OnMapStart()
89 public Action:Timer_RandomizeNextmap(Handle:timer)
93 new bool:oldMaps = false;
94 if (GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(g_MapList) > GetConVarInt(g_Cvar_ExcludeMaps))
99 new b = GetRandomInt(0, GetArraySize(g_MapList) - 1);
100 GetArrayString(g_MapList, b, map, sizeof(map));
102 while (oldMaps && FindStringInArray(g_OldMapList, map) != -1)
104 b = GetRandomInt(0, GetArraySize(g_MapList) - 1);
105 GetArrayString(g_MapList, b, map, sizeof(map));
108 SetConVarString(g_Cvar_Nextmap, map);
109 PushArrayString(g_OldMapList, map);
111 if (GetArraySize(g_OldMapList) > GetConVarInt(g_Cvar_ExcludeMaps))
113 RemoveFromArray(g_OldMapList, 0);
116 LogMessage("RandomCycle has chosen %s for the nextmap.", map);