1.1 --- a/plugins/mapchooser.sp Thu Oct 18 01:08:48 2007 +0000
1.2 +++ b/plugins/mapchooser.sp Thu Oct 18 01:16:42 2007 +0000
1.3 @@ -71,8 +71,8 @@
1.4 new Handle:g_MapList = INVALID_HANDLE;
1.5 new Handle:g_OldMapList = INVALID_HANDLE;
1.6 new Handle:g_NextMapList = INVALID_HANDLE;
1.7 +new Handle:g_TeamScores = INVALID_HANDLE;
1.8 new Handle:g_VoteMenu = INVALID_HANDLE;
1.9 -new Handle:g_TeamScores = INVALID_HANDLE;
1.10
1.11 new bool:g_HasVoteStarted;
1.12 new g_mapFileTime;
1.13 @@ -122,7 +122,7 @@
1.14 AutoExecConfig(true, "mapchooser");
1.15 }
1.16
1.17 -public OnMapStart()
1.18 +public OnConfigsExecuted()
1.19 {
1.20 g_Cvar_Nextmap = FindConVar("sm_nextmap");
1.21
1.22 @@ -132,7 +132,7 @@
1.23 SetFailState("sm_nextmap not found");
1.24 }
1.25
1.26 - if (LoadMaps())
1.27 + if (LoadMaps(g_MapList, g_mapFileTime, g_Cvar_Mapfile))
1.28 {
1.29 CreateNextVote();
1.30 SetupTimeleftTimer();
1.31 @@ -143,8 +143,18 @@
1.32 public OnMapEnd()
1.33 {
1.34 g_HasVoteStarted = false;
1.35 - g_RetryTimer = INVALID_HANDLE;
1.36 - g_VoteTimer = INVALID_HANDLE;
1.37 +
1.38 + if (g_VoteTimer != INVALID_HANDLE)
1.39 + {
1.40 + KillTimer(g_VoteTimer);
1.41 + g_VoteTimer = INVALID_HANDLE;
1.42 + }
1.43 +
1.44 + if (g_RetryTimer != INVALID_HANDLE)
1.45 + {
1.46 + KillTimer(g_RetryTimer);
1.47 + g_RetryTimer = INVALID_HANDLE;
1.48 + }
1.49 }
1.50
1.51 public OnMapTimeLeftChanged()
1.52 @@ -173,7 +183,7 @@
1.53 g_VoteTimer = INVALID_HANDLE;
1.54 }
1.55
1.56 - g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote, TIMER_FLAG_NO_MAPCHANGE);
1.57 + g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote);
1.58 }
1.59 }
1.60 }
1.61 @@ -301,7 +311,7 @@
1.62 if (IsVoteInProgress())
1.63 {
1.64 // Can't start a vote, try again in 5 seconds.
1.65 - g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, TIMER_FLAG_NO_MAPCHANGE);
1.66 + g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote);
1.67 return;
1.68 }
1.69
1.70 @@ -536,82 +546,4 @@
1.71 PushArrayString(g_NextMapList, map);
1.72 RemoveFromArray(tempMaps, b);
1.73 }
1.74 -}
1.75 -
1.76 -LoadMaps()
1.77 -{
1.78 - new bool:fileFound;
1.79 -
1.80 - decl String:mapPath[256], String:mapFile[64];
1.81 - GetConVarString(g_Cvar_Mapfile, mapFile, 64);
1.82 - BuildPath(Path_SM, mapPath, sizeof(mapPath), mapFile);
1.83 - fileFound = FileExists(mapPath);
1.84 - if (!fileFound)
1.85 - {
1.86 - new Handle:mapCycleFile = FindConVar("mapcyclefile");
1.87 - GetConVarString(mapCycleFile, mapPath, sizeof(mapPath));
1.88 - fileFound = FileExists(mapPath);
1.89 - }
1.90 -
1.91 - if (!fileFound)
1.92 - {
1.93 - LogError("Unable to locate sm_mapvote_file or mapcyclefile, no maps loaded.");
1.94 -
1.95 - if (g_MapList != INVALID_HANDLE)
1.96 - {
1.97 - ClearArray(g_MapList);
1.98 - }
1.99 -
1.100 - return 0;
1.101 - }
1.102 -
1.103 - // If the file hasn't changed, there's no reason to reload
1.104 - // all of the maps.
1.105 - new fileTime = GetFileTime(mapPath, FileTime_LastChange);
1.106 - if (g_mapFileTime == fileTime)
1.107 - {
1.108 - return GetArraySize(g_MapList);
1.109 - }
1.110 -
1.111 - g_mapFileTime = fileTime;
1.112 -
1.113 - // Reset the array
1.114 - if (g_MapList != INVALID_HANDLE)
1.115 - {
1.116 - ClearArray(g_MapList);
1.117 - }
1.118 -
1.119 - LogMessage("[SM] Loading mapchooser map file [%s]", mapPath);
1.120 -
1.121 - new Handle:file = OpenFile(mapPath, "rt");
1.122 - if (file == INVALID_HANDLE)
1.123 - {
1.124 - LogError("[SM] Could not open file: %s", mapPath);
1.125 - return 0;
1.126 - }
1.127 -
1.128 - decl String:currentMap[32];
1.129 - GetCurrentMap(currentMap, sizeof(currentMap));
1.130 -
1.131 - decl String:buffer[64], len;
1.132 - while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
1.133 - {
1.134 - TrimString(buffer);
1.135 -
1.136 - if ((len = StrContains(buffer, ".bsp", false)) != -1)
1.137 - {
1.138 - buffer[len] = '\0';
1.139 - }
1.140 -
1.141 - if (buffer[0] == '\0' || !IsValidConVarChar(buffer[0]) || !IsMapValid(buffer)
1.142 - || strcmp(currentMap, buffer, false) == 0)
1.143 - {
1.144 - continue;
1.145 - }
1.146 -
1.147 - PushArrayString(g_MapList, buffer);
1.148 - }
1.149 -
1.150 - CloseHandle(file);
1.151 - return GetArraySize(g_MapList);
1.152 }
1.153 \ No newline at end of file