1.1 --- a/plugins/randomcycle.sp Thu Oct 18 01:08:48 2007 +0000
1.2 +++ b/plugins/randomcycle.sp Thu Oct 18 01:16:42 2007 +0000
1.3 @@ -62,7 +62,7 @@
1.4 AutoExecConfig(true, "randomcycle");
1.5 }
1.6
1.7 -public OnMapStart()
1.8 +public OnConfigsExecuted()
1.9 {
1.10 g_Cvar_Nextmap = FindConVar("sm_nextmap");
1.11
1.12 @@ -72,7 +72,7 @@
1.13 SetFailState("sm_nextmap not found");
1.14 }
1.15
1.16 - if (LoadMaps())
1.17 + if (LoadMaps(g_MapList, g_mapFileTime, g_Cvar_Mapfile))
1.18 {
1.19 CreateTimer(5.0, Timer_RandomizeNextmap); // Small delay to give Nextmap time to complete OnMapStart()
1.20 }
1.21 @@ -108,82 +108,4 @@
1.22 LogMessage("RandomCycle has chosen %s for the nextmap.", map);
1.23
1.24 return Plugin_Stop;
1.25 -}
1.26 -
1.27 -LoadMaps()
1.28 -{
1.29 - new bool:fileFound;
1.30 -
1.31 - decl String:mapPath[256], String:mapFile[64];
1.32 - GetConVarString(g_Cvar_Mapfile, mapFile, 64);
1.33 - BuildPath(Path_SM, mapPath, sizeof(mapPath), mapFile);
1.34 - fileFound = FileExists(mapPath);
1.35 - if (!fileFound)
1.36 - {
1.37 - new Handle:mapCycleFile = FindConVar("mapcyclefile");
1.38 - GetConVarString(mapCycleFile, mapPath, sizeof(mapPath));
1.39 - fileFound = FileExists(mapPath);
1.40 - }
1.41 -
1.42 - if (!fileFound)
1.43 - {
1.44 - LogError("Unable to locate sm_randomcycle_file or mapcyclefile, no maps loaded.");
1.45 -
1.46 - if (g_MapList != INVALID_HANDLE)
1.47 - {
1.48 - ClearArray(g_MapList);
1.49 - }
1.50 -
1.51 - return 0;
1.52 - }
1.53 -
1.54 - // If the file hasn't changed, there's no reason to reload
1.55 - // all of the maps.
1.56 - new fileTime = GetFileTime(mapPath, FileTime_LastChange);
1.57 - if (g_mapFileTime == fileTime)
1.58 - {
1.59 - return GetArraySize(g_MapList);
1.60 - }
1.61 -
1.62 - g_mapFileTime = fileTime;
1.63 -
1.64 - // Reset the array
1.65 - if (g_MapList != INVALID_HANDLE)
1.66 - {
1.67 - ClearArray(g_MapList);
1.68 - }
1.69 -
1.70 - LogMessage("[SM] Loading Random Cycle map file [%s]", mapPath);
1.71 -
1.72 - new Handle:file = OpenFile(mapPath, "rt");
1.73 - if (file == INVALID_HANDLE)
1.74 - {
1.75 - LogError("[SM] Could not open file: %s", mapPath);
1.76 - return 0;
1.77 - }
1.78 -
1.79 - decl String:currentMap[32];
1.80 - GetCurrentMap(currentMap, sizeof(currentMap));
1.81 -
1.82 - decl String:buffer[64], len;
1.83 - while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
1.84 - {
1.85 - TrimString(buffer);
1.86 -
1.87 - if ((len = StrContains(buffer, ".bsp", false)) != -1)
1.88 - {
1.89 - buffer[len] = '\0';
1.90 - }
1.91 -
1.92 - if (buffer[0] == '\0' || !IsValidConVarChar(buffer[0]) || !IsMapValid(buffer)
1.93 - || strcmp(currentMap, buffer, false) == 0)
1.94 - {
1.95 - continue;
1.96 - }
1.97 -
1.98 - PushArrayString(g_MapList, buffer);
1.99 - }
1.100 -
1.101 - CloseHandle(file);
1.102 - return GetArraySize(g_MapList);
1.103 }
1.104 \ No newline at end of file