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

Hooking a game cvar into a command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-12-2020 , 14:56   Hooking a game cvar into a command
Reply With Quote #1

How can i hook a game cvar to a command? so like tf_max_voice_speak_delay cvar can be hooked as a command into sm_voicespeakdelay <value>
__________________
Teamkiller324 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-12-2020 , 20:59   Re: Hooking a game cvar into a command
Reply With Quote #2

Untested. I don't think you can change the value of that specific convar anyway.

See thread for issue regarding that convar: [TF2] tf_max_voice_speak_delay not existing

PHP Code:
ConVar g_cvVoiceSpeakDelay;

public 
void OnPluginStart()
{
    
g_cvVoiceSpeakDelay FindConVar("tf_max_voice_speak_delay");
    
RegAdminCmd("sm_voicespeakdelay"cmdVoiceSpeakDelayADMFLAG_ROOT"Adjust the voice speak delay.");
}

public 
Action cmdVoiceSpeakDelay(int clientint args)
{
    switch (
args)
    {
        case 
1:
        {
            
char sArg[2];
            
GetCmdArg(1sArgsizeof sArg);
            if (
g_cvVoiceSpeakDelay != null)
            {
                
g_cvVoiceSpeakDelay.FloatValue StringToFloat(sArg);
            }
            else
            {
                
ReplyToCommand(client"[SM] Unable to find convar: tf_max_voice_speak_delay");
            }
        }
        default: 
ReplyToCommand(client"[SM] Usage: sm_voicespeakdelay <value>");
    }

    return 
Plugin_Handled;

__________________
Psyk0tik is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-12-2020 , 22:52   Re: Hooking a game cvar into a command
Reply With Quote #3

Quote:
Originally Posted by Crasher_3637 View Post
Untested. I don't think you can change the value of that specific convar anyway.

See thread for issue regarding that convar: [TF2] tf_max_voice_speak_delay not existing

PHP Code:
ConVar g_cvVoiceSpeakDelay;

public 
void OnPluginStart()
{
    
g_cvVoiceSpeakDelay FindConVar("tf_max_voice_speak_delay");
    
RegAdminCmd("sm_voicespeakdelay"cmdVoiceSpeakDelayADMFLAG_ROOT"Adjust the voice speak delay.");
}

public 
Action cmdVoiceSpeakDelay(int clientint args)
{
    switch (
args)
    {
        case 
1:
        {
            
char sArg[2];
            
GetCmdArg(1sArgsizeof sArg);
            if (
g_cvVoiceSpeakDelay != null)
            {
                
g_cvVoiceSpeakDelay.FloatValue StringToFloat(sArg);
            }
            else
            {
                
ReplyToCommand(client"[SM] Unable to find convar: tf_max_voice_speak_delay");
            }
        }
        default: 
ReplyToCommand(client"[SM] Usage: sm_voicespeakdelay <value>");
    }

    return 
Plugin_Handled;

it resets the value to 1.00000 only, maybe should be able to use sm_cvar as prefix, such as sm_voicepspeakdelay 123 makes it execute sm_cvar tf_max_voice_speak_delay 123
__________________
Teamkiller324 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-12-2020 , 22:57   Re: Hooking a game cvar into a command
Reply With Quote #4

Quote:
Originally Posted by Teamkiller324 View Post
it resets the value to 1.00000 only, maybe should be able to use sm_cvar as prefix, such as sm_voicepspeakdelay 123 makes it execute sm_cvar tf_max_voice_speak_delay 123
The method I showed works fine. It has SourceMod directly setting the value of the convar. The thread I linked explains why the value is not changing and why the convar itself doesn't work anymore after the Inferno update.

Specifically, these posts:

Quote:
Originally Posted by DarkPyro View Post
i can confirm after the inferno update that this is no longer working. the cvar may exist but the actual delay isn't affected anymore (u can sort of hear it spamming very quick in the beginning but the delay catches up, it's weird), kinda makes me sad, along with a lot of people in my community as this was their favorite thing to do, albeit obnoxious lol
Quote:
Originally Posted by asherkin View Post
It's not changing the cvar here that is the problem (sm_cvar ignores all restrictions and limits), the game just doesn't respect the cvar any more.
__________________
Psyk0tik is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-12-2020 , 23:00   Re: Hooking a game cvar into a command
Reply With Quote #5

https://github.com/nosoop/SM-ConVarConfigs found this can make convars originally needed for sm_cvar prefix to change cvar now open so you can change it without needing to do sm_cvar like sm_cvar tf_max_voice_speak_delay
__________________
Teamkiller324 is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-12-2020 , 23:04   Re: Hooking a game cvar into a command
Reply With Quote #6

seems to work going upwards but cannot go lower than 0.00 even with the command exposed, doing it manually tf_max_voice_speak_delay works fine
__________________

Last edited by Teamkiller324; 07-12-2020 at 23:05.
Teamkiller324 is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-13-2020 , 20:28   Re: Hooking a game cvar into a command
Reply With Quote #7

Tested the code on a different command, the result is that the convar it is hooked to is just resetting to its minimum
__________________

Last edited by Teamkiller324; 07-13-2020 at 20:29.
Teamkiller324 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-14-2020 , 01:29   Re: Hooking a game cvar into a command
Reply With Quote #8

Quote:
Originally Posted by Teamkiller324 View Post
Tested the code on a different command, the result is that the convar it is hooked to is just resetting to its minimum
If you want to lower the minimum value of a convar, use ConVar.SetBounds.

Code:
g_cvExampleConVar.SetBounds(ConVarBound_Lower, true, -1.0);
__________________
Psyk0tik is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-14-2020 , 12:17   Re: Hooking a game cvar into a command
Reply With Quote #9

I tested the code on mp_warmuptime in csgo, it just resets it to the minimum, example doing sm_warmuptime 120 makes it only change to 5.0, nothing else
__________________

Last edited by Teamkiller324; 07-14-2020 at 12:30.
Teamkiller324 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 09:48.


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