1
0
Fork 0
mirror of https://codeberg.org/spire/autoexec.git synced 2026-08-02 04:04:48 +02:00

better persist current config

This commit is contained in:
Robin Appelman 2026-07-23 23:09:18 +02:00
commit 15b63eef7c
2 changed files with 62 additions and 12 deletions

Binary file not shown.

View file

@ -20,11 +20,12 @@ bool inAutoExec = false;
// size 4 so we can use team indexes
bool warned[4] = {false, false, false, false};
bool initialized = false;
new Handle:CvarLeague = INVALID_HANDLE;
new Handle:CvarMode = INVALID_HANDLE;
new Handle:CvarAutoset = INVALID_HANDLE;
new Handle:CvarWhitelist = INVALID_HANDLE;
new ConVar:CvarLeague = null;
new ConVar:CvarMode = null;
new ConVar:CvarAutoset = null;
new ConVar:CvarWhitelist = null;
public OnPluginStart() {
mapPrefixMap = new StringMap();
@ -34,7 +35,9 @@ public OnPluginStart() {
configOverwriteMap = new StringMap();
CvarLeague = CreateConVar("sm_autoexec_league", "ugc", "league to execute the configs for (ugc or etf2l)", FCVAR_PROTECTED);
CvarLeague.AddChangeHook(PersistLeague);
CvarMode = CreateConVar("sm_autoexec_mode", "9v9", "game mode to execute the config for (9v9, 6v6 or 4v4)", FCVAR_PROTECTED);
CvarMode.AddChangeHook(PersistGameMode);
CvarAutoset = CreateConVar("sm_autoexec_autoset", "true", "try to set league and mode when a config is manually loaded (true or false)", FCVAR_PROTECTED);
CvarWhitelist = FindConVar("mp_tournament_whitelist");
@ -66,9 +69,14 @@ public OnPluginStart() {
}
public OnMapStart() {
ExecMapCfg();
CreateTimer(3.0, RestoreCfg);
}
CreateTimer(10.0, ExecMapCfg);
public RestoreCfg() {
RestoreGameMode();
RestoreLeague();
ExecMapCfg();
initialized = true;
}
@ -106,27 +114,27 @@ public Action:HandleExecAction(args) {
if ((StrContains(cfg, "9v9_") > 0) || (StrContains(cfg, "hl_") > 0)) {
PrintToChatAll("Setting game mode to 9v9");
SetConVarString(CvarMode, "9v9");
SetGameMode("9v9");
}
if (StrContains(cfg, "6v6_") > 0) {
PrintToChatAll("Setting game mode to 6v6");
SetConVarString(CvarMode, "6v6");
SetGameMode("6v6");
}
if (StrContains(cfg, "6v_") > 0) {
PrintToChatAll("Setting game mode to 6v6");
SetConVarString(CvarMode, "6v6");
SetGameMode("6v6");
}
if (StrContains(cfg, "4v4_") > 0) {
PrintToChatAll("Setting game mode to 4v4");
SetConVarString(CvarMode, "4v4");
SetGameMode("4v4");
}
if (StrContains(cfg, "ultiduo") > 0) {
PrintToChatAll("Setting game mode to 2v2");
SetConVarString(CvarMode, "2v2");
SetGameMode("2v2");
}
return Plugin_Continue;
@ -202,6 +210,48 @@ public GetGameMode(String:leagueGamemode[8], String:league[8]) {
leagueGamemode = gamemode;
}
public void SetGameMode(String:mode[8]) {
SetConVarString(CvarMode, mode);
}
public void PersistGameMode(ConVar convar, const char[] oldValue, const char[] newValue) {
if (!initialized) {
return;
}
File file = OpenFile("autoexec_gamemode", "w");
file.WriteString(newValue, -1);
file.Close();
}
public void RestoreGameMode() {
decl String:mode[8];
File file = OpenFile("autoexec_gamemode", "r");
if (file) {
file.ReadString(mode, 8, -1);
file.Close();
SetConVarString(CvarMode, mode);
}
}
public void PersistLeague(ConVar convar, const char[] oldValue, const char[] newValue) {
if (!initialized) {
return;
}
File file = OpenFile("autoexec_league", "w");
file.WriteString(newValue, -1);
file.Close();
}
public void RestoreLeague() {
decl String:league[8];
File file = OpenFile("autoexec_league", "r");
if (file) {
file.ReadString(league, 8, -1);
file.Close();
SetConVarString(CvarLeague, league);
}
}
public GetLeagueMapType(String:map[128], String:leagueMapType[128], String:league[8]) {
decl String:mapType[128];
GetMapType(map, mapType);
@ -272,7 +322,7 @@ public void CheckPlayerCount(int team) {
if (gotExpectedMode && strncmp(expectedMode, expectedModeOther, strlen(expectedMode)) == 0) {
PrintToChatAll("Switching config to %s", expectedMode);
SetConVarString(CvarMode, expectedMode);
SetGameMode(expectedMode);
ExecMapCfg();
CreateTimer(0.5, ReadyTeamTimer, team);
return;