
|
|
|
|
Basiror was requesting this. 'A god tut' as he put it :)
Ok, lets open up subs.cpp Look for this line:
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:
// BigGuy--Teamplay spawn
LINK_ENTITY_TO_CLASS(info_player_observer,CBaseDMStart);
LINK_ENTITY_TO_CLASS(info_player_team1,CBaseDMStart);
LINK_ENTITY_TO_CLASS(info_player_team2,CBaseDMStart);
// BigGuy--end
Now, we need to add a new function to choose our spawn location. Look for this in player.cpp:
extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer );
Underneath that add this:
// BigGuy--Teamplay spawn
extern edict_t *EntSelectTeamSpawnPoint( CBaseEntity *pPlayer );
// BigGuy--end
Ok, that declares our new function for choosing spawn points. You need to also declare it in
gamerules.cpp (look for the same function). Also in gamerules.cpp in GetPlayerSpawnSpot():
// BigGuy--Teamplay spawn
edict_t *pentSpawnSpot = NULL;
if (g_pGameRules->IsTeamplay())
pentSpawnSpot = EntSelectTeamSpawnPoint( pPlayer );
else
pentSpawnSpot = EntSelectSpawnPoint( pPlayer );
// BigGuy--end
Just replace the old EntSelectSpawnPoint() with that.
Now for the big change. We need to add the body of the function to player.cpp Look for the
old EntSelectSpawnPoint() and put our new function above or below it:
// BigGuy--Teamplay spawn
// Yes I know this uses goto (its the devil!) but I dont see any reason fixing something
// that isnt broke!
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, "TeamONE")) // if team1
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team1" );
else if (FStrEq(cbPlayer->m_szTeamName, "TeamTWO"))// 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, "TeamONE"))
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team1" );
else if (FStrEq(cbPlayer->m_szTeamName, "TeamTWO"))
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team2" );
else
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, "TeamONE"))
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team1" );
else if (FStrEq(cbPlayer->m_szTeamName, "TeamTWO"))
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team2" );
else
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_observer" );
continue;
}
// valid pSpot, so it can be returned
goto ReturnSpot;
}
}
// increment pSpot
if (FStrEq(cbPlayer->m_szTeamName, "TeamONE"))
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team1" );
else if (FStrEq(cbPlayer->m_szTeamName, "TeamTWO"))
pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_team2" );
else
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();
}
// BigGuy--end
Theres your spawn point routine! That should work, I havent completely tested it but I dont
really feel like adding another copy of the SDK. :) If this doesnt work, email me please!
Any questions or suggestions should be sent to me:
bigguy@valveworld.com
![]()