AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Condition on cvar (https://forums.alliedmods.net/showthread.php?t=320627)

shadow728988 12-31-2019 23:03

Condition on cvar
 
Suppose a plugin has a cvar which is turned on for eg. "bullet_dmg 1".
Is it possible to check this cvar in another plugin?
Like if bullet_dmg is 1 show a message to admin

Bugsy 12-31-2019 23:20

Re: Condition on cvar
 
You can also consider the xvar natives

PHP Code:

g_BulletDmgPtr get_cvar_pointer"bullet_dmg" );

if ( 
get_pcvar_numg_BulletDmgPtr ) == )
{
     
//do something



shadow728988 01-01-2020 00:59

Re: Condition on cvar
 
Quote:

Originally Posted by Bugsy (Post 2678605)
You can also consider the xvar natives

PHP Code:

g_BulletDmgPtr get_cvar_pointer"bullet_dmg" );

if ( 
get_pcvar_numg_BulletDmgPtr ) == )
{
     
//do something



where am i wrong please help..
Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>

new g_racePtr

public plugin_init() {

register_clcmd("say /mode", "SelectStyle", ADMIN_BAN)
g_racePtr = get_cvar_pointer( "fl_on" );

}

public SelectStyle(id)
{
    menu created
}

public menu_handle(id)
 {
  switch(item) {

                case 0: {
                                if ( get_pcvar_num( g_racePtr ) == 1 )
                                    {
                                        set_hudmessage(0, 255, 255, -1.0, 0.0, 0, 1.0, 7.0, 0.1, 0.2)
                                          show_hudmessage(id, "Race is currently on kindly stop the race or wait for it to finish")
                                    }
                                                         

//statments to be executed
}


Bugsy 01-01-2020 01:28

Re: Condition on cvar
 
From a psuedo-code perspective it looks fine, you are retrieving the cvar pointer from an existing cvar at plugin_cfg() and using it in your menu callback. Is it not working? Did you debug at all by console/server printing the get_pcvar_num() return value?

shadow728988 01-01-2020 03:27

Re: Condition on cvar
 
Quote:

Originally Posted by Bugsy (Post 2678611)
From a psuedo-code perspective it looks fine, you are retrieving the cvar pointer from an existing cvar at plugin_init() and using it in your menu callback. Is it not working? Did you debug at all by console/server printing the get_pcvar_num() return value?

No it wasnt working then but i made it work as i registered this cvar as initial value 0 and then used get_pcvar_num

Code:

public plugin_init()
 {
  cvar_race= register_cvat ("fl_on","0")
}
  and then used
    if(get_pcvar_num(cvar_race)==1)
      {
        //statements
}

thank you for your help..

OciXCrom 01-01-2020 09:10

Re: Condition on cvar
 
If you register the cvar in the same plugin, your original question is out of point. You're not using a cvar from a different plugin if you register it again in this one. Make sure the cvar name is correct and the value is really the one you need.

Bugsy 01-01-2020 11:56

Re: Condition on cvar
 
get_cvar_pointer() returns the same value that register_cvar() would return, except it uses an existing CVAR instead of creating new. What I provided is the correct way, you must have implemented it incorrectly.

fysiks 01-01-2020 13:33

Re: Condition on cvar
 
A cvar created by another plugin isn't guaranteed to exist in plugin_init() of a different plugin. Generally, you register cvars in plugin_init() and get cvar pointers in plugin_cfg() so that you know that the cvar is created prior to trying to retrieve the cvar pointer.


All times are GMT -4. The time now is 02:43.

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