AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] How to block the change notification of cvars with NOTIFY flag (https://forums.alliedmods.net/showthread.php?t=144616)

berni 12-05-2010 20:40

[SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Since the notify=false parameter of the SetConVar Functions doesn't work anymore for orangebox/L4D games, and because it's often necessary to set the NOFITY flag for certain cvars that need to be public, here is how to block the notifcations that normally automatically goes th the clients when such a ConVar gets changed.



PHP Code:

public OnPluginStart() {
     
HookEvent("server_cvar"Event_ServerCvarEventHookMode_Pre);
}

public 
Action:Event_ServerCvar(Handle:event, const String:name[], bool:dontBroadcast) { 

Block all cvar notifications:

PHP Code:

    return Plugin_Handled

or block all cvar notifications of my plugin only starting with "mycvarprefix_":

PHP Code:

    decl String:cvarName[64];
    
GetEventString(event"cvarname"cvarNamesizeof(cvarName));

    if (
StrContains(cvarName"mycvarprefix_") == 0) {
        return 
Plugin_Handled;
    }

    return 
Plugin_Continue

PHP Code:




Master53 01-17-2011 11:29

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
does this block sourcemod cvar change, or just server cvars?

berni 01-17-2011 12:59

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
It does not block cvar changes at all.

Master53 01-17-2011 15:36

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
well not block them, just stop the notification been sent to the players.

berni 01-17-2011 16:14

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
cvars are cvars, there is no difference between sourcemod cvars and server cvars.

asherkin 01-17-2011 19:53

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Doing this will cause the rules list to get out-of-sync.

EDIT: Treat this as a reply to the post below, I was rather tired and misread the OP originally :P.

DJ Tsunami 01-18-2011 04:39

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
If your plugin is the one changing the convar, it can just remove the FCVAR_NOTIFY flag, change the value, and re-add the flag. HLSW Info does this.

Twelve-60 01-18-2011 09:48

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Quote:

Originally Posted by DJ Tsunami (Post 1396035)
If your plugin is the one changing the convar, it can just remove the FCVAR_NOTIFY flag, change the value, and re-add the flag. HLSW Info does this.

I use this technique for my WarMod plugin, however I found out that as asherkin said, this does not update the rules list sent out by a server query (A2S_RULES).

To properly update a public CVAR (FCVAR_NOTIFY) without displaying it ingame, you can use the SteamTools extension and use Steam_SetRule() to manually set it, here are my stocks:

PHP Code:

/*********************************************************
 *  Hide setting an int cvar
 * 
 * @noreturn
 *********************************************************/
 
stock SetConVarIntHidden(Handle:cvar, const value) {
    new 
String:cvar_name[64];
    new 
String:value_string[512];
    new 
flags GetConVarFlags(cvar);
    
SetConVarFlags(cvarflags & ~FCVAR_NOTIFY);
    
SetConVarInt(cvarvalue);
    
GetConVarName(cvarcvar_namesizeof(cvar_name));
    
IntToString(valuevalue_stringsizeof(value_string));
    
Steam_SetRule(cvar_namevalue_string);
    
SetConVarFlags(cvarflags);
}


/*********************************************************
 *  Hide setting a string cvar
 * 
 * @noreturn
 *********************************************************/
 
stock SetConVarStringHidden(Handle:cvarString:value[]) {
    new 
String:cvar_name[64];
    new 
flags GetConVarFlags(cvar);
    
SetConVarFlags(cvarflags & ~FCVAR_NOTIFY);
    
SetConVarString(cvarvalue);
    
GetConVarName(cvarcvar_namesizeof(cvar_name));
    
Steam_SetRule(cvar_namevalue);
    
SetConVarFlags(cvarflags);



berni 01-18-2011 11:03

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Quote:

Originally Posted by asherkin (Post 1395922)
Doing this will cause the rules list to get out-of-sync.

I already wondered what you mean yesterday o.O

I think my method is preferable, because no extension is required, not everyone
has Steamtools installed on their server, my method also doesn't break if new updates come out.

berni 03-16-2011 06:54

Re: [SNIPPET] How to block the change notification of cvars with NOTIFY flag
 
Update: Added missing code line.


All times are GMT -4. The time now is 09:26.

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