mapchooser_extended: store cooldowns in file
This commit is contained in:
parent
93dcb84f20
commit
4dd6a78cb7
@ -0,0 +1,3 @@
|
||||
"mapchooser_extended"
|
||||
{
|
||||
}
|
@ -373,6 +373,7 @@ public void OnPluginStart()
|
||||
g_MapVoteWarningTickForward = CreateGlobalForward("OnMapVoteWarningTick", ET_Ignore, Param_Cell);
|
||||
g_MapVoteRunoffStartForward = CreateGlobalForward("OnMapVoteRunnoffWarningStart", ET_Ignore);
|
||||
|
||||
InternalRestoreMapCooldowns();
|
||||
}
|
||||
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||
@ -548,6 +549,7 @@ public void OnMapEnd()
|
||||
else
|
||||
g_OldMapList.Remove(map);
|
||||
}
|
||||
InternalStoreMapCooldowns();
|
||||
delete OldMapListSnapshot;
|
||||
}
|
||||
|
||||
@ -2110,6 +2112,7 @@ public int Native_ExcludeMap(Handle plugin, int numParams)
|
||||
}
|
||||
|
||||
g_OldMapList.SetValue(map, Cooldown, true);
|
||||
InternalStoreMapCooldowns();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -2590,3 +2593,121 @@ stock int FindIntInArray(int[] array, int size, int value)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
stock void InternalRestoreMapCooldowns()
|
||||
{
|
||||
char sCooldownFile[PLATFORM_MAX_PATH];
|
||||
BuildPath(Path_SM, sCooldownFile, sizeof(sCooldownFile), "configs/mapchooser_extended/cooldowns.cfg");
|
||||
|
||||
if(!FileExists(sCooldownFile))
|
||||
{
|
||||
LogMessage("Could not find cooldown file: \"%s\"", sCooldownFile);
|
||||
return;
|
||||
}
|
||||
|
||||
KeyValues Cooldowns = new KeyValues("mapchooser_extended");
|
||||
|
||||
if(!Cooldowns.ImportFromFile(sCooldownFile))
|
||||
{
|
||||
LogMessage("Unable to load cooldown file: \"%s\"", sCooldownFile);
|
||||
delete Cooldowns;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!Cooldowns.GotoFirstSubKey(true))
|
||||
{
|
||||
LogMessage("Unable to goto first sub key: \"%s\"", sCooldownFile);
|
||||
delete Cooldowns;
|
||||
return;
|
||||
}
|
||||
|
||||
int Cooldown;
|
||||
char map[PLATFORM_MAX_PATH];
|
||||
do
|
||||
{
|
||||
if(!Cooldowns.GetSectionName(map, sizeof(map)))
|
||||
{
|
||||
LogMessage("Unable to get section name: \"%s\"", sCooldownFile);
|
||||
delete Cooldowns;
|
||||
return;
|
||||
}
|
||||
|
||||
if((Cooldown = Cooldowns.GetNum("cd", -1)) > 0)
|
||||
{
|
||||
LogMessage("Restored cooldown: %s -> %d", map, Cooldown);
|
||||
g_OldMapList.SetValue(map, Cooldown, true);
|
||||
}
|
||||
} while(Cooldowns.GotoNextKey(true));
|
||||
|
||||
delete Cooldowns;
|
||||
}
|
||||
|
||||
stock void InternalStoreMapCooldowns()
|
||||
{
|
||||
char sCooldownFile[PLATFORM_MAX_PATH];
|
||||
BuildPath(Path_SM, sCooldownFile, sizeof(sCooldownFile), "configs/mapchooser_extended/cooldowns.cfg");
|
||||
|
||||
if(!FileExists(sCooldownFile))
|
||||
{
|
||||
LogMessage("Could not find cooldown file: \"%s\"", sCooldownFile);
|
||||
return;
|
||||
}
|
||||
|
||||
KeyValues Cooldowns = new KeyValues("mapchooser_extended");
|
||||
if(!Cooldowns.ImportFromFile(sCooldownFile))
|
||||
{
|
||||
LogMessage("Unable to import cooldown file: \"%s\"", sCooldownFile);
|
||||
delete Cooldowns;
|
||||
return;
|
||||
}
|
||||
Cooldowns.Rewind();
|
||||
if (Cooldowns.GotoFirstSubKey())
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (Cooldowns.DeleteThis() < 1)
|
||||
break;
|
||||
}
|
||||
|
||||
if(!Cooldowns.ExportToFile(sCooldownFile))
|
||||
{
|
||||
LogMessage("Unable to export cooldown file: \"%s\"", sCooldownFile);
|
||||
delete Cooldowns;
|
||||
return;
|
||||
}
|
||||
}
|
||||
delete Cooldowns;
|
||||
|
||||
Cooldowns = new KeyValues("mapchooser_extended");
|
||||
Cooldowns.Rewind();
|
||||
int Cooldown;
|
||||
char map[PLATFORM_MAX_PATH];
|
||||
|
||||
StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot();
|
||||
for(int i = 0; i < OldMapListSnapshot.Length; i++)
|
||||
{
|
||||
OldMapListSnapshot.GetKey(i, map, sizeof(map));
|
||||
g_OldMapList.GetValue(map, Cooldown);
|
||||
|
||||
if (!Cooldowns.JumpToKey(map, true))
|
||||
{
|
||||
LogMessage("Unable to create/find key: %s", map);
|
||||
delete Cooldowns;
|
||||
delete OldMapListSnapshot;
|
||||
return;
|
||||
}
|
||||
Cooldowns.SetNum("cd", Cooldown);
|
||||
Cooldowns.Rewind();
|
||||
}
|
||||
|
||||
if(!Cooldowns.ExportToFile(sCooldownFile))
|
||||
{
|
||||
LogMessage("Unable to export cooldown file: \"%s\"", sCooldownFile);
|
||||
delete Cooldowns;
|
||||
delete OldMapListSnapshot;
|
||||
return;
|
||||
}
|
||||
|
||||
delete Cooldowns;
|
||||
delete OldMapListSnapshot;
|
||||
}
|
Loading…
Reference in New Issue
Block a user