2008-03-30 09:00:22 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Random Map Cycle Plugin
|
|
|
|
* Randomly picks a map from the mapcycle.
|
|
|
|
*
|
2021-03-14 10:02:42 +01:00
|
|
|
* SourceMod (C)2004-2021 AlliedModders LLC. All rights reserved.
|
2008-03-30 09:00:22 +02:00
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma semicolon 1
|
|
|
|
#include <sourcemod>
|
|
|
|
|
2014-12-16 20:16:06 +01:00
|
|
|
#pragma newdecls required
|
|
|
|
|
|
|
|
public Plugin myinfo =
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
name = "RandomCycle",
|
|
|
|
author = "AlliedModders LLC",
|
|
|
|
description = "Randomly chooses the next map.",
|
|
|
|
version = SOURCEMOD_VERSION,
|
|
|
|
url = "http://www.sourcemod.net/"
|
|
|
|
};
|
|
|
|
|
2014-11-10 01:10:31 +01:00
|
|
|
ConVar g_Cvar_ExcludeMaps;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-12-16 20:16:06 +01:00
|
|
|
ArrayList g_MapList = null;
|
|
|
|
ArrayList g_OldMapList = null;
|
|
|
|
int g_mapListSerial = -1;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-12-16 20:16:06 +01:00
|
|
|
public void OnPluginStart()
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-12-16 20:16:06 +01:00
|
|
|
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
|
|
|
|
g_MapList = new ArrayList(arraySize);
|
|
|
|
g_OldMapList = new ArrayList(arraySize);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
g_Cvar_ExcludeMaps = CreateConVar("sm_randomcycle_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0);
|
|
|
|
|
|
|
|
AutoExecConfig(true, "randomcycle");
|
|
|
|
}
|
|
|
|
|
2014-12-16 20:16:06 +01:00
|
|
|
public void OnConfigsExecuted()
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (ReadMapList(g_MapList,
|
|
|
|
g_mapListSerial,
|
|
|
|
"randomcycle",
|
|
|
|
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER)
|
2014-11-16 01:30:45 +01:00
|
|
|
== null)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (g_mapListSerial == -1)
|
|
|
|
{
|
|
|
|
LogError("Unable to create a valid map list.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-14 10:02:42 +01:00
|
|
|
CreateTimer(5.0, Timer_RandomizeNextmap, _, TIMER_FLAG_NO_MAPCHANGE); // Small delay to give Nextmap time to complete OnMapStart()
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2014-12-16 20:16:06 +01:00
|
|
|
public Action Timer_RandomizeNextmap(Handle timer)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-12-16 20:16:06 +01:00
|
|
|
char map[PLATFORM_MAX_PATH];
|
2015-09-14 17:21:26 +02:00
|
|
|
char resolvedMap[PLATFORM_MAX_PATH];
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-12-16 20:16:06 +01:00
|
|
|
bool oldMaps = false;
|
|
|
|
if (g_Cvar_ExcludeMaps.IntValue && g_MapList.Length > g_Cvar_ExcludeMaps.IntValue)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
oldMaps = true;
|
|
|
|
}
|
|
|
|
|
2015-09-14 17:21:26 +02:00
|
|
|
do
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2015-09-14 17:21:26 +02:00
|
|
|
int b = GetRandomInt(0, g_MapList.Length - 1);
|
2014-12-16 20:16:06 +01:00
|
|
|
g_MapList.GetString(b, map, sizeof(map));
|
2015-09-14 17:21:26 +02:00
|
|
|
FindMap(map, resolvedMap, sizeof(resolvedMap));
|
|
|
|
} while (oldMaps && g_OldMapList.FindString(resolvedMap) != -1);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2015-09-14 17:21:26 +02:00
|
|
|
g_OldMapList.PushString(resolvedMap);
|
2008-09-21 04:20:01 +02:00
|
|
|
SetNextMap(map);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-12-16 20:16:06 +01:00
|
|
|
if (g_OldMapList.Length > g_Cvar_ExcludeMaps.IntValue)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-12-16 20:16:06 +01:00
|
|
|
g_OldMapList.Erase(0);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2011-03-21 00:37:25 +01:00
|
|
|
LogAction(-1, -1, "RandomCycle has chosen %s for the nextmap.", map);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
return Plugin_Stop;
|
2014-11-10 01:10:31 +01:00
|
|
|
}
|