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

Make shure that a cvar is always set


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
~Gh05t~
Member
Join Date: Oct 2007
Old 04-16-2009 , 13:30   Make shure that a cvar is always set
Reply With Quote #1

Hi all,
how can i set a cvar (or a cmd) each time the server auto-resets it?

For example: I want bots are only allowed to play handguns while my plugin is loaded, no matter what is configured in server.cfg. So i set
Code:
ServerCommand("bot_pistols_only")
But on what time do i execute that? I just implemented a hook on round_start, but that is not very nice.
~Gh05t~ is offline
Send a message via ICQ to ~Gh05t~
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 04-16-2009 , 16:33   Re: Make shure that a cvar is always set
Reply With Quote #2

PHP Code:
public OnConfigsExecuted()
{
    
// Do stuff here

bl4nk is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 04-17-2009 , 06:13   Re: Make shure that a cvar is always set
Reply With Quote #3

I prefer something like this.

PHP Code:
new Handle:cvar_bot_pistols_only INVALID_HANDLE;

public 
OnPluginStart()
{    
    
cvar_bot_pistols_only FindConVar("bot_pistols_only");
    
HookConVarChange(cvar_bot_pistols_onlyOnCVarChange);
}

public 
OnCVarChange(Handle:convar_hndl, const String:oldValue[], const String:newValue[])
{
    
SetConVarBool(cvar_bot_pistols_onlytrue);

__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
~Gh05t~
Member
Join Date: Oct 2007
Old 04-17-2009 , 08:11   Re: Make shure that a cvar is always set
Reply With Quote #4

Thanks for your answers.

exvel: I had that idea, too, but it only works if you are realy watching a cvar. "bot_pistols_only" is no cvar, so you will get INVALID_HANDLE from FindConVar("bot_pistols_only").
I would prefer
bl4nk's solution here, looks clean and conceptional. If that is not enough, i try to use HookConVarChange. Thanks again!
~Gh05t~ is offline
Send a message via ICQ to ~Gh05t~
~Gh05t~
Member
Join Date: Oct 2007
Old 04-17-2009 , 08:43   Re: Make shure that a cvar is always set
Reply With Quote #5

hmmm... it seems that OnConfigsExecuted gets executed at the time of executing, not after it. So if i set something there it gets overwritten immediately.

Maybe i have to add some ConVarChange hooks on the associated cvars after all.

/edit: that is not nice, but works as expected:
PHP Code:
new Handle:g_cVarBotAllowMachineGuns INVALID_HANDLE;     //If nonzero, bots may use the machine gun.
new Handle:g_cVarBotAllowPistols INVALID_HANDLE;      //If nonzero, bots may use pistols.
new Handle:g_cVarBotAllowRifles INVALID_HANDLE;    //If nonzero, bots may use rifles.
new Handle:g_cVarBotAllowShotguns INVALID_HANDLE;    //If nonzero, bots may use shotguns.
new Handle:g_cVarBotAllowSubMachineGuns INVALID_HANDLE;    //If nonzero, bots may use sub-machine guns.
new Handle:g_cVarBotAllowSnipers INVALID_HANDLE;    //If nonzero, bots may use sniper rifles.
new Handle:g_cVarBotAllowGrenades INVALID_HANDLE;    //If nonzero, bots may use grenades.

public OnPluginStart()
{
    
ServerCommand("bot_pistols_only");

    
g_cVarBotAllowMachineGuns FindConVar("bot_allow_machine_guns");
    
g_cVarBotAllowPistols FindConVar("bot_allow_pistols");
    
g_cVarBotAllowRifles FindConVar("bot_allow_rifles");
    
g_cVarBotAllowShotguns FindConVar("bot_allow_shotguns");
    
g_cVarBotAllowSubMachineGuns FindConVar("bot_allow_sub_machine_guns");
    
g_cVarBotAllowSnipers FindConVar("bot_allow_snipers");
    
g_cVarBotAllowGrenades FindConVar("bot_allow_grenades");
    
    
HookConVarChange(g_cVarBotAllowMachineGunsOnCVarChange);
    
HookConVarChange(g_cVarBotAllowPistolsOnCVarChange);
    
HookConVarChange(g_cVarBotAllowRiflesOnCVarChange);
    
HookConVarChange(g_cVarBotAllowShotgunsOnCVarChange);
    
HookConVarChange(g_cVarBotAllowSubMachineGunsOnCVarChange);
    
HookConVarChange(g_cVarBotAllowSnipersOnCVarChange);
    
HookConVarChange(g_cVarBotAllowGrenadesOnCVarChange);
    ...
}

public 
OnCVarChange(Handle:convar_hndl, const String:oldValue[], const String:newValue[])
{
    
ServerCommand("bot_pistols_only");


Last edited by ~Gh05t~; 04-17-2009 at 09:09.
~Gh05t~ is offline
Send a message via ICQ to ~Gh05t~
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 04-17-2009 , 10:01   Re: Make shure that a cvar is always set
Reply With Quote #6

As I told you. I just didn't know that it is something like command
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
RM_Hamster
SourceMod Donor
Join Date: Jul 2008
Location: MA
Old 04-17-2009 , 19:42   Re: Make shure that a cvar is always set
Reply With Quote #7

Instead of OnConfigsExecuted, you might have more luck using OnAutoConfigsBuffered.
RM_Hamster 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:31.


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