Force model update on team change

Locked
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Force model update on team change

Post by bludshot »

I am working on a mod that has two player models only: female and male. On the red team there are 2 skins for female and 2 skins for male to choose from. Same thing on the blue team.

The problem I'm having is when I do /team red to switch from blue team to red team, the model messes up and all I have are legs (my torso disappears). Even if I hit Tab Scores it doesn't fix it (because it's not even deferring).

So when a played changes teams, I'm assuming that I need to somehow execute the code that normally gets executed in q3 when you change your /model - that way the player model will get fixed and not just be a pair of legs running around.

Any clues to how I could achieve this? Or should I be looking into something slightly different to fix this?

Thanks
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Force model update on team change

Post by ^misantropia^ »

First thing that comes to mind is that you probably need to set the new model in ClientUserinfoChanged() in game/g_client.c.
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Force model update on team change

Post by bludshot »

Yeah it's weird the way we have it. Like, we only have two player models: male and female. And each one has two skins per team.

The way you choose which model and skin you have is through a new cvar called racered or raceblue depending on which team you are on.

So if you are on team red, and you are racered 0, you are the female model with the camo skin. Then if you type /racered 3 you will become the male model with the plain skin. And this currently works fine. But if you do racered 3, your actual /model cvar value remains female. Because the code to change models in team games doesn't regard your model cvar, it checks your team and then regards your racered or raceblue depending on which team you are on.

So based on your post, I did actually go in and set the new model in ClientUserinfoChanged() in game/g_client.c. And I set the skin too. But, it has no effect. And to come to think of it, I'm pretty sure I used to have this very same code in there but removed it when I realized it did nothing.

Here is the svn for the code, which is up to date as per this writing (minus the code I just added and then commented out as per your post's suggestion): https://sourceforge.net/projects/alturt/

If you or anybody has the inclination to take a peak at it, the thing to note is that /racered and /raceblue are working great and switch your model and skin fine. It's just that when you switch teams your upper body is invisible. :shrug:

But yeah I'm pretty much stumped.
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Force model update on team change

Post by bludshot »

It seems this problem also occurs when changing racered when you are on blue team (or viceversa) which should not happen, so probably if I fix that it will fix the changing team problem.

When you are on team blue, changing /raceblue is supposed to affect your model and skin (and it does, successfully) but if you change /racered it's not supposed to do anything since you are on blue team not red, but it IS doing something, it's making your upper body disappear

It makes no sense to me because in the code i do checks, like if team == TEAM_BLUE then set the model/skin based on raceblue and ignore racered. But it's sneaking through somewhere or something...
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Force model update on team change

Post by ^misantropia^ »

Come to think of it, you might be facing fundamental issues here. Cvars are either client-side (not visible to other players or the server) or global. Shouldn't you be adding a field or two to the client_t structure and some server side logic or a server command to switch teams/models?
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Force model update on team change

Post by bludshot »

Well I added racered and raceblue to clientInfo_t and then added rr and rb like this:

s = va("n\\%s\\t\\%i\\model\\%s\\hmodel\\%s\\rr\\%d\\rb\\%d\\skin\\%s\\c1\\%s\\c2\\%s\\hc\\%i\\w\\%i\\l\\%i\\skill\\%s\\tt\\%d\\tl\\%d",

...

trap_SetConfigstring( CS_PLAYERS+clientNum, s );


This is in ClientUserinfoChanged in g_client.c


Then in CG_LoadingClient in cg_info.c I do:

Code: Select all

// raceblue blud
		v = Info_ValueForKey( info, "rb" );
		raceblue = atoi( v );

		if ( cgs.gametype >= GT_TEAM )
		{
			if ( team == TEAM_BLUE )
			{
				race = raceblue;
			}
			else //team is red
			{
				race = racered;
			}


			// set model (just for getting the right icon)
			switch( race )
			{
				case 0:
				case 1:		Q_strncpyz( model, "athena", sizeof( model ) );
							break;
				case 2:
				case 3:		Q_strncpyz( model, "orion", sizeof( model ) );
							break;

etc

There's more code regarding this, but that just gives an example of how I am handling it.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Force model update on team change

Post by ^misantropia^ »

Looks sound enough. I could think of a few reasons why things don't work but that will have you chasing ghosts more often than not. It's probably better to whip out the debugger and step through your code.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Force model update on team change

Post by ^misantropia^ »

Maybe one quick check: pre-cache all your models and skins at level load. Do you still have the problem?
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Force model update on team change

Post by bludshot »

I will look into the pre-cache idea soon. But about debugging, how do you step through code? I know about setting break points and stuff in regular windows apps (well tbh last time I did it was in Visual Basic), but how can I do it with a quake 3 mod? (Or is there some document somewhere I could read about this?)

I guess I would have to start compiling the engine too? I'm only compiling cgame and game currently.

Would I also have to run the mod in the normal base directory instead of a mod directory, to like fake it as being the core game? (I just don't get how you would run the debug engine with +fs_game?)
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Force model update on team change

Post by ^misantropia^ »

The way I do it is by compiling both engine and SDK. The engine is not strictly necessary but it makes debugging a hell of a lot easier. I mostly use Eclipse with the C/C++ plugin for the actual debugging. It's as easy as putting a breakpoint somewhere and starting the game in Eclipse's debug mode.
AnthonyJ
Posts: 130
Joined: Wed Nov 15, 2006 7:51 pm

Re: Force model update on team change

Post by AnthonyJ »

It's easy enough to debug just the mod side from Visual Studio.

Open up the properties of the project you want to debug, and go to the "debugging" section. There you can set the executable to debug (give it the full path to quake3.exe), the commandline (to make it load DLLs, use "+set sv_pure 0 +set vm_game 0 +set vm_cgame 0 +set vm_ui 0 +set fs_game YOURMOD"), and the working directory (set to the directory containing quake3.exe).

You'll also want to go into the linker properties, and set the output path to be your mod directory, so that VS drops the DLLs into the right place.

Then hit build, and go. Put breakpoints at the appropriate places and it should stop.

Make sure you're building in debug mode ofc.
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Force model update on team change

Post by bludshot »

Ok, I tried that, but it complains that the binary was not built with debug information and asks if I want to continue debugging. I click Yes and then it comes up with the console window and stops right away with the error Couldn't load default.cfg

Also, where you said do "+set vm_game 0 +set vm_cgame 0 +set vm_ui 0" I left out the vm_ui since I am not changing or compiling the ui dll (I'm stating that in case that makes a difference to this)
AnthonyJ
Posts: 130
Joined: Wed Nov 15, 2006 7:51 pm

Re: Force model update on team change

Post by AnthonyJ »

"Couldn't load default.cfg" means it couldn't find the pak files - which probably means that you didn't set the "working directory" to be the directory where quake3 was.

The message about it not having debug symbols for quake3.exe is normal - either click the "don't tell me about this again" box, or just ignore it. Or if you want, build a debug version of quake3.exe (ie, the engine code), but you shouldn't need that.
Silicone_Milk
Posts: 2237
Joined: Sat Mar 12, 2005 10:49 pm

Re: Force model update on team change

Post by Silicone_Milk »

I'm still amazed that there was a time when I wrote mods using just notepad and the .bat files that came with the SDK. I don't know how I managed without a debugger :D
Locked