YoYo Administrador
Mensajes : 134 Fecha de inscripción : 12/07/2010 Edad : 33 Localización : Perú
| Tema: Explanation of Spawns Jue Abr 14, 2011 12:54 am | |
| Explanation of Spawns Última actualización: 14 abr 2011 - YoYo [PER]
Descripción
Una breve explicación sobre los Spawns, su funcionamiento y algunas aclaraciones, para mejor comprensión, se recomienda conocer las funciones y procedimientos del juego.
No se entrará en detalles para no confundir al usuario ^^.
Requisitos
Definiciones
- ¿Qué son los Re/spawn?
Hablando por el lado del jugador, spawn es una función que se llama cuando las propiedades/atributos del jugador, vuelven a sus valores iniciales, por ejemplo:
Nombre de clase: player Health: 100. Armorvalue: 0. No longjump module. Model: player.mdl Entre otras cosas.
Erroneamente se dice que Spawn es cuando un jugador "revive", sin embargo, es aceptable, pero no necesariamente tiene que "revivir".
Proceso antes del Spawn:
- Se establecen los atributos iniciales.
- Se establece el model/team por defecto.
- Selecciona un spawnpoint.
- Verifica si spawnpoint es válido.
- Se agrega los weapons y ammos por defecto.
- Spawn.
Respawn es generalmente para los weapons, ammos e items, cuando estos son re-materializados, es decir, pasar de estado "invisible" a "visible".
- ¿Qué es un Spawnpoint?
Es la ubicación seleccionada semi-aleatoriamente, siguiendo un algoritmo y cumpliendo ciertas condiciones.
En Deathmatch tienen como nombre de clase (classname) info_player_deathmatch y cada uno de ellos (como toda entidad) esta representado por un número (índice).
- ¿Cómo se selecciona un Spawnpoint?
- Se selecciona un número aleatorio entre el 1 y el 5.
- Busca un Spawnpoint (partiendo desde el úlitmo Spawnpoint encontrado con anterioridad), la búsqueda se repetirá según el número aleatorio del paso 1.
Aclaración: Imaginar que sólo se cuenta con 10 Spawnpoints y que cada uno tiene un índice del 33 al 42.
Imaginar también que es nuestro primer Spawn (iniciará la busqueda desde el índice 33) y que el número aleatorio seleccionado es el 3.
El spawnpoint seleccionado hasta el momento es el del índice 35, este índice será el inicio de busqueda para el siguiente Spawn y un nuevo número aleatorio será seleccionado.
- En la ubicación del Spawnpoint seleccionado, se comprobará si está libre de jugadores en un radio de 128 unidades, caso contrario, el siguiente Spawnpoint será seleccionado (considerando el ejemplo anterior, sería el índice 36).
- Si no existe ningun Spawnpoint válido, el Spawn será normal, pero los jugadores en un radio de 128 serán asesinados.
- Si no existe ningun Spawnpoint (info_player_deathmatch) en el mapa, el Spawn será en info_player_start.
Source code
Todo lo anterior esta representado en el lenguaje de programación C/C++. Código proveniente de player.cpp
Selección de Spawnpoint.
- Spoiler:
- Código:
-
/* ============ EntSelectSpawnPoint
Returns the entity to spawn at
USES AND SETS GLOBAL g_pLastSpawn ============ */ edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer ) { CBaseEntity *pSpot; edict_t *player;
player = pPlayer->edict();
// choose a info_player_deathmatch point if (g_pGameRules->IsCoOp()) { pSpot = UTIL_FindEntityByClassname( g_pLastSpawn, "info_player_coop"); if ( !FNullEnt(pSpot) ) goto ReturnSpot; pSpot = UTIL_FindEntityByClassname( g_pLastSpawn, "info_player_start"); if ( !FNullEnt(pSpot) ) goto ReturnSpot; } else if ( g_pGameRules->IsDeathmatch() ) { pSpot = g_pLastSpawn; // Randomize the start spot for ( int i = RANDOM_LONG(1,5); i > 0; i-- ) pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_deathmatch" ); if ( FNullEnt( pSpot ) ) // skip over the null point pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_deathmatch" );
CBaseEntity *pFirstSpot = pSpot;
do { if ( pSpot ) { // check if pSpot is valid if ( IsSpawnPointValid( pPlayer, pSpot ) ) { if ( pSpot->pev->origin == Vector( 0, 0, 0 ) ) { pSpot = UTIL_FindEntityByClassname( pSpot, "info_player_deathmatch" ); continue; }
// if so, go to pSpot goto ReturnSpot; } } // increment pSpot pSpot = UTIL_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 ( !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; } }
// If startspot is set, (re)spawn there. if ( FStringNull( gpGlobals->startspot ) || !strlen(STRING(gpGlobals->startspot))) { pSpot = UTIL_FindEntityByClassname(NULL, "info_player_start"); if ( !FNullEnt(pSpot) ) goto ReturnSpot; } else { pSpot = UTIL_FindEntityByTargetname( NULL, STRING(gpGlobals->startspot) ); if ( !FNullEnt(pSpot) ) goto ReturnSpot; }
ReturnSpot: if ( FNullEnt( pSpot ) ) { ALERT(at_error, "PutClientInServer: no info_player_start on level"); return INDEXENT(0); }
g_pLastSpawn = pSpot; return pSpot->edict(); }
Verificación.
- Spoiler:
- Código:
-
// checks if the spot is clear of players BOOL IsSpawnPointValid( CBaseEntity *pPlayer, CBaseEntity *pSpot ) { CBaseEntity *ent = NULL;
if ( !pSpot->IsTriggered( pPlayer ) ) { return FALSE; }
while ( (ent = UTIL_FindEntityInSphere( ent, pSpot->pev->origin, 128 )) != NULL ) { // if ent is a client, don't spawn on 'em if ( ent->IsPlayer() && ent != pPlayer ) return FALSE; }
return TRUE; }
|
|
Srtxyoyo
Mensajes : 23 Fecha de inscripción : 09/12/2010 Edad : 32 Localización : Peru
| Tema: Re: Explanation of Spawns Jue Mayo 12, 2011 11:20 pm | |
| Oh, nice . |
|