Cleaned up the code a bit. Also, added cvar change hook and made it execute OnMapStart when the plugin is reloaded so no map change is necessary to change the timer value.
PHP Code:
#include <sourcemod>
public Plugin myinfo =
{
name = "auto_map_reload",
author = "91346706501435897134",
description = "automatically reloads the current map",
version = "1.1",
};
ConVar sm_auto_map_reload_time;
float fTime;
public void OnPluginStart()
{
sm_auto_map_reload_time = CreateConVar("sm_auto_map_reload_time", "43200.0", "Timer in seconds (WARNING: RELOAD MAP FOR CHANGES TO TAKE EFFECT)", FCVAR_NOTIFY, true, 3600.0, true, 86400.0);
fTime = sm_auto_map_reload_time.FloatValue;
sm_auto_map_reload_time.AddChangeHook(CvarUpdate);
AutoExecConfig(true);
OnMapStart();
}
public void CvarUpdate(ConVar cvar, const char[] oldValue, const char[] newValue)
{
fTime = sm_auto_map_reload_time.FloatValue;
}
public void OnMapStart()
{
CreateTimer(fTime-60.0, notify_map_reload);
}
public Action notify_map_reload(Handle timer)
{
PrintHintTextToAll(">> Map reloading in 60 seconds <<");
CreateTimer(60.0, map_reload);
}
public Action map_reload(Handle timer)
{
char current_map_name[255];
GetCurrentMap(current_map_name, sizeof(current_map_name));
ServerCommand("changelevel %s", current_map_name);
}