Quote:
Originally Posted by Fyren
The server doesn't know or care about the difference between typing something into the console and exec'ing a config. Your choices are don't put your cvar into the config or don't exec the config (which may mean don't use AutoExecConfig, since you're not clear on what you're actually doing).
|
I kept coming to this conclusion but kept finding it strange. I do exec the plugins config only once in OnPluginStart and it does what it should. I have the HookConVarChange hooks in place because I do wish to be able to change some of those cvars while the server is running. The gotcha is how on every map change the plugin reloads its config and obliterates what you set in the console.
After considering this is by design and not what I thought should happen I've implemented a way to change cvars over the console and lock them from changes due to this behavior. I'll be uploading those changes today, here's a preview of how I'm doing it in my ConVarChanged callback..
PHP Code:
StringMap g_Cvars;
public OnPluginStart() {
g_Cvars = new StringMap();
}
public UpdateConVarsHook(Handle convar, const char[] oldCv, const char[] newCv) {
GetConVarName(convar, g_sB, sizeof(g_sB));
Echo(1, "UpdateConVarsHook: %s %s %s", g_sB, oldCv, newCv);
char name[32];
char modCv[32];
Format(name, sizeof(name), g_sB);
Format(modCv, sizeof(modCv), "%s", newCv);
if (StrContains(newCv, "-l") == 0) {
ReplaceString(modCv, sizeof(modCv), "-l", "");
g_Cvars.SetString(name, modCv, true);
}
else if (StrContains(newCv, "-u") == 0) {
ReplaceString(modCv, sizeof(modCv), "-u", "");
g_Cvars.Remove(name);
}
g_Cvars.GetString(name, modCv, sizeof(modCv));
TrimString(modCv);
if (modCv[0] == EOS) {
Format(modCv, sizeof(modCv), oldCv);
}
if (StrEqual(name, "abm_extraplayers")) {
SetConVarString(g_cvExtraPlayers, newCv);
g_ExtraPlayers = GetConVarInt(g_cvExtraPlayers);
}
}
Everything works as it should. Changing cvars over the console and having them reset on map change all work as expected. If over the console you want to lock a cvar, you prefix it with the option
-l (l for lock) and it will no longer change on map change. It will stay locked. You won't even be able to change it again over the console unless you use -l again. To unlock the cvar use
-u (u for unlock) followed by a new value or no value in which case the old value is used.
If you unlock a cvar, it will change on map change if it differs from what's in the config. I guess keep this in mind. I didn't want to overengineer a solution but I'm afraid it came to that. I'd still like to know if there is a better way as I feel what I'm doing should have sort of been the default behavior?
Thanks!