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

Enumeration ConVar Class


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stickz
Senior Member
Join Date: Oct 2012
Location: Ontario, Canada
Old 08-03-2015 , 17:36   Enumeration ConVar Class
Reply With Quote #1

Is it possible to Enumerate the ConVar class? If so, how do I do it?

I tried something like this, and it was an invalid directive.

Code:
#pragma semicolon 1

enum convars
{
      cvar1,
      cvar2,
      cvar3,
      cvar4
};

Convar g_cvar[convars];

Last edited by stickz; 08-03-2015 at 17:39.
stickz is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-03-2015 , 17:54   Re: Enumeration ConVar Class
Reply With Quote #2

seems like this works:

PHP Code:
enum convars
{
      
ConVar:cvar1,
      
ConVar:cvar2,
      
ConVar:cvar3,
      
ConVar:cvar4
}

ConVar g_cvar[convars]; 
edit: or the proper way:

PHP Code:
enum
{
      
cvar1,
      
cvar2,
      
cvar3,
      
cvar4,
      
convars
}

ConVar g_cvar[convars]; 

Last edited by Miu; 08-03-2015 at 18:00.
Miu is offline
stickz
Senior Member
Join Date: Oct 2012
Location: Ontario, Canada
Old 08-04-2015 , 12:32   Re: Enumeration ConVar Class
Reply With Quote #3

In the end I got it working like this.
Code:
enum convars
{
	 ConVar:cvar1,
	 ConVar:cvar2,
	 ConVar:cvar3,
	 ConVar:cvar4
};

ConVar g_cvar[convars];
I wanted to loop through all my convars on plugin start, check if they are null then add change hooks to each of them. But I can't seem to find enum documentation anywhere; specially to get the size of the enum, so I just added length as my best guess.

Code:
public OnPluginStart()
{
      g_cvar[cvar1]   =  CreateConVar("sm_cvar_one", "1", "description here);
      g_cvar[cvar2]   =  CreateConVar("sm_cvar_two", "1", "description here);
      g_cvar[cvar3]   =  CreateConVar("sm_cvar_three", "1", "description here);
      g_cvar[cvar4]   =  CreateConVar("sm_cvar_four", "1", "description here);

      for (new cIDX = 0; cIDX < convars.length; cIDX++)
      {
            if(g_cvar[cIDX] != null)
            {
                  g_cvar[cIDX].AddChangeHook(OnConvarChanged);
            }
      }
}

Last edited by stickz; 08-04-2015 at 12:47.
stickz 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 13:00.


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