Page 1 of 1

Scoreboard Question

PostPosted: Thu Dec 07, 2006 8:48 am
by zlehmann
this might be a problem not involving the scoreboard, im not sure. i got my teams menu up and running but when i pick a team the scoreboard doesnt show any change. i assume because i based my mod off the deathmatch game that there are no teams or i have to change some code to make the active.

i really am trying to get the hang of codding, instead of asking for the code to get this to work, can someone just point me at the files i would have to look at? again the team menu comes up fine, although its after the motd for some reason, but when i choose teams nothing really changes. could it be a map thing? i tried making a map with 2 team spawns one for combine and one for rebels but i get errors and cant get it to compile correctly. any help is appreciated!

p.s. i got a clip system in my mod for my weapons! progress is awesome lol

PostPosted: Thu Dec 07, 2006 1:32 pm
by Bob
go search for scoreboard in the projects, you'll see what you are looking for there.

PostPosted: Thu Dec 07, 2006 2:50 pm
by zlehmann
are you sure its a scoreboard problem? if i put spawn points in the map for the 2 teams the map wont run. It doesnt seem to reconize the info_player_REBELS and COMBINE entities

PostPosted: Thu Dec 07, 2006 5:13 pm
by Bob
[15:48] Zakarius83: hey, you got a minute?
[15:48] The Advocate SB: sup
[15:48] Zakarius83: i got my team menu working but i dont think there are actually teams
[15:49] The Advocate SB: why not?
[15:49] Zakarius83: ive been going through the code and all the stuff on the scoreboard that talks about teams refrences IsTeamplay() function
[15:49] Zakarius83: but i cant find what im supposed to change
[15:49] Zakarius83: well heres what happens
[15:49] Zakarius83: i can run the game if there is a info_player_start entity on the map, or the deathmatch one
[15:50] Zakarius83: but if i use the info_player_combine/rebel entity i get an error and the game crashes
[15:50] Zakarius83: but the map compiles fine
[15:50] Zakarius83: so something in my code isnt letting there be teams
[15:51] The Advocate SB: hold on a second
[15:51] Zakarius83: sure
[15:54] The Advocate SB: Oaky let me read this
[15:57] The Advocate SB: sorry
[15:58] The Advocate SB: martin sargeant is drawing my attention
[15:58] Zakarius83: oh its ok, take your time
[15:58] The Advocate SB: isteamplay
[15:59] Zakarius83: ?
[15:59] The Advocate SB: overwrite that funcion
[15:59] The Advocate SB: by default the function returns false or 0
[15:59] The Advocate SB: somehting like that
[16:00] Zakarius83: so just write it in so it returns something else?
[16:00] The Advocate SB: something like that
[16:02] Zakarius83: mine says return true; in it
[16:02] The Advocate SB: there should be another one
[16:03] Zakarius83: ah ha
[16:03] Zakarius83: i think i found it

PostPosted: Thu Dec 07, 2006 6:21 pm
by Baer
There is a scoreboard tut on wavelength. It helped me putting my team names on the scoreboard. One warning though, be careful what you change or add, because you can royally mess up the scoreboard.

PostPosted: Sun Dec 10, 2006 10:53 pm
by Wildfire
If you are using the Deathmatch SDK, the scoreboard is already complete and fully functioning.

What you want to do is force teamplay. I've reworked the Creating Teams tutorial on the wiki, it should help you with all of your team-related troubles now.

http://www.gneu.org/wiki/index.php?title=Creating_Teams

PostPosted: Mon Dec 11, 2006 2:44 pm
by zlehmann
SIR I WOULD LOVE TO SHAKE YOUR HAND! It totally works, thank you so much. I did run into one problem though. In the Player.cpp file i got errors from your added function about the TEAM_REBELS and COMBINE being unitified or something. I commented out those lines and it appears to work fine. Any idea why that happened?

I think it may be I only followed your tut for the forcing teamplay part as I already had team menus and such.

PostPosted: Mon Dec 11, 2006 3:48 pm
by Wildfire
Which lines did you comment out to make it work? You're talking about what goes in the CBasePlayer::ClientCommand function in player.cpp, right?

Mine looks like this:
Code: Select all
else if ( stricmp( cmd, "jointeam" ) == 0 ) //start jointeam
{
   if ( engine->Cmd_Argc() < 2 )
      return true;
 
   int team = atoi( engine->Cmd_Argv(1) );
 
   //dont do anything if you join your own team
   if ( team == GetTeamNumber() )
      return true;
 
   //auto assign if you join team 0
   if ( team == 0 )
   {
      if ( g_Teams[TEAM_COMBINE]->GetNumPlayers() > g_Teams[TEAM_REBELS]->GetNumPlayers() )
         team = TEAM_REBELS;
      else
         team = TEAM_COMBINE;
   }

   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

Doesnt look much different than whats on the wiki but I know it works so I'll replace the one that was up there.


Also, I edited the tutorial and added a small bit in the Final Touches section about adding some code to the end of function CHL2MP_Player::Spawn in hl2mp_player.cpp, which should get rid of the red 1 hp health indicator when you first connect.

PostPosted: Mon Dec 11, 2006 6:49 pm
by zlehmann
That section right in the middle that references TEAM_COMBINE and TEAM_REBELS, any line that had those in it I commented out and it worked just fine.

PostPosted: Mon Dec 11, 2006 10:21 pm
by Bob
That may have been a mistake.

You should change those lines over to your TEAM_ defines.

PostPosted: Tue Dec 12, 2006 6:05 am
by zlehmann
I'm not sure what you mean by TEAM_defines. Sorry I'm a newb!

BLASTS!!! ok so it doesn't quite work yet. The scoreboard and team select stuff works perfectly but there is still the same problem I had before with the spawn points. Whenever I make a map that has rebel and combine spawn points instead of normal player start points the game crashes right before it finishes loading.

Please someone tell me they know whats going on!!

Team Defines & Spawn Point Selection

PostPosted: Tue Dec 12, 2006 11:22 am
by Bob
If you are using an MP mod, ~ line 29 or so of hl2mp_gamerules.h

Code: Select all
enum
{
   TEAM_COMBINE = 2,
   TEAM_REBELS,
};


You should see something like that. These are your team defines. There are three others, in shareddefs.h

Code: Select all
//===================================================================================================================
// Team Defines
#define   TEAM_INVALID         -1
#define TEAM_UNASSIGNED         0   // not assigned to a team
#define TEAM_SPECTATOR         1   // spectator team


You may have changed these OR you need to include hl2mp_gamerules.h

As for the game crashing, its probably because you haven't got the teams set up properly. There is some code that finds an open spawn point right before you spawn, and its not finding one because you are not on a specified team. look inside hl2mp_player.cpp(SERVER)

Code: Select all
CBaseEntity* CHL2MP_Player::EntSelectSpawnPoint( void )
{
   CBaseEntity *pSpot = NULL;
   CBaseEntity *pLastSpawnPoint = g_pLastSpawn;
   edict_t      *player = edict();
   const char *pSpawnpointName = "info_player_deathmatch";

   if ( HL2MPRules()->IsTeamplay() == true )
   {
      if ( GetTeamNumber() == TEAM_COMBINE )
      {
         pSpawnpointName = "info_player_combine";
         pLastSpawnPoint = g_pLastCombineSpawn;
      }
      else if ( GetTeamNumber() == TEAM_REBELS )
      {
         pSpawnpointName = "info_player_rebel";
         pLastSpawnPoint = g_pLastRebelSpawn;
      }

      if ( gEntList.FindEntityByClassname( NULL, pSpawnpointName ) == NULL )
      {
         pSpawnpointName = "info_player_deathmatch";
         pLastSpawnPoint = g_pLastSpawn;
      }
   }

   pSpot = pLastSpawnPoint;
   // Randomize the start spot
   for ( int i = random->RandomInt(1,5); i > 0; i-- )
      pSpot = gEntList.FindEntityByClassname( pSpot, pSpawnpointName );
   if ( !pSpot )  // skip over the null point
      pSpot = gEntList.FindEntityByClassname( pSpot, pSpawnpointName );

   CBaseEntity *pFirstSpot = pSpot;

   do
   {
      if ( pSpot )
      {
         // check if pSpot is valid
         if ( g_pGameRules->IsSpawnPointValid( pSpot, this ) )
         {
            if ( pSpot->GetLocalOrigin() == vec3_origin )
            {
               pSpot = gEntList.FindEntityByClassname( pSpot, pSpawnpointName );
               continue;
            }

            // if so, go to pSpot
            goto ReturnSpot;
         }
      }
      // increment pSpot
      pSpot = gEntList.FindEntityByClassname( pSpot, pSpawnpointName );
   } while ( pSpot != pFirstSpot ); // loop if we're not back to the start

   // we haven't found a place to spawn yet,  so kill any guy at the first spawn point and spawn there
   if ( pSpot )
   {
      CBaseEntity *ent = NULL;
      for ( CEntitySphereQuery sphere( pSpot->GetAbsOrigin(), 128 ); (ent = sphere.GetCurrentEntity()) != NULL; sphere.NextEntity() )
      {
         // if ent is a client, kill em (unless they are ourselves)
         if ( ent->IsPlayer() && !(ent->edict() == player) )
            ent->TakeDamage( CTakeDamageInfo( GetContainingEntity(INDEXENT(0)), GetContainingEntity(INDEXENT(0)), 300, DMG_GENERIC ) );
      }
      goto ReturnSpot;
   }

   if ( !pSpot  )
   {
      pSpot = gEntList.FindEntityByClassname( pSpot, "info_player_start" );

      if ( pSpot )
         goto ReturnSpot;
   }

ReturnSpot:

   if ( HL2MPRules()->IsTeamplay() == true )
   {
      if ( GetTeamNumber() == TEAM_COMBINE )
      {
         g_pLastCombineSpawn = pSpot;
      }
      else if ( GetTeamNumber() == TEAM_REBELS )
      {
         g_pLastRebelSpawn = pSpot;
      }
   }

   g_pLastSpawn = pSpot;

   m_flSlamProtectTime = gpGlobals->curtime + 0.5;

   return pSpot;
}


or player.cpp (SERVER)
Code: Select all
CBaseEntity *CBasePlayer::EntSelectSpawnPoint()
{
   CBaseEntity *pSpot;
   edict_t      *player;

   player = edict();

// choose a info_player_deathmatch point
   if (g_pGameRules->IsCoOp())
   {
      pSpot = gEntList.FindEntityByClassname( g_pLastSpawn, "info_player_coop");
      if ( pSpot )
         goto ReturnSpot;
      pSpot = gEntList.FindEntityByClassname( g_pLastSpawn, "info_player_start");
      if ( pSpot )
         goto ReturnSpot;
   }
   else if ( g_pGameRules->IsDeathmatch() )
   {
      pSpot = g_pLastSpawn;
      // Randomize the start spot
      for ( int i = random->RandomInt(1,5); i > 0; i-- )
         pSpot = gEntList.FindEntityByClassname( pSpot, "info_player_deathmatch" );
      if ( !pSpot )  // skip over the null point
         pSpot = gEntList.FindEntityByClassname( pSpot, "info_player_deathmatch" );

      CBaseEntity *pFirstSpot = pSpot;

      do
      {
         if ( pSpot )
         {
            // check if pSpot is valid
            if ( g_pGameRules->IsSpawnPointValid( pSpot, this ) )
            {
               if ( pSpot->GetLocalOrigin() == vec3_origin )
               {
                  pSpot = gEntList.FindEntityByClassname( pSpot, "info_player_deathmatch" );
                  continue;
               }

               // if so, go to pSpot
               goto ReturnSpot;
            }
         }
         // increment pSpot
         pSpot = gEntList.FindEntityByClassname( pSpot, "info_player_deathmatch" );
      } while ( pSpot != pFirstSpot ); // loop if we're not back to the start

      // we haven't found a place to spawn yet,  so kill any guy at the first spawn point and spawn there
      if ( pSpot )
      {
         CBaseEntity *ent = NULL;
         for ( CEntitySphereQuery sphere( pSpot->GetAbsOrigin(), 128 ); (ent = sphere.GetCurrentEntity()) != NULL; sphere.NextEntity() )
         {
            // if ent is a client, kill em (unless they are ourselves)
            if ( ent->IsPlayer() && !(ent->edict() == player) )
               ent->TakeDamage( CTakeDamageInfo( GetContainingEntity(INDEXENT(0)), GetContainingEntity(INDEXENT(0)), 300, DMG_GENERIC ) );
         }
         goto ReturnSpot;
      }
   }

   // If startspot is set, (re)spawn there.
   if ( !gpGlobals->startspot || !strlen(STRING(gpGlobals->startspot)))
   {
      pSpot = FindPlayerStart( "info_player_start" );
      if ( pSpot )
         goto ReturnSpot;
   }
   else
   {
      pSpot = gEntList.FindEntityByName( NULL, gpGlobals->startspot );
      if ( pSpot )
         goto ReturnSpot;
   }

ReturnSpot:
   if ( !pSpot  )
   {
      Warning( "PutClientInServer: no info_player_start on level\n");
      return CBaseEntity::Instance( INDEXENT( 0 ) );
   }

   g_pLastSpawn = pSpot;
   return pSpot;
}

PostPosted: Tue Dec 12, 2006 11:49 am
by zlehmann
but you pick a team before you spawn so wouldnt that part not matter?

i tried including that file but then i got like 150 errors so i changed it back. all my indentifiers are there, havent changed anything. this is the exact message i get when i uncomment those lines. and i think it will fix my spawning problem too.

in player.cpp (server) i get this
error C2065: 'TEAM_COMBINE' : undeclared identifier
.\player.cpp(5811) : error C2227: left of '->GetNumPlayers' must point to class/struct/union/generic type
.\player.cpp(5811) : error C2065: 'TEAM_REBELS' : undeclared identifier
.\player.cpp(5811) : error C2227: left of '->GetNumPlayers' must point to class/struct/union/generic type


this makes no sense to me, aren't those referenced somewhere else in the same file?

PostPosted: Tue Dec 12, 2006 1:23 pm
by Wildfire
zlehmann wrote:but you pick a team before you spawn so wouldnt that part not matter?

No, it does matter because when you spawn as a spectator you are still technically spawning.
Your map needs AT LEAST one info_player_start as well as the team spawns so that the game knows where to spawn spectators when they first connect.


I don't see why you would have gotten any errors for including that gamerules header. Just ADD
Code: Select all
#include "hl2mp_gamerules.h"

exactly one line BELOW
Code: Select all
#include "rumble_shared.h"

in player.cpp and it should compile without errors.

PostPosted: Tue Dec 12, 2006 2:26 pm
by zlehmann
YESSSS!!! ah thank you guys so much, that was sooo annoying! I finally have working teams!

PostPosted: Tue Dec 12, 2006 3:33 pm
by Bob
I would highly suggest that you start experimenting with the code, and actually do some C++ reading because this is not going to get any easier.