Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/sites/a/articles.thewavelength.net/public_html/utils/sql.php on line 20
Wavelength | Your Game Editing Resource | Team Spawn Points Fixed!
Welcome, Guest! Login | Register

Team Spawn Points Fixed! [Print this Article]
Posted by: Put Put Cars
Date posted: Aug 29 2003
User Rating: 3 out of 5.0
Number of views: 8957
Number of comments: 32
Description: Bigguys Team Spawn Points had a couple of errors, so here is how your fix them.
Original tut: http://hlpp.telefragged.com/tuts/teamspawn.htm
First, to make these work, you must complete this tutorial on Teams: http://elife.5u.com/teamstutorialsdk22.html


First, go to subs.cpp Look for this line:

 CODE (C++) 
LINK_ENTITY_TO_CLASS(info_player_deathmatch,CBaseDMStart);



Under that put these new entities. Each of these will act as our team and observer spawn points:


 CODE (C++) 
LINK_ENTITY_TO_CLASS(info_player_observer,CBaseDMStart);
LINK_ENTITY_TO_CLASS(info_player_team1,CBaseDMStart);
LINK_ENTITY_TO_CLASS(info_player_team2,CBaseDMStart);


Now, we need to add a new function to choose our spawn location. Look for this in player.cpp:

 CODE (C++) 
extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer );

Underneath that add this:


 CODE (C++) 
extern edict_t *EntSelectTeamSpawnPoint( CBaseEntity *pPlayer );


Ok, that declares our new function for choosing spawn points. You need to also declare it in
gamerules.cpp, so add under the includes:


 CODE (C++) 
extern edict_t *EntSelectTeamSpawnPoint( CBaseEntity *pPlayer );


Also in gamerules.cpp, in GetPlayerSpawnSpot():

 CODE (C++) 
edict_t *pentSpawnSpot = NULL;
if (g_pGameRules->IsTeamplay())
    pentSpawnSpot = EntSelectTeamSpawnPoint( pPlayer );
else

    pentSpawnSpot = EntSelectSpawnPoint( pPlayer );



Just replace the old EntSelectSpawnPoint() with that.

Now for the big change. We need to add the body of the function to player.cpp, and at the top, add:

 CODE (C++) 
#include "teamplay_gamerules.h"


Look for the old EntSelectSpawnPoint() and put our new function above or below it:


 CODE (C++) 
edict_t *EntSelectTeamSpawnPoint( CBaseEntity *pPlayer )
{
    CBaseEntity *pSpot;
    edict_t *player;

    player = pPlayer->edict();
    CBasePlayer *cbPlayer = (CBasePlayer *)pPlayer; // Get a CBasePlayer

    pSpot = g_pLastSpawn;
    // Randomize the start spot
    for ( int i = RANDOM_LONG(1,5); i > 0; i-- )
    {
        if (FStrEq(cbPlayer->m_szTeamName, TEAM1_NAME)) // if team1
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team1" );
        else if (FStrEq(cbPlayer->m_szTeamName, TEAM2_NAME))// if team2
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team2" );
        else // not team observer
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_observer" );
    }

    if ( FNullEnt( pSpot ) ) // skip over the null point
    {

        if (FStrEq(cbPlayer->m_szTeamName, TEAM1_NAME)) // if team1
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team1" );
        else if (FStrEq(cbPlayer->m_szTeamName, TEAM2_NAME))// if team2
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team2" );
        else // not team observer
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_observer" );
    }


    CBaseEntity *pFirstSpot = pSpot;

    do
    {
        if ( pSpot )
        {
            // check if pSpot is valid
            if ( IsSpawnPointValid( pPlayer, pSpot ) )
            {
                if ( pSpot->pev->origin == Vector( 0, 0, 0 ) )
                {
                   
                    if (FStrEq(cbPlayer->m_szTeamName, TEAM1_NAME)) // if team1
                        pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team1" );
                    else if (FStrEq(cbPlayer->m_szTeamName, TEAM2_NAME))// if team2
                        pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team2" );
                    else // not team observer
                        pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_observer" );
                    continue;
                }

                // valid pSpot, so it can be returned
                goto ReturnSpot;
            }
        }
        // increment pSpot
       
       
        if (FStrEq(cbPlayer->m_szTeamName, TEAM1_NAME)) // if team1
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team1" );
        else if (FStrEq(cbPlayer->m_szTeamName, TEAM2_NAME))// if team2
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team2" );
        else // not team observer
            pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_observer" );

    } 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 ( !FNullEnt( pSpot ) )
    {
        CBaseEntity *ent = NULL;
        while ( (ent = UTIL_FindEntityInSphere( ent, pSpot->pev->origin, 128 )) != NULL )
        {
            // if ent is a client, kill em (unless they are ourselves)
            if ( ent->IsPlayer() && !(ent->edict() == player) )
                ent->TakeDamage( VARS(INDEXENT(0)), VARS(INDEXENT(0)), 300, DMG_GENERIC );
        }
        goto ReturnSpot;
    }

ReturnSpot:
    if ( FNullEnt( pSpot ) )
    {
        ALERT(at_error, "PutClientInServer: no spawn points on level");
        return INDEXENT(0);
    }

    g_pLastSpawn = pSpot;
    return pSpot->edict();
}



That should do it, now compile a map with your team spawn points, and you observer points, and Frag away!

Rate This Article
This article is currently rated: 3 out of 5.0 (2 Votes)

You have to register to rate this article.
User Comments
prev ( 1 [2] ) next Showing comments 20-32


Posted By: Put Put Cars on Sep 19 2003 at 11:45:08
Well you guys must be doing something wrong because It works perfectly when i do the tut.

Posted By: Ratking on Sep 30 2003 at 03:05:22
i find that this bit of code will not go in at the complete bottom.

//=========================================================
// Chip - JoinTeam Function
//=========================================================
void CHalfLifeTeamplay::JoinTeam(CBasePlayer *pPlayer, const char *pTeamName)
{
char text [1024];

//If already on this team, do nothing
if (FStrEq(pPlayer->m_szTeamName, pTeamName))
{
return;
}
//Join the team

//When observer, make it respawnable, let it join a team and then respawn
if ( pPlayer->m_afPhysicsFlags & PFLAG_OBSERVER)
{
// notify everyone of the team change
sprintf( text, "* %s has joined %s\n", STRING(pPlayer->pev->netname), pTeamName );
UTIL_SayText( text, pPlayer );
UTIL_LogPrintf( "\"%s<%i>\" has joined %s\n", STRING( pPlayer->pev->netname ), GETPLAYERUSERID( pPlayer->edict() ), pTeamName );
pPlayer->pev->deadflag = DEAD_RESPAWNABLE;
ChangePlayerTeam( pPlayer, pTeamName, FALSE, FALSE );
// recound stuff
RecountTeams();
pPlayer->Spawn();
}
//Else just switch teams
else
{
// notify everyone of the team change
sprintf( text, "* %s has joined %s\n", STRING(pPlayer->pev->netname), pTeamName );
UTIL_SayText( text, pPlayer );
UTIL_LogPrintf( "\"%s<%i>\" has joined %s\n", STRING( pPlayer->pev->netname ), GETPLAYERUSERID( pPlayer->edict() ), pTeamName );
ChangePlayerTeam( pPlayer, pTeamName, TRUE, TRUE );
// recound stuff
RecountTeams();
}
}
//Chip


Compiling...
teamplay_gamerules.cpp
C:\SIERRA\Half-Life\SDK\Multiplayer Source\dlls\teamplay_gamerules.cpp(628) : error C2039: 'JoinTeam' : is not a member of 'CHalfLifeTeamplay'
C:\SIERRA\Half-Life\SDK\Multiplayer Source\dlls\teamplay_gamerules.h(30) : see declaration of 'CHalfLifeTeamplay'
C:\SIERRA\Half-Life\SDK\Multiplayer Source\dlls\teamplay_gamerules.cpp(630) : error C2601: 'JoinTeam' : local function definitions are illegal
Error executing cl.exe.

teamplay_gamerules.obj - 2 error(s), 0 warning(s)

Posted By: Put Put Cars on Oct 02 2003 at 18:40:05
add virtual void JoinTeam(CBasePlayer *pPlayer, const char *pTeamName) to teamplay_gamerules.h in the declaration of 'CHalfLifeTeamplay' , DUH

Posted By: SanguiS on Oct 14 2003 at 01:31:24
Yay it works kinda wierd tutorial as it seems for a lot of people not to work out the first time :PEdited by SanguiS on Oct 14 2003, 02:21:27

Posted By: mathew on Oct 14 2003 at 15:03:43
You may not have to if you use coustom maps they can have an object that blocks monsters

Posted By: Dark_Matter on Mar 20 2004 at 05:50:39
Anyone know how to get spawn points to work in SOHL 1.2?

I've done the whole thing 3-4 times in SDK 2.3 and every time worked

In SOHL I have tried it about 10 + times and can't get the spawn points to work.

When i run a game and join a team if gives me the

no spawn points on level

Even when there are spawn points.

The exact same map works with my sdk 2.3 dlls but not with my SOHL 1.2 dlls that have the code.

I'm pretty sure that something the ppl did over at spirit is what is messing them up. Anyone got time to go through and find out how to make these spawn points work with SOHL 1.2 ?

PLEASE!!!!

Posted By: Ender on Jun 03 2004 at 03:37:19
I get a errer in file "hud_spectator.cpp" =

\hud_spectator.cpp(1079): error C2668: 'sqrt' : ambiguous call to overloaded function

when i try to compile my client side dll.

help please =(

Posted By: Ender on Jun 03 2004 at 03:38:14
o and i never edited the file either if anyones wondering

Posted By: WoW_Nirss on Aug 20 2004 at 03:58:16
Thank you, this has saved me lots of time of de bugging.

Posted By: djlorenzo on Apr 29 2005 at 09:38:44
hey guys, i don't know if anybody still reads this.
but i'm working on a half-life1 mod and when i do this tutorial i still spawn in de middle of the map. not on one of the spawnpoints.

i've added this to my .cfg file
@PointClass base(PlayerClass) = info_player_team1 : "Player 1 start" []
@PointClass base(PlayerClass) = info_player_observer: "Player observer start" []
@PointClass base(PlayerClass) = info_player_team2 : "Player 2 start" []

but i dont spawn there, can you help me ?

Posted By: Revvy on May 01 2005 at 15:12:32
You want those definitions in the fgd file your hammer configuration uses, not the cfg.

Posted By: djlorenzo on May 04 2005 at 20:41:52
i fixed it

i changed the edict_t *EntSelectTeamSpawnPoint( CBaseEntity *pPlayer ) to EntSelectSpawnPoint( CBaseEntity *pPlayer )
and just deleted the original EntSelectSpawnPoint( CBaseEntity *pPlayer )

because the EntSelectSpawnPoint was coded the right way for my teams but just wasn't activated i think. i'm a real coding newb and this is the first thing i really found out myself :P sow i'm very happy.

prev ( 1 [2] ) next
You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 05 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
knock knock
General | News
By: MIFUNE | Dec 31 2017
 
knock knock
General | News
By: omega | Dec 22 2016
 
knock knock
General | News
By: MIFUNE | Oct 10 2015
 
New HL HUD Message System
Half-Life | Coding | Shared Tutorials
By: chbrules | Dec 31 2011
 
knock knock
General | News
By: Whistler | Nov 05 2011
 
Particle Engine tutorial part 4
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 18 2010
 
Particle Engine tutorial part 2
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Particle Engine tutorial part 3
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
 
Game Movement Series #2: Analog Jumping and Floating
Half-Life 2 | Coding | Shared Tutorials
By: mars3554 | Oct 26 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009
 

Site Info
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (7 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!