Raised This Month: $51 Target: $400
 12% 

Solved How do you stop reading your own plugin cfg on every new round?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NgBUCKWANGS
Senior Member
Join Date: Dec 2014
Old 01-20-2017 , 17:48   How do you stop reading your own plugin cfg on every new round?
Reply With Quote #1

In L4D2 on every new round my plugins config overwrites anything I've set in the console. This is unexpected and I am having a hard time figuring out how to stop it. The plugin reads the default values in OnPluginStart just fine and updates them just fine with some hooks *but* the problem is, how can I stop reading those default values more than once? I only ever want them only once and any new changes will be made by console and should always supersede the config or up until I reload the plugin?

Anyone know how to do this?

Last edited by NgBUCKWANGS; 01-23-2017 at 08:20. Reason: Marked Solved
NgBUCKWANGS is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 01-20-2017 , 18:19   Re: How do you stop reading your own plugin cfg on every new round?
Reply With Quote #2

HookConVarChange is the answer unless that's not what you wanted.
cravenge is offline
NgBUCKWANGS
Senior Member
Join Date: Dec 2014
Old 01-20-2017 , 19:22   Re: How do you stop reading your own plugin cfg on every new round?
Reply With Quote #3

Quote:
Originally Posted by cravenge View Post
HookConVarChange is the answer unless that's not what you wanted.
I'm using HookConVarChange in OnPluginStart. That function is the only place I'm using it. It reads the config just fine on start and that's good and changing cvars over the console is good but what's bad is, changing a cvar over console doesn't last pass a map change. I've been scratching my head about this and almost feel like it's on purpose or I'm doing something wrong?

Last edited by NgBUCKWANGS; 01-21-2017 at 01:06.
NgBUCKWANGS is offline
NgBUCKWANGS
Senior Member
Join Date: Dec 2014
Old 01-21-2017 , 12:09   Re: How do you stop reading your own plugin cfg on every new round?
Reply With Quote #4

I was under the impression that changing a cvar in the console would live the entire game. This just isn't true. It will always be reset back to it's default config value on map change. I just can't figure out how to stop this. How do you set a value for a cvar over the console and **never** have the config overwrite it?
NgBUCKWANGS is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 01-21-2017 , 23:08   Re: How do you stop reading your own plugin cfg on every new round?
Reply With Quote #5

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).
Fyren is offline
NgBUCKWANGS
Senior Member
Join Date: Dec 2014
Old 01-22-2017 , 07:35   Re: How do you stop reading your own plugin cfg on every new round?
Reply With Quote #6

Quote:
Originally Posted by Fyren View Post
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(convarg_sBsizeof(g_sB));
    Echo(
1"UpdateConVarsHook: %s %s %s"g_sBoldCvnewCv);

    
char name[32];
    
char modCv[32];

    
Format(namesizeof(name), g_sB);
    
Format(modCvsizeof(modCv), "%s"newCv);

    if (
StrContains(newCv"-l") == 0) {
        
ReplaceString(modCvsizeof(modCv), "-l""");
        
g_Cvars.SetString(namemodCvtrue);
    }

    else if (
StrContains(newCv"-u") == 0) {
        
ReplaceString(modCvsizeof(modCv), "-u""");
        
g_Cvars.Remove(name);
    }

    
g_Cvars.GetString(namemodCvsizeof(modCv));
    
TrimString(modCv);
    if (
modCv[0] == EOS) {
        
Format(modCvsizeof(modCv), oldCv);
    }

    if (
StrEqual(name"abm_extraplayers")) {
        
SetConVarString(g_cvExtraPlayersnewCv);
        
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!

Last edited by NgBUCKWANGS; 01-22-2017 at 11:11. Reason: simplified the code
NgBUCKWANGS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode