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

register_cvar() and get_pcvar_num()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hypheni
Senior Member
Join Date: Jul 2011
Location: India
Old 01-12-2013 , 14:25   register_cvar() and get_pcvar_num()
Reply With Quote #1

PHP Code:
new pCvar

public plugin_init() 
{
pCvar register_cvar("sample_cvar""1")
...
...

if(
get_pcvar_num(pCvar) == 1)
  ..echo 
1
else
  ..echo 
0

From the above snippet I'm always getting pCvar value to be 1 while in amxx.cfg its written: sample_cvar 0

I have tried getting the value using get_cvar_num() and in different places like plugin_cfg() but the result is same. What am I missing here ?

Last edited by hypheni; 01-12-2013 at 14:26.
hypheni is offline
Send a message via Skype™ to hypheni
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-12-2013 , 14:33   Re: register_cvar() and get_pcvar_num()
Reply With Quote #2

amxx.cfg is executed during plugin_cfg, so checking it before then will alter the results. Make sure that the cvar value has actually changed, execute "amx_cvar sample_cvar" and see what it says the value is
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
hypheni
Senior Member
Join Date: Jul 2011
Location: India
Old 01-12-2013 , 14:43   Re: register_cvar() and get_pcvar_num()
Reply With Quote #3

Okay.

Actually what I want is depending on a cvar value start a timer(continuous timer). So what is best function in my case ?
hypheni is offline
Send a message via Skype™ to hypheni
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-12-2013 , 22:12   Re: register_cvar() and get_pcvar_num()
Reply With Quote #4

Actually, this should work after the map has been changed once. On first boot it will not.
__________________
fysiks is offline
hypheni
Senior Member
Join Date: Jul 2011
Location: India
Old 01-13-2013 , 00:43   Re: register_cvar() and get_pcvar_num()
Reply With Quote #5

^^Correct. This is what happening. But where should I put this stuff which will work everytime ?
hypheni is offline
Send a message via Skype™ to hypheni
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-13-2013 , 01:58   Re: register_cvar() and get_pcvar_num()
Reply With Quote #6

Read the cvar in plugin_cfg().
__________________
fysiks is offline
hypheni
Senior Member
Join Date: Jul 2011
Location: India
Old 01-13-2013 , 02:24   Re: register_cvar() and get_pcvar_num()
Reply With Quote #7

Actually that was originally written and not working. Let me show you the original code.

PHP Code:
new amx_showads
new g_ads

public plugin_init() 
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR)
    
    
amx_showads register_cvar("amx_showads""1")
}

public 
plugin_precache()
{
    
g_ads ArrayCreate(128)
}

public 
plugin_cfg()
{
    
load_ini("Ad_File.ini"g_ads)

    if(
get_pcvar_num(amx_showads) == && ArraySize(g_ads) != 0)
    {
        
server_cmd("echo ----Ads ON")
        
set_task(DELAY_ADS"ShowAds"0""0"b")
    }
    else
    {
        
server_cmd("echo Ads OFF")
    } 
Now with this amx_showads is set to 0 in amxx.cfg but while the server is booting as you mentioned already it prints ----Ads ON while it should print ----Ads OFF
hypheni is offline
Send a message via Skype™ to hypheni
AngeIII
Senior Member
Join Date: Sep 2007
Location: Latvia
Old 01-13-2013 , 09:08   Re: register_cvar() and get_pcvar_num()
Reply With Quote #8

create own cfg and execute it inside plugin_cfg
or check your plugins.ini maybe the possition of your plugin is too high you should to take it last.(I think)
__________________
skype: pavle_ivanof
-=ThQ=-
PRIVATE SUPPORT = PAID SUPPORT
AngeIII is offline
Send a message via Skype™ to AngeIII
hypheni
Senior Member
Join Date: Jul 2011
Location: India
Old 01-13-2013 , 09:56   Re: register_cvar() and get_pcvar_num()
Reply With Quote #9

Can anyone show me a quick version of reading own cfg and reflecting that changes to registered cvars ?
hypheni is offline
Send a message via Skype™ to hypheni
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-13-2013 , 15:00   Re: register_cvar() and get_pcvar_num()
Reply With Quote #10

Quote:
Originally Posted by hypheni View Post
Can anyone show me a quick version of reading own cfg and reflecting that changes to registered cvars ?
He didn't say anything about reading a cfg file. He said to execute a cfg file. I don't understand why you are having problems though. It should work fine in plugin_cfg(). Maybe I will test it later to see for myself.
__________________
fysiks 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 07:25.


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