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

Query cvar from chat


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nomarky
SourceMod Donor
Join Date: Sep 2007
Old 08-15-2008 , 16:25   Query cvar from chat
Reply With Quote #1

I've come across this in the SM documentation:

PHP Code:
public OnPluginStart()
{
    
RegConsoleCmd("say"Command_Say)
}
 
public 
Action:Command_Say(clientargs)
{
    new 
String:text[192]
    
GetCmdArgString(textsizeof(text))
 
    new 
startidx 0
    
if (text[0] == '"')
    {
        
startidx 1
        
/* Strip the ending quote, if there is one */
        
new len strlen(text);
        if (
text[len-1] == '"')
        {
            
text[len-1] = '\0'
        
}
    }
 
    if (
StrEqual(text[startidx], "/ff"))
    {
        new 
Handle:ff FindConVar("mp_friendlyfire")
        if (
GetConVarInt(ff))
        {
            
PrintToConsole(client"Friendly fire is enabled.")
        } else {
            
PrintToConsole(client"Friendly fire is disabled.")
        }
        
/* Block the client's messsage from broadcasting */
        
return Plugin_Handled
    
}
 
    
/* Let say continue normally */
    
return Plugin_Continue

but can't figure out how to change it to report the actual value of mp_friendlyfire. What am I missing?
Nomarky is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 08-15-2008 , 17:38   Re: Query cvar from chat
Reply With Quote #2

That looks like it should work fine. What exactly do you want it to do?
bl4nk is offline
Nomarky
SourceMod Donor
Join Date: Sep 2007
Old 08-15-2008 , 17:44   Re: Query cvar from chat
Reply With Quote #3

Quote:
Originally Posted by bl4nk View Post
That looks like it should work fine. What exactly do you want it to do?
I want it to report the actual value, i.e. in this example 1 or 0, rather than say enabled/disabled
Nomarky is offline
RM_Hamster
SourceMod Donor
Join Date: Jul 2008
Location: MA
Old 08-15-2008 , 17:56   Re: Query cvar from chat
Reply With Quote #4

All you would need to change is the two PrintToConsole lines to whatever you want them to say. 1 is enabled and 0 is disabled, so you could easily just change it to:

Code:
        if (GetConVarInt(ff))
        {
            PrintToConsole(client, "mp_friendlyfire is 1.")
        } else {
            PrintToConsole(client, "mp_friendlyfire is 0.")
        }
RM_Hamster is offline
Nomarky
SourceMod Donor
Join Date: Sep 2007
Old 08-15-2008 , 18:32   Re: Query cvar from chat
Reply With Quote #5

I see where you're coming from, but thats not what I'm after. mp_friendlyfire is just in the example code I'm trying to adapt. I would like to be able to adapt it to report other stuff like gravity, plugin version etc, so I'm trying to suss how to get the actual value of a given cvar to display.
Nomarky is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 08-15-2008 , 18:42   Re: Query cvar from chat
Reply With Quote #6

PrintToConsole(client, "%s is %i", cvarNameString, cvarValue);
bl4nk is offline
msleeper
Veteran Member
Join Date: May 2008
Location: Atlanta, Jawjuh
Old 08-15-2008 , 18:43   Re: Query cvar from chat
Reply With Quote #7

Use GetConVarInt and a Format. What the code Hamster quoted is using a programming trick; since GetConVarInt(ff) returns 1 when it is on, and since 1 is interpreted as "true", the first console string is printed. When it is off, set to 0, and interpreted as "false", the second string is printed.
__________________
msleeper is offline
Kigen
BANNED
Join Date: Feb 2008
Old 08-19-2008 , 11:42   Re: Query cvar from chat
Reply With Quote #8

Code:
PrintToConsole(client, "mp_friendlyfire is %d.", GetConVarInt(ff))
Why make it more complex than it has to be?
Kigen is offline
Nomarky
SourceMod Donor
Join Date: Sep 2007
Old 08-19-2008 , 17:33   Re: Query cvar from chat
Reply With Quote #9

Quote:
Originally Posted by Kigen View Post
Code:
PrintToConsole(client, "mp_friendlyfire is %d.", GetConVarInt(ff))
Why make it more complex than it has to be?
Works great, thanks Kigen
Nomarky is offline
Nomarky
SourceMod Donor
Join Date: Sep 2007
Old 08-19-2008 , 18:57   Re: Query cvar from chat
Reply With Quote #10

How could I use this to return a value with a '.' in it? I tried to get the value of a plugin version:

Code:
         if (StrEqual(text[startidx], "cvars"))
        {
        new Handle:ff = FindConVar("mp_friendlyfire");
        new Handle:cda = FindConVar("cd_announcer_version");
        if (GetConVarInt(ff), (cda))
        {
            PrintToChat(client, "FF is %d", GetConVarInt(ff));
            PrintToChat(client, "CD Announcer Version %d", GetConVarInt(cda));
        }
But it only returns the first number of the plugin version i.e. 2 instead of 2.1. What am I missing here?
Nomarky 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 08:07.


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