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

[TF2] QueryClientConVar cl_downloadfilter


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
StayOx
SourceMod Donor
Join Date: Jun 2012
Location: Gliese 581g
Old 03-02-2014 , 19:14   [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #1

I need help, I'm trying to create a function to verify the value of the client cvar "cl_downloadfilter". that cvar use values: none, all, mapsonly, nosound.

I'm struggling to check these values ​​and the value of convar is not "all" plugin print a message for client.

PHP Code:
 
#define CVAR_ALL = "all";
 
public Action:Timer_QueryClient(Handle:timerany:client)
{
 
g_hTimer_Query[client] = INVALID_HANDLE;
 if(
IsClientInGame(client))
 {
  
QueryClientConVar(client"cl_downloadfilter"ConVarQueryFinished:ClientConVarclient);
 }
 return 
Plugin_Continue;
}
public 
ClientConVar(QueryCookie:cookieclientConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
 if(
g_bEnabled && IsClientInGame(client))
 {
  if(
result == ConVarQuery)
  {
   new 
bool:_bCurrent StringToInt(cvarValue);
   if(
cvarValue) != CVAR_ALL)
 
   if(
_bCurrent != g_bDisabled[client])
   { 
StayOx is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-02-2014 , 19:36   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #2

It'd help if you posted what the compiler's error message was.

However, just from glancing at the code, you have two errors (one syntax, one logic) on this line:
Code:
if(cvarValue) != CVAR_ALL)
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
StayOx
SourceMod Donor
Join Date: Jun 2012
Location: Gliese 581g
Old 03-02-2014 , 19:41   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #3

Yes, however I really can not find a way to do this correctly. please the the spoiler

Spoiler

Last edited by StayOx; 03-02-2014 at 19:44.
StayOx is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 03-02-2014 , 20:36   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #4

Strings are not built-in SourcePawn. What you're having is a char array. Therefore you can't use
Quote:
"str" == "str"
directly like in some other languages.

You probably want to use StrEqual or StrContains.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 03-02-2014 at 20:36.
RedSword is offline
StayOx
SourceMod Donor
Join Date: Jun 2012
Location: Gliese 581g
Old 03-02-2014 , 23:42   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #5

Quote:
Originally Posted by RedSword View Post
Strings are not built-in SourcePawn. What you're having is a char array. Therefore you can't use directly like in some other languages.

You probably want to use StrEqual or StrContains.

thank you very much, despite the links have not worked you reminded me it existed

PHP Code:
public ConVar_QueryClient(QueryCookie:cookieclientConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
       if(
g_bEnabled && IsClientInGame(client))
       {
             if(
result == ConVarQuery_Okay)
             {
                  new 
bool:_bCurrent StrContains("all"cvarValue) ? true false;
                  if(
_bCurrent != g_bDisabled[client])
                  {
 
                         
/// code continue.... 
damn, I need to write everything not to forget ?!

Thanks for all

Last edited by StayOx; 03-02-2014 at 23:44. Reason: bacon in the code!
StayOx is offline
sheo
SourceMod Donor
Join Date: Jul 2013
Location: Russia, Moscow
Old 03-03-2014 , 02:44   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #6

You should replace "StrContains("all", cvarValue) ? true : false;" by "StrContains("all", cvarValue) != -1 ? true : false;"
sheo is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-03-2014 , 10:27   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #7

Quote:
Originally Posted by sheo View Post
You should replace "StrContains("all", cvarValue) ? true : false;" by "StrContains("all", cvarValue) != -1 ? true : false;"
Not sure if necessary, but adding parentheses may also help keep clean code
Code:
new bool:bStatement = (StrContains("all", cvarValue) != -1) ? true : false;
Mitchell is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 03-03-2014 , 15:33   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #8

PHP Code:
new bool:bStatement StrContains("all"cvarValue) != -1
Boolean comparisons already return a bool, no need to do a ternary conditional.
__________________
Dr. McKay is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-03-2014 , 16:20   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #9

Quote:
Originally Posted by Dr. McKay View Post
PHP Code:
new bool:bStatement StrContains("all"cvarValue) != -1
Boolean comparisons already return a bool, no need to do a ternary conditional.
Good point.
Mitchell is offline
StayOx
SourceMod Donor
Join Date: Jun 2012
Location: Gliese 581g
Old 03-03-2014 , 20:30   Re: [TF2] QueryClientConVar cl_downloadfilter
Reply With Quote #10

in my case the function should search only the value of the cvar "all" if the player set to any other value a message is shown every 5 seconds for him.
StayOx 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 02:08.


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