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: 5656
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 1-20


Posted By: Jorkapp on Aug 28 2003 at 19:53:19
Be sure to check for grammatical errors and typos, I found quite a number (well, 2) of them.

First, got to subs.cpp Look for this line... (Grammatical Error)

#include "templay_gamerules.h" (That would result in an error)

Posted By: XENO on Aug 28 2003 at 21:04:20
I recommend a few changes... For observers, have it look for "info_player_observer", if it cant find that, make it look for "info_player_deathmatch" and then "info_player_start" ents, for variation. It works quite nicely, I've tried it. Also, you might want to have the part that kills clients that are on the spawn-point, you should have it kill monsters too, if, that is your mod supports monsters in MP. It's just generally a good idea to not have the player spawn inside a gargantua or something...

Other than that, it's great.

Posted By: mr_manzee on Aug 29 2003 at 01:56:15
Jorkapp wrote:
Be sure to check for grammatical errors and typos, I found quite a number (well, 2) of them.

First, got to subs.cpp Look for this line... (Grammatical Error)

#include "templay_gamerules.h" (That would result in an error)



umm, this sorts out the idiots, probably for the better to have it in there

Posted By: Put Put Cars on Aug 29 2003 at 04:04:13
who exactly r u calling an idiot?

Posted By: rkzad on Aug 29 2003 at 04:32:10
I took it as the people who don't read the comments... hence the plural. I don't think it was an attack on you.

Posted By: Put Put Cars on Aug 29 2003 at 15:49:16
oh, ok, I tried to fix the error but it wont show up!

Posted By: Bulk on Aug 29 2003 at 16:39:22
Any edits you make have to be re-approved by a moderator. Won't take long.

Posted By: Entropy on Aug 29 2003 at 17:01:58
OK, apparently I've screwed this up. I attempted to correct the other spelling error, and now the board thinks I'm the author. *sigh* Apologies, Put Put. I'll see if rkzad can fix it. Alternatively, you could resubmit the article and I'll delete this one.

Posted By: Bulk on Aug 29 2003 at 17:13:42
Fixed..

Posted By: Put Put Cars on Aug 29 2003 at 17:36:58
Thank YOu, lol, I fixed the error myself, then sent it in to pending, so ther ewas no need to look for it LOL. But thanx anyways

Posted By: crazycoder on Aug 31 2003 at 11:33:19
I am getting

Linking...
Creating library .\Profilemp/mp.lib and object .\Profilemp/mp.exp
gamerules.obj : error LNK2001: unresolved external symbol "struct edict_s * __cdecl EntSelectSpawnPoint(class CBaseEntity *)" (?EntSelectSpawnPoint@@YAPAUedict_s@@PAVCBaseEntity@@@Z)
player.obj : error LNK2001: unresolved external symbol "struct edict_s * __cdecl EntSelectSpawnPoint(class CBaseEntity *)" (?EntSelectSpawnPoint@@YAPAUedict_s@@PAVCBaseEntity@@@Z)
.\Profilemp/mp.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

When I try to compile it.Edited by crazycoder on Aug 31 2003, 11:33:44

Posted By: Put Put Cars on Aug 31 2003 at 21:23:54
In GetPlayerSpawn Spot in gamerules.cpp did u replace

pentSpawnSpot = EntSelectSpawnPoint( pPlayer );

with


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

pentSpawnSpot = EntSelectSpawnPoint( pPlayer );

Posted By: crazycoder on Aug 31 2003 at 23:40:44
yes

here is the line


/=========================================================
//=========================================================
edict_t *CGameRules :: GetPlayerSpawnSpot( CBasePlayer *pPlayer )
{
edict_t *pentSpawnSpot = NULL;
if (g_pGameRules->IsTeamplay())
pentSpawnSpot = EntSelectTeamSpawnPoint( pPlayer );
else

pentSpawnSpot = EntSelectSpawnPoint( pPlayer );

pPlayer->pev->origin = VARS(pentSpawnSpot)->origin + Vector(0,0,1);
pPlayer->pev->v_angle = g_vecZero;
pPlayer->pev->velocity = g_vecZero;
pPlayer->pev->angles = VARS(pentSpawnSpot)->angles;
pPlayer->pev->punchangle = g_vecZero;
pPlayer->pev->fixangle = TRUE;

return pentSpawnSpot;
}

same error ;\Edited by crazycoder on Aug 31 2003, 23:41:02

Posted By: Put Put Cars on Sep 01 2003 at 00:30:03
Redo the tut , there might be someting missing

Posted By: crazycoder on Sep 01 2003 at 03:17:33
I did it 3 times. no luck ;\

Posted By: crazycoder on Sep 01 2003 at 20:49:15
Any ideas how to fix it?

Posted By: combat on Sep 16 2003 at 01:02:13
Okay when you make a tut to fix a tut, you should just tell the readers to do the tut you are fixing. Then, tell them how to fix it. I will write a fix that works at 3rdlife.net soon...

Posted By: crazycoder on Sep 16 2003 at 12:17:11
i fixed it ages ago

Posted By: combat on Sep 16 2003 at 15:49:07
if you fixed it, you should post a comment telling the other users how to fix it.

Posted By: rkzad on Sep 16 2003 at 17:03:50
'ages ago'... what? Two weeks ago you were asking how to fix it. And yes, you should post the fix. That's the piont of this comment system.

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
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
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Persuter | Aug 02 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009
 
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Persuter | Jul 25 2009
 

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

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!