Tutorial *143*
Back when I first started playing with QuakeC, years ago, I searched through the entire console command list looking for the command to execute QC functions from the console. Alas there was none. To debug your QC modifications you have to stick in an impulse to perform the function you need and have to remember to take it out by the time you release it. There is a better way:

In this tutorial I'll show you how to add a console command "qcexec" that will perform QC functions from the console. This may or may not work with the QW code (my thought is that it won't). To get started, open up sv_user.c, locating in the function SV_ReadClientMessage there is a large if-else tree accepting all valid commands from a client. Find the lines that read:



else if (Q_strncasecmp(s, "ban", 3) == 0)

     ret = 1;

After them, add:


else if (Q_strncasecmp(s, "qcexec", 6) == 0)

     ret = 1;

So far, so good. Next open up host_cmd.c and after the function Host_Status_f, add this mess of code:


/*

==================

Host_QC_Exec



Execute QC commands from the console

==================

*/

void Host_QC_Exec (void)

{

	dfunction_t *f;



	if (cmd_source == src_command)

	{

		Cmd_ForwardToServer ();

		return;

	}

	if (!developer.value)

		return;

	f = 0;

	if ((f = ED_FindFunction(Cmd_Argv(1))) != NULL)

	{



		pr_global_struct->self = EDICT_TO_PROG(sv_player);

		PR_ExecuteProgram ((func_t)(f - pr_functions));

	}

	else

		Con_Printf("bad function\n");



}


You'll notice the line read if (!developer.value), this is to ensure that the command isn't used for cheating, and only when the developer console variable is set. Okay one final step, we must now register the command with Quake, so scroll all the way down in host_cmd.c, you will see the function Host_Init_Commands at the bottom, after the line:


Cmd_AddCommand ("mcache", Mod_Print);

Add:



Cmd_AddCommand ("qcexec", Host_QC_Exec);

Compile and fire up the modified engine, type developer 1, go into a single player game and type "qcexec GibPlayer" to test it. If all works well, you will be a pile of guts on the start map's brick floor.



 
Sign up
Login:
Passwd:
[Remember Me]