nextmap reloads the map list on map change, IF the file has changed.
authorMichael McKoy <ferret99gt@gmail.com>
Wed Sep 19 00:24:00 2007 +0000 (2007-09-19)
changeset 1439e184b23ba4d8
parent 1438 55a01d8b3960
child 1440 a99687dd0d57
nextmap reloads the map list on map change, IF the file has changed.
plugins/nextmap.sp
     1.1 --- a/plugins/nextmap.sp	Wed Sep 19 00:20:46 2007 +0000
     1.2 +++ b/plugins/nextmap.sp	Wed Sep 19 00:24:00 2007 +0000
     1.3 @@ -53,6 +53,7 @@
     1.4  
     1.5  new g_MapPos = -1;
     1.6  new Handle:g_MapList = INVALID_HANDLE;
     1.7 +new g_mapFileTime;
     1.8   
     1.9  public OnPluginStart()
    1.10  {
    1.11 @@ -70,10 +71,8 @@
    1.12  	g_Cvar_Mapcycle = FindConVar("mapcyclefile");
    1.13  	
    1.14  	g_MapList = CreateArray(32);
    1.15 -	
    1.16 -	decl String:mapCycle[64];
    1.17 -	GetConVarString(g_Cvar_Mapcycle, mapCycle, 64);
    1.18 -	if (LoadMaps(mapCycle) < 1)
    1.19 +
    1.20 +	if (!LoadMaps())
    1.21  	{
    1.22  		LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
    1.23  		SetFailState("Mapcycle Not Found");		
    1.24 @@ -107,6 +106,12 @@
    1.25  	// not in mapcyclefile. So we keep it set to the last expected nextmap. - ferret
    1.26  	if (strcmp(lastMap, currentMap) == 0)
    1.27  	{
    1.28 +		if (!LoadMaps())
    1.29 +		{
    1.30 +			LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
    1.31 +			SetFailState("Mapcycle Not Found");	
    1.32 +		}		
    1.33 +		
    1.34  		FindAndSetNextMap();
    1.35  	}
    1.36  }
    1.37 @@ -120,7 +125,7 @@
    1.38  {
    1.39  	if (strcmp(oldValue, newValue, false) != 0)
    1.40  	{
    1.41 -		if (LoadMaps(newValue) < 1)
    1.42 +		if (!LoadMaps())
    1.43  		{
    1.44  			LogError("FATAL: Cannot load map cycle. Nextmap not loaded.");
    1.45  			SetFailState("Mapcycle Not Found");	
    1.46 @@ -244,23 +249,37 @@
    1.47  	return Plugin_Stop;
    1.48  }
    1.49   
    1.50 -LoadMaps(const String:path[])
    1.51 +LoadMaps()
    1.52  {
    1.53 -	if (!FileExists(path))
    1.54 +	decl String:mapCycle[64];
    1.55 +	GetConVarString(g_Cvar_Mapcycle, mapCycle, 64);	
    1.56 +	
    1.57 +	if (!FileExists(mapCycle))
    1.58  	{
    1.59  		return 0;
    1.60  	}
    1.61 +	
    1.62 +	new fileTime =  GetFileTime(mapCycle, FileTime_LastChange);
    1.63 +	if (g_mapFileTime == fileTime)
    1.64 +	{
    1.65 +		return GetArraySize(g_MapList);
    1.66 +	}
    1.67 +	
    1.68 +	g_mapFileTime = fileTime;
    1.69   
    1.70 -	new Handle:file = OpenFile(path, "r");
    1.71 +	new Handle:file = OpenFile(mapCycle, "r");
    1.72  	
    1.73  	if (file == INVALID_HANDLE)
    1.74  	{
    1.75 -		LogError("[SM] Could not open file: %s", path);
    1.76 +		LogError("[SM] Could not open file: %s", mapCycle);
    1.77  		return 0;
    1.78  	}
    1.79  	
    1.80 -	ClearArray(g_MapList);
    1.81  	g_MapPos = -1;
    1.82 +	if (g_MapList != INVALID_HANDLE)
    1.83 +	{
    1.84 +		ClearArray(g_MapList);
    1.85 +	}
    1.86  	
    1.87  	decl String:buffer[255];
    1.88  	while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))