Fixed most of mapchooser.sp. May have issues with mp_winlimit on DoD. Timelimits may not function 100% in cstrike (Depends on something else, sorry)

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401458
This commit is contained in:
Michael McKoy 2007-09-22 17:44:18 +00:00
parent d27a768d97
commit dd076961bf

View File

@ -57,24 +57,16 @@ new Handle:g_OldMapList = INVALID_HANDLE;
new Handle:g_NextMapList = INVALID_HANDLE; new Handle:g_NextMapList = INVALID_HANDLE;
new Handle:g_VoteMenu = INVALID_HANDLE; new Handle:g_VoteMenu = INVALID_HANDLE;
new g_MapCount;
new g_GameType;
new bool:g_HasVoteStarted; new bool:g_HasVoteStarted;
new g_mapFileTime; new g_mapFileTime;
enum
{
GAME_HL2 = 0,
GAME_CSS,
GAME_DOD
}
public OnPluginStart() public OnPluginStart()
{ {
LoadTranslations("mapchooser.phrases"); LoadTranslations("mapchooser.phrases");
g_MapList = CreateArray(33); g_MapList = CreateArray(33);
g_OldMapList = CreateArray(33); g_OldMapList = CreateArray(33);
g_NextMapList = CreateArray(33);
g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies the time to start the vote when this much time remains.", _, true, 1.0); g_Cvar_StartTime = CreateConVar("sm_mapvote_start", "3.0", "Specifies the time to start the vote when this much time remains.", _, true, 1.0);
g_Cvar_ExtendTimeMax = CreateConVar("sm_extendmap_maxtime", "90", "Specifies the maximum amount of time a map can be extended"); g_Cvar_ExtendTimeMax = CreateConVar("sm_extendmap_maxtime", "90", "Specifies the maximum amount of time a map can be extended");
@ -87,20 +79,12 @@ public OnPluginStart()
decl String:FolderName[32]; decl String:FolderName[32];
GetGameFolderName(FolderName, sizeof(FolderName)); GetGameFolderName(FolderName, sizeof(FolderName));
if (strcmp(FolderName, "cstrike", false) == 0) g_Cvar_Winlimit = FindConVar("mp_winlimit");
{ g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
g_GameType = GAME_CSS;
g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
}
else if (strcmp(FolderName, "dod", false) == 0)
{
g_GameType = GAME_DOD;
}
if (g_GameType) if (g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE)
{ {
g_Cvar_Winlimit = FindConVar("mp_winlimit"); HookEvent("round_end", Event_RoundEnd);
HookEvent("team_score", Event_TeamScore);
} }
} }
@ -131,6 +115,7 @@ public OnMapEnd()
public OnMapTimeLeftChanged() public OnMapTimeLeftChanged()
{ {
SetupTimeleftTimer(); SetupTimeleftTimer();
LogMessage("[MC] Timeleft changed, resetting timer.");
} }
SetupTimeleftTimer() SetupTimeleftTimer()
@ -141,7 +126,7 @@ SetupTimeleftTimer()
new startTime = GetConVarInt(g_Cvar_StartTime); new startTime = GetConVarInt(g_Cvar_StartTime);
if (time - startTime < 0) if (time - startTime < 0)
{ {
InitiateVote(); InitiateVote();
} }
else else
{ {
@ -149,7 +134,7 @@ SetupTimeleftTimer()
{ {
KillTimer(g_VoteTimer); KillTimer(g_VoteTimer);
g_VoteTimer = INVALID_HANDLE; g_VoteTimer = INVALID_HANDLE;
} }
g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote, TIMER_FLAG_NO_MAPCHANGE); g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote, TIMER_FLAG_NO_MAPCHANGE);
} }
@ -158,11 +143,12 @@ SetupTimeleftTimer()
public Action:Timer_StartMapVote(Handle:timer) public Action:Timer_StartMapVote(Handle:timer)
{ {
if (!g_MapCount) if (!GetArraySize(g_MapList))
{ {
return Plugin_Stop; return Plugin_Stop;
} }
if (timer == g_RetryTimer) if (timer == g_RetryTimer)
{ {
g_RetryTimer = INVALID_HANDLE; g_RetryTimer = INVALID_HANDLE;
@ -177,32 +163,44 @@ public Action:Timer_StartMapVote(Handle:timer)
return Plugin_Stop; return Plugin_Stop;
} }
public Event_TeamScore(Handle:event, const String:name[], bool:dontBroadcast) public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{ {
if (!g_MapCount) if (!GetArraySize(g_MapList))
{ {
return; return;
} }
static Score[2]; new team = GetEventInt(event, "winner");
new Team = GetEventInt(event, "teamid"); if (team != 2 || team != 3)
Score[Team - 2] = GetEventInt(event, "score");
new winlimit = GetConVarInt(g_Cvar_Winlimit);
if (winlimit)
{ {
new Limit = winlimit - 2; return;
if (Score[0] > Limit || Score[1] > Limit) }
static score[2];
score[team - 2]++;
LogMessage("[MC] Team scored! %d - %d", score[0], score[1]);
if (g_Cvar_Winlimit != INVALID_HANDLE)
{
new winlimit = GetConVarInt(g_Cvar_Winlimit);
if (winlimit)
{ {
InitiateVote(); new Limit = winlimit - 2;
if (score[0] > Limit || score[1] > Limit)
{
InitiateVote();
}
} }
} }
else if (g_GameType == GAME_CSS)
if (g_Cvar_Maxrounds != INVALID_HANDLE)
{ {
new maxrounds = GetConVarInt(g_Cvar_Maxrounds); new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
if (maxrounds) if (maxrounds)
{ {
if ((Score[0] + Score[1]) > maxrounds - 2) if ((score[0] + score[1]) > maxrounds - 2)
{ {
InitiateVote(); InitiateVote();
} }
@ -228,35 +226,30 @@ InitiateVote()
g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL); g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL);
SetMenuTitle(g_VoteMenu, "Vote Nextmap"); SetMenuTitle(g_VoteMenu, "Vote Nextmap");
KvRewind(g_NextMapList);
KvGotoFirstSubKey(g_NextMapList);
decl String:map[32]; decl String:map[32];
do for (new i = 0; i < GetArraySize(g_NextMapList); i++)
{ {
KvGetSectionName(g_NextMapList, map, sizeof(map)); GetArrayString(g_NextMapList, i, map, sizeof(map));
AddMenuItem(g_VoteMenu, map, map); AddMenuItem(g_VoteMenu, map, map);
} }
while (KvGotoNextKey(g_NextMapList));
new bool:AllowExtend, time; new bool:allowExtend, time;
if (GetMapTimeLimit(time) && time > 0 && time < GetConVarInt(g_Cvar_ExtendTimeMax)) if (GetMapTimeLimit(time) && time > 0 && time < GetConVarInt(g_Cvar_ExtendTimeMax))
{ {
AllowExtend = true; allowExtend = true;
} }
if (g_GameType) if (g_Cvar_Winlimit != INVALID_HANDLE && GetConVarInt(g_Cvar_Winlimit) < GetConVarInt(g_Cvar_ExtendRoundMax))
{ {
// Yes, I could short circuit this above. But I find it cleaner to break allowExtend = true;
// it up into two if's
if (GetConVarInt(g_Cvar_Maxrounds) < GetConVarInt(g_Cvar_ExtendRoundMax)
|| GetConVarInt(g_Cvar_Winlimit) < GetConVarInt(g_Cvar_ExtendRoundMax))
{
AllowExtend = true;
}
} }
if (g_Cvar_Maxrounds != INVALID_HANDLE && GetConVarInt(g_Cvar_Maxrounds) < GetConVarInt(g_Cvar_ExtendRoundMax))
{
allowExtend = true;
}
if (AllowExtend) if (allowExtend)
{ {
AddMenuItem(g_VoteMenu, "##extend##", "Extend"); AddMenuItem(g_VoteMenu, "##extend##", "Extend");
} }
@ -338,22 +331,21 @@ public Handler_MapVoteMenu(Handle:menu, MenuAction:action, param1, param2)
} }
} }
if (g_GameType) if (g_Cvar_Winlimit != INVALID_HANDLE)
{ {
new roundstep = GetConVarInt(g_Cvar_ExtendRoundStep);
new winlimit = GetConVarInt(g_Cvar_Winlimit); new winlimit = GetConVarInt(g_Cvar_Winlimit);
if (winlimit < GetConVarInt(g_Cvar_ExtendRoundMax)) if (winlimit && winlimit < GetConVarInt(g_Cvar_ExtendRoundMax))
{ {
SetConVarInt(g_Cvar_Winlimit, winlimit + roundstep); SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
} }
}
if (g_GameType == GAME_CSS)
if (g_Cvar_Maxrounds != INVALID_HANDLE)
{
new maxrounds = GetConVarInt(g_Cvar_Maxrounds);
if (maxrounds && maxrounds < GetConVarInt(g_Cvar_ExtendRoundMax))
{ {
new maxrounds = GetConVarInt(g_Cvar_Maxrounds); SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
if (maxrounds < GetConVarInt(g_Cvar_ExtendRoundMax))
{
SetConVarInt(g_Cvar_Maxrounds, maxrounds + roundstep);
}
} }
} }
@ -382,42 +374,40 @@ SetNextMap(const String:map[])
RemoveFromArray(g_OldMapList, 0); RemoveFromArray(g_OldMapList, 0);
} }
PrintToChatAll("[SM] %t", "Nextmap Voting Finished"); PrintToChatAll("[SM] %t", "Nextmap Voting Finished", map);
LogMessage("Voting for next map has finished. Nextmap: %s.", map); LogMessage("Voting for next map has finished. Nextmap: %s.", map);
} }
CreateNextVote() CreateNextVote()
{ {
if(IsValidHandle(g_NextMapList)) if(g_NextMapList != INVALID_HANDLE)
{ {
CloseHandle(g_NextMapList); ClearArray(g_NextMapList);
} }
g_NextMapList = CreateKeyValues("MapChooser"); decl String:map[32];
new limit = (MAX_MAPS_SELECTION < GetArraySize(g_MapList) ? MAX_MAPS_SELECTION : GetArraySize(g_MapList));
new bool:oldMaps = false; new bool:oldMaps = false;
if (g_MapCount > GetConVarInt(g_Cvar_ExcludeMaps)) if (limit > GetConVarInt(g_Cvar_ExcludeMaps))
{ {
limit -= GetArraySize(g_OldMapList);
oldMaps = true; oldMaps = true;
} }
decl String:map[32]; for (new i = 0; i < limit; i++)
for (new i = 0, b, count; i < g_MapCount; i++)
{ {
b = GetRandomInt(0, g_MapCount - 1); new b = GetRandomInt(0, limit - 1);
GetArrayString(g_MapList, b, map, sizeof(map)); GetArrayString(g_MapList, b, map, sizeof(map));
if (!IsMapSelected(map) && !(oldMaps && IsMapOld(map))) while (IsStringInArray(g_NextMapList, map) || (oldMaps && IsStringInArray(g_OldMapList, map)))
{ {
b = GetRandomInt(0, limit - 1);
KvJumpToKey(g_NextMapList, map, true); GetArrayString(g_MapList, b, map, sizeof(map));
count++;
}
if (count == MAX_MAPS_SELECTION || count >= 9)
{
break;
} }
LogMessage("[MC] Map was good, %s pushed on array.", map);
PushArrayString(g_NextMapList, map);
} }
} }
@ -440,7 +430,6 @@ LoadMaps()
{ {
LogError("Unable to locate g_Cvar_Mapfile or mapcyclefile, no maps loaded."); LogError("Unable to locate g_Cvar_Mapfile or mapcyclefile, no maps loaded.");
g_MapCount = 0;
if (g_MapList != INVALID_HANDLE) if (g_MapList != INVALID_HANDLE)
{ {
ClearArray(g_MapList); ClearArray(g_MapList);
@ -454,19 +443,18 @@ LoadMaps()
new fileTime = GetFileTime(mapPath, FileTime_LastChange); new fileTime = GetFileTime(mapPath, FileTime_LastChange);
if (g_mapFileTime == fileTime) if (g_mapFileTime == fileTime)
{ {
return g_MapCount; return GetArraySize(g_MapList);
} }
g_mapFileTime = fileTime; g_mapFileTime = fileTime;
// Reset the array // Reset the array
g_MapCount = 0;
if (g_MapList != INVALID_HANDLE) if (g_MapList != INVALID_HANDLE)
{ {
ClearArray(g_MapList); ClearArray(g_MapList);
} }
PrintToServer("[SM] Loading mapchooser map file [%s]", mapPath); LogMessage("[SM] Loading mapchooser map file [%s]", mapPath);
decl String:currentMap[32]; decl String:currentMap[32];
GetCurrentMap(currentMap, sizeof(currentMap)); GetCurrentMap(currentMap, sizeof(currentMap));
@ -495,36 +483,13 @@ LoadMaps()
} }
PushArrayString(g_MapList, buffer); PushArrayString(g_MapList, buffer);
g_MapCount++;
} }
CloseHandle(file); CloseHandle(file);
return g_MapCount; return GetArraySize(g_MapList);
} }
stock bool:IsValidCvarChar(c) stock bool:IsValidCvarChar(c)
{ {
return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c)); return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c));
}
stock bool:IsMapSelected(const String:Map[])
{
KvRewind(g_NextMapList);
return KvJumpToKey(g_NextMapList, Map);
}
stock bool:IsMapOld(const String:map[])
{
decl String:oldMap[64];
for (new i = 0; i < GetArraySize(g_OldMapList); i++)
{
GetArrayString(g_OldMapList, i, oldMap, sizeof(oldMap));
if(strcmp(map, oldMap, false) == 0)
{
return false;
}
}
return true;
} }