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

Condition on cvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shadow728988
Member
Join Date: Sep 2017
Old 12-31-2019 , 23:03   Condition on cvar
Reply With Quote #1

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
shadow728988 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-31-2019 , 23:20   Re: Condition on cvar
Reply With Quote #2

You can also consider the xvar natives

PHP Code:
g_BulletDmgPtr get_cvar_pointer"bullet_dmg" );

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

__________________

Last edited by Bugsy; 12-31-2019 at 23:29.
Bugsy is offline
shadow728988
Member
Join Date: Sep 2017
Old 01-01-2020 , 00:59   Re: Condition on cvar
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
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
}
shadow728988 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-01-2020 , 01:28   Re: Condition on cvar
Reply With Quote #4

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?
__________________

Last edited by Bugsy; 01-01-2020 at 14:22. Reason: Corrected plugin_init to cfg
Bugsy is offline
shadow728988
Member
Join Date: Sep 2017
Old 01-01-2020 , 03:27   Re: Condition on cvar
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
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..

Last edited by Bugsy; 01-01-2020 at 14:21.
shadow728988 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-01-2020 , 09:10   Re: Condition on cvar
Reply With Quote #6

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.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-01-2020 , 11:56   Re: Condition on cvar
Reply With Quote #7

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.
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-01-2020 , 13:33   Re: Condition on cvar
Reply With Quote #8

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.
__________________
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 08:26.


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