PDA

View Full Version : Not spawning player till they have chosen a class


Temerity
07-24-2007, 02:04 AM
I did both the team and class menu tutorials off the gneu wiki, I got them both working right but I wanted to tweak it a little bit.

Basically I don't want the player to spawn until they have a class. So after the player chooses their team, they get taken to the class selection menu, and only after they choose their class will they spawn. Same thing if they change teams. I don't want the player to be able to press cancel on the class selection screen and be in the game with no weapons etc...

I suppose though if the player wanted to change their class midway through a game and bring up the classmenu, as long as they have a class, then they can press cancel and get out of the menu.

I tried a bunch of stuff but I couldn't get it to work right, I think I could maybe get it working if I put a bunch of the code on the server side, but it seems to me that it would be much more efficient to do it client side.

Hopefully everyone is following me! If you played TFC, that is basically what I want, thanks!

StuD-tos
07-24-2007, 07:04 AM
put a condition in the ::Spawn method in hlmp_player or SDK_player, if it's false make the player a spectator.

Temerity
07-25-2007, 10:04 PM
I managed to get it working.

Basically all I did was move the HandleCommand_JoinTeam( int teamnum ); call to the code that handles the joinclass command.

I was having trouble getting the joinclass part of the function the right teamnumber, so I also added a private int playerteamnum variable to the mp_player.h

Final product:

bool CHL2MP_Player::ClientCommand( const char *pcmd )
{
.
.
.
else if ( FStrEq( pcmd, "jointeam" ) )
{
if ( engine->Cmd_Argc() < 2 )
{
Warning( "Player sent bad jointeam syntax\n" );
}

if ( ShouldRunRateLimitedCommand( pcmd ) )
{
playerTeamNum = atoi( engine->Cmd_Argv(1) );
//HandleCommand_JoinTeam( iTeam );
engine->ServerCommand( "chooseclass\n" );
}
return true;
}
else if ( stricmp( pcmd, "joinclass" ) == 0 )
{
if (engine->Cmd_Argc() < 2 )
return true;

int iclass = atoi( engine->Cmd_Argv(1) );

//don't change cuz its the same class
if (iclass == GetClass())
return true;

ChangeClass( iclass );

RemoveAllItems( true );

EquipSuit();

//Now join the right team, and give you the right weapons...

HandleCommand_JoinTeam( playerTeamNum );
.
.
.

So all the jointeam command does is put the player's team in a variable and bring up the class menu. So whenever the player change's teams they will also be asked for a new class, which is fine. And if the player hits cancel on the class menu, they will just stay as a spectator, and have to bring up the team menu again to get in the game.