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

Copying ConVars


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 10-17-2010 , 22:35   Copying ConVars
Reply With Quote #1

Hi,

At the moment my ZombieMod plugin uses long prefixes for it's cvars [zombie_] and I'd like to offer an alternative while still keeping the old ones.

What would be the best way to go about it while keeping the cvars in synch with one another, will I really have to check each one in a callback and change the value of the other once I do manage to replicate them all?

Thanks in advance,
c0ld
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
API
Veteran Member
Join Date: May 2006
Old 10-18-2010 , 01:22   Re: Copying ConVars
Reply With Quote #2

You can create all the ConVar's using the same callback, then replace "zombie_" with "", format "zm_" to prefix, and SetConVar.
__________________
API is offline
Send a message via AIM to API
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 10-18-2010 , 18:28   Re: Copying ConVars
Reply With Quote #3

Quote:
Originally Posted by pimpinjuice View Post
You can create all the ConVar's using the same callback, then replace "zombie_" with "", format "zm_" to prefix, and SetConVar.
See I want them to list the same details too, is there copy convar type functionality anywhere already??
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
API
Veteran Member
Join Date: May 2006
Old 10-18-2010 , 22:20   Re: Copying ConVars
Reply With Quote #4

Hmm, details? What I had in mind was this type of setup. Please excuse my psuedo-C

CreateConsoleVariable("zombie_a", "description for a", "1", CallbackGlobal);
CreateConsoleVariable("zm_a", "description for a", "1", CallbackGlobal);
CreateConsoleVariable("zombie_b", "description for b", "2.5", CallbackGlobal);
CreateConsoleVariable("zm_b", "description for b", "2.5", CallbackGlobal);

// global callback
void CallbackGlobal(const char *ConvarName, const char *OldValue, const char *NewValue)
{
// check if ConvarName is prefixed with either zombie_ or zm_, substr() stuff
// if it is prefixed, replace with the counter prefix and bam...
SetConsoleVariable(CounterPrefixedName, NewValue);
}
__________________
API is offline
Send a message via AIM to API
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 10-19-2010 , 05:46   Re: Copying ConVars
Reply With Quote #5

Hey Pimp,

The double declarations is what I'm trying to avoid, I wanted to loop my convar container and create copies which I could alter so even as I add new ones I won't need duplicate declarations.

The Callback I was expecting no matter what as no matter how I duplicate them be it manully with duplicate vars or i find a way to programmaticaly do it they will still be two distinct cvars.

Thanks for your input so far pimpin,
c0ld
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
API
Veteran Member
Join Date: May 2006
Old 10-19-2010 , 16:06   Re: Copying ConVars
Reply With Quote #6

Hmm, I see what you are saying. Maybe you can hook the input of the server console?
PSUEDO
Code:
Hook ServerConsoleInput
OnInput Check for "zombie_"
If found, search within your defined containers, and take action
OnInput Also Check for "zm_"
If found, search containers, set REAL cvar, and block "command not found"
__________________
API is offline
Send a message via AIM to API
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 10-21-2010 , 10:01   Re: Copying ConVars
Reply With Quote #7

I have most of it figured out... The only remaining part I can't seem to get down is how to get a list of my plugins cvars before ConVar_Register is called. They only appear in the list after that call and by then it'll be too late to hitch a free ride on the cvar automation
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 10-21-2010 , 19:22   Re: Copying ConVars
Reply With Quote #8

This code works and doesn't knock out anything else but none of the new cvars show up in 'meta cvars' nor do they act like cvars, I've tried changing paernt to the convar itself with the same result.

Any ideaS?

Code:
	#if defined ORANGEBOX_BUILD
		/* NOTE! g_pCvar must be set to a valid ICvar instance first. */
		g_pCVar = m_CVar;
		ConVar_Register(0, &g_Accessor);
	#else
		ConCommandBaseMgr::OneTimeInit(&g_Accessor);
	#endif

	ConCommandBase *pStart= m_CVar->GetCommands();
	while (pStart)
	{
		if ( !pStart->IsCommand() )
		{
			ConVar *pVar = (ConVar *)pStart;
			char *sPrefix = "";
			const char *sName = pVar->GetName();
			if ( Q_strncmp( sName, "zombie_", 7 ) == 0 )
			{
				char sNewVar[100] = "";
				char sVarName[100] = "";
				Q_strncpy( sNewVar, "zm_", 100 );
				Q_StrRight( sName, Q_strlen( sName ) - 7, sVarName, 100 );
				Q_strncat( sNewVar, sVarName, 100, Q_strlen( sVarName ) );
				META_LOG( g_PLAPI, "Convar - %s", sNewVar );
				float fMax = 0;
				float fMin = 0;
				pVar->GetMin(fMin);
				pVar->GetMax(fMax);

				
				ConVar *pNewVar = new ConVar(sNewVar, pVar->GetDefault(), pVar->m_nFlags);
				
				pNewVar->m_pParent = pVar->m_pParent;
				pNewVar->m_pszHelpString = pVar->GetHelpText();
				pNewVar->m_bHasMin = pVar->m_bHasMin;
				pNewVar->m_fMinVal = fMin;
				pNewVar->m_bHasMax = pVar->m_bHasMax;
				pNewVar->m_fMaxVal = fMax;
				pNewVar->InstallChangeCallback ( CVar_CallBack );

				m_CVar->RegisterConCommand( (ConCommand *)pNewVar );
				m_ConVars.AddToHead(pNewVar);
			}

		}
		pStart = const_cast<ConCommandBase *>(pStart->GetNext());
	}

	ConVar_Register(0, &g_Accessor);
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 10-21-2010 , 23:52   Re: Copying ConVars
Reply With Quote #9

I've sort of solved it...

Code:
#define CreateConvar( sName, sDefault, lFlags, sHelp, bMin, fMin, bMax, fMax, oCallback ) \
	ConVar zm_##sName("zm_##sName", sDefault, lFlags, sHelp, bMin, fMin, bMax, fMax,oCallback ); \
	ConVar zombie_##sName("zombie_##Name", sDefault, lFlags, sHelp, bMin, fMin, bMax, fMax, oCallback );
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
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 00:21.


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