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

Creating a global cvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dordnung
Veteran Member
Join Date: Apr 2010
Old 01-20-2013 , 09:45   Creating a global cvar
Reply With Quote #1

Hey, i'm trying to create a global cvar. I want to find this cvar e.g on http://www.game-monitor.com/.

What i'm trying:

PHP Code:
ConVar *announcer_version = new ConVar ("annnouncer_version""0.5B"FCVAR_SPONLY|FCVAR_NOTIFY"Announcer Version"); 
and i also tried:

PHP Code:
g_pCVar->Init();

ConVar *announcer_version = new ConVar ("annnouncer_version""0.5B"FCVAR_SPONLY|FCVAR_NOTIFY"Announcer Version");
ConCommandBase *announcer_version_command announcer_version;

#if !defined GAME_HL2 
    
g_pCVar->RegisterConCommand(announcer_version_command);
#else
    
g_pCVar->RegisterConCommandBase(announcer_version_command);
#endif

announcer_version->SetValue("0.5B"); 
But it doesn't work?

Can please anyone help?

greetz

Popoklopsi
__________________

Last edited by dordnung; 01-20-2013 at 09:46.
dordnung is offline
Old and Slow
Senior Member
Join Date: May 2005
Location: Arlington, Texas
Old 01-20-2013 , 13:18   Re: Creating a global cvar
Reply With Quote #2

I have been using this mechanism:

define in global area:

Code:
ConVar announcer_version("annnouncer_version", "0.5B",  FCVAR_SPONLY|FCVAR_NOTIFY, "Announcer Version");
also add in the global area:

Code:
/** 
 * Something like this is needed to register cvars/CON_COMMANDs.
 */
class BaseAccessor : public IConCommandBaseAccessor
{
public:
    bool RegisterConCommandBase(ConCommandBase *pCommandBase) {
	/* Always call META_REGCVAR instead of going through the engine. */
	return (META_REGCVAR(pCommandBase));
    }
} s_BaseAccessor;
In Load(), make sure this is included already:

Code:
GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
after the SH_ADD_HOOKs in Load(), add:

Code:
#if SOURCE_ENGINE >= SE_ORANGEBOX
    g_pCVar = icvar;
    ConVar_Register(0, &s_BaseAccessor);
#else
    ConCommandBaseMgr::OneTimeInit(&s_BaseAccessor);
#endif
Finally your set value:

Code:
announcer_version.SetValue("0.5B");
I didn't use the "new" construction but it should work by adjusting the above.
__________________
.......Chuck |TxA| Old and Slow [AARP]

Last edited by Old and Slow; 01-20-2013 at 13:19.
Old and Slow is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 01-20-2013 , 13:23   Re: Creating a global cvar
Reply With Quote #3

Thanks

honestly i'm only coding a vsp plugin, sry i didn't mentioned that. But i tried it also like you did it, but it didn't work
__________________
dordnung is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 01-24-2013 , 11:38   Re: Creating a global cvar
Reply With Quote #4

PHP Code:

// Globals

ConVar plugin_ver"annnouncer_version""0.5B" );


// In your Load() function after assigning interfaces

g_pCvar->RegisterConCommand((ConCommandBase*)&plugin_ver); 
ajr1234 is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 01-24-2013 , 16:33   Re: Creating a global cvar
Reply With Quote #5

Thanks! Will report status soon^^
__________________
dordnung is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 01-24-2013 , 22:49   Re: Creating a global cvar
Reply With Quote #6

Don't forget to UnregisterConCommand() on Unload or your plugin will crash as the game exits.
ajr1234 is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 01-28-2013 , 17:34   Re: Creating a global cvar
Reply With Quote #7

Thank you very much, i only added the flags "FCVAR_SPONLY|FCVAR_NOTIFY", so it's visible with game-monitor^^

I'm very confused, because i thought i did it just like you^^
__________________
dordnung 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 01:19.


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