Console Commands/Convars over C++

Hey,
I’m bit new to C++ and tryed making a “Hello world”.
Since the traditional Hello world was easy; I tryed something more complicated - Creating a convar/concommand in c++ that also print’s “Hello world”.
The code:




// Skip rarely used Windows API functions
#define GAME_DLL
#define CLIENT_DLL
#define WIN32_LEAN_AND_MEAN

#pragma comment (linker, "/NODEFAULTLIB:libcmt")

// Headers
#include <GMLuaModule.h>
#include <convar.h>
#include <cdll_int.h>
// Module definition
GMOD_MODULE( Init, Shutdown );
 
// Globals
ILuaInterface* g_Lua;

void testconcommand( const CCommand &args )
{
	g_Lua->Msg("Hello world !
");
}

ConCommand lolatestconcommand("test_concommands", testconcommand, "Says hello to the world", 0);
ConVar lolatestconvar("test_convars", "0", FCVAR_NONE, "Hello world !", 0, 0, 1, 1 );

// Initialization
int Init( lua_State *L )
{
	g_Lua = Lua();
	g_Lua->Msg("gmcl_test loaded sucefully !
");
	return 0;
}
 
 
// Shutdown
int Shutdown( lua_State *L )
{
	return 0;
}


It basicly gives no errors at compiling, but the concommand/convar doesn’t load.
And yes, i am requiring the module.

Here’s how I do it.

[cpp]ICvar *g_ICvar = NULL;
static ConCommand *lua_run_mn = NULL;
ILuaInterface *g_Lua = NULL;

GMOD_MODULE( Open, Close );

void RunLuaMenu( const CCommand &command )
{
g_Lua->RunString( “”, “”, command.ArgS(), true, true );
}

int Open( lua_State *L )
{
g_Lua = Lua();

CreateInterfaceFn VSTDLibFactory = Sys_GetFactory( "vstdlib.dll" );
if ( !VSTDLibFactory )
	Lua()-&gt;Error( "Error getting vstdlib.dll factory.

" );

g_ICvar = ( ICvar* )VSTDLibFactory( CVAR_INTERFACE_VERSION, NULL );
if ( !g_ICvar )
	Lua()-&gt;Error( "Error getting ICvar interface.

" );

lua_run_mn = new ConCommand("lua_run_mn", RunLuaMenu, "Run a Lua command", FCVAR_UNREGISTERED );
g_ICvar-&gt;RegisterConCommand( lua_run_mn );

return 0;

}

int Close(lua_State *L)
{
if ( lua_run_mn ) {
g_ICvar->UnregisterConCommand( lua_run_mn );
delete lua_run_mn;
}
return 0;
}[/cpp]

[cpp]
ICvar * Cvar;
if(!Sys_LoadInterface(“vstdlib”, “VEngineCvar004”, NULL, reinterpret_cast<void**>(&Cvar)))
\error
[/cpp]

Thanks, i’m going to try it - Look’s promising.

Why compromising :v:?

Where i can get cvar headers? O:

Next time, try posting in your own thread, or a thread that’s from this month.

You can get all the SourceSDK stuff from git via https://github.com/ValveSoftware/source-sdk-2013
or you can git clone:



git clone https://github.com/ValveSoftware/source-sdk-2013.git


The file you are looking for is: https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/icvar.h