Tutorial *137*
If you did my qcexec tutorial, you probably noticed that at the bottom of the function we modified in sv_user.c just Dprints to the server console that the cmd the user tried to issue was invalid (well I noticed). I dunno about you, but I think that is a serious waste of good info. In this tutorial we'll make an unrecognized cmd be forwarded to the QC, so mod authors can do what they like with the info. I sure think "cmd addbot" is a lot better than remembering "impulse 100". Anyway, to get started open up sv_user.c again, scroll to SV_ReadClientMessage. At the top of the function, add this little declaration:

eval_t	*val; // CMDTUT

Now scroll down to the lines:


	Con_DPrintf("%s tried to %s\n", host_client->name, s);

Replace all that with this mess:



	val = GetEdictFieldValue(sv_player, "cmd");

	if (val)


		s[30] = 0; // stop overflows, truncate at 30

		Q_strcpy (host_client->hcmd, s);

		val->string =  host_client->hcmd - pr_strings;


	//Con_DPrintf("%s tried to %s\n", host_client->name, s);


I cheated a bit with this code. You see, I could simply set val->string = s - pr_strings, but that is only a local pointer and could be over written with another cmd occurring in the same frame. Instead, we copy it off into the client struct for safe keeping. Now to simply add the storage space to the client_t struct, open up server.h find the line that reads

// client known data for deltas

	int				old_frags;

and after it add:

	char			hcmd[32]; // CMDTUT

Okay this is not a pretty solution, I agree, but it works. Let's do something practical in the QC with it. Open up defs.qc and at the very bottom add:

.string	cmd;

Save & close, move onto weapons.qc, scroll over to ImpulseCommands (idealy there should be a special function to check for cmd's, but ImpulseCommands will have to do for now) then add this stuff at the top of the function:

if (self.cmd != "")


	if (self.cmd == "prevwep")

		self.impulse = 12;

	else if (self.cmd == "nextwep")

		self.impulse = 10;

	else if (self.cmd == "quad")

		self.impulse = 255;

	else if (self.cmd == "cheat")

		self.impulse = 9;




		dprint(" tried to ");




	self.cmd = "";


I used setting self.impulse as a shortcut. Obviously, you could put in any code you want. Compile that, open up your modified Quake with the patch, and you should be able to give yourself quad simply by typing "cmd quad" on the console. Any suggestions on this tutorial, don't hesitate to email me. Thanks.

Not logged in
Sign up