I see at least one problem here.

Let's say I do "jointeam 0". It's going to go thru the code and randomly
assign me to a team as you want, but then it's going to fall through to this
code here:

            ChangeTeam( team );

            return true;
        } //end jointeam

And put me back on team 0.

Also, this code:
ChangeTeam( random->RandomInt( TEAM_COMBINE, TEAM_REBELS ) );

Assumes TEAM_REBEL comes after TEAM_COMBINE (which, it does, but not
necessarily safe to assume). A better way would be to switch on a random
number 0 to 1 so that you don't depend on the value of the constants. For
example:

switch(random->RandomInt(0, 1))
{
    case 0:
        ChangeTeam(TEAM_COMBINE);
        break;
    default:
        ChangeTeam(TEAM_REBELS);
        break;
}

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Yorg Kuijs
Sent: Monday, August 04, 2008 5:29 AM
To: Discussion of Half-Life Programming
Subject: [hlcoders] AutoAssign to a team

Hey list,
been trying to get AutoAssign to work, got as far as to making it 
actually join instead of dumping you back into spectate or not working 
at all.. but now I'm stuck
To get autoassign to work I'm employing the basic if teamplay = 1 and 
you join team 0(unassigned) then it's supposed to move you to either 
Rebels or Combine, instead in a teamplay game your not moved so you join 
the game as unnasigned, you then take on the spawnpoints of 
info_player_deathmatch instead of info_player_insertteamname which are 
placed randomly on the map. Also you don't show up on the scoreboard.

The mod is in Ep1 and using the command mp_teamplay each map can be set 
to be either deathmatch or team deatmatch(spawns for teams are in a 
bunker, deathmatch spawns are scattered across the map)

Here's the code I'm using in player.cpp in the function bool 
CBasePlayer::ClientCommand(const char *cmd):

       (code concerning spectate commands above)
        else if ( stricmp( cmd, "jointeam" ) == 0 ) //start jointeam
        {
            if (engine->Cmd_Argc() < 2 )
            return true;
   
            int team = atoi( engine->Cmd_Argv(1) );

            //don't do anything if you join your own team
            if ( team == GetTeamNumber() )
            return true;

            CTeam *pCombine = g_Teams[TEAM_COMBINE];
            CTeam *pRebels = g_Teams[TEAM_REBELS];

            //auto assign if you join team 0
            if ( GetTeamNumber() == 0 )
            {
                if ( HL2MPRules()->IsTeamplay() == true )
                {
                    if ( pCombine == NULL || pRebels == NULL )
                    {
                        ChangeTeam( random->RandomInt( TEAM_COMBINE, 
TEAM_REBELS ) );
                    }
                    else
                    {
                        if ( pCombine->GetNumPlayers() > 
pRebels->GetNumPlayers() )
                        {
                            ChangeTeam( TEAM_REBELS );
                        }
                        else if ( pCombine->GetNumPlayers() < 
pRebels->GetNumPlayers() )
                        {
                            ChangeTeam( TEAM_COMBINE );
                        }
                        else
                        {
                            ChangeTeam( random->RandomInt( TEAM_COMBINE, 
TEAM_REBELS ) );
                        }
                    }
                }
            }
            if ( !IsDead() )
            {
                if ( GetTeamNumber() != TEAM_UNASSIGNED )
                {
                    CommitSuicide();
                    IncrementFragCount(1); //adds 1 frag to balance out 
the 1 subtracted for killing yourself
                }
            }

            ChangeTeam( team );

            return true;
        } //end jointeam
   
    return true;
    }


    return false;

}

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives,
please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders



_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to