AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   register_cvar() and get_pcvar_num() (https://forums.alliedmods.net/showthread.php?t=205620)

hypheni 01-12-2013 14:25

register_cvar() and get_pcvar_num()
 
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 ?

YamiKaitou 01-12-2013 14:33

Re: register_cvar() and get_pcvar_num()
 
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

hypheni 01-12-2013 14:43

Re: register_cvar() and get_pcvar_num()
 
Okay.

Actually what I want is depending on a cvar value start a timer(continuous timer). So what is best function in my case ?

fysiks 01-12-2013 22:12

Re: register_cvar() and get_pcvar_num()
 
Actually, this should work after the map has been changed once. On first boot it will not.

hypheni 01-13-2013 00:43

Re: register_cvar() and get_pcvar_num()
 
^^Correct. This is what happening. But where should I put this stuff which will work everytime ?

fysiks 01-13-2013 01:58

Re: register_cvar() and get_pcvar_num()
 
Read the cvar in plugin_cfg().

hypheni 01-13-2013 02:24

Re: register_cvar() and get_pcvar_num()
 
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

AngeIII 01-13-2013 09:08

Re: register_cvar() and get_pcvar_num()
 
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)

hypheni 01-13-2013 09:56

Re: register_cvar() and get_pcvar_num()
 
Can anyone show me a quick version of reading own cfg and reflecting that changes to registered cvars ?

fysiks 01-13-2013 15:00

Re: register_cvar() and get_pcvar_num()
 
Quote:

Originally Posted by hypheni (Post 1872787)
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.


All times are GMT -4. The time now is 13:37.

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