Hi guys!
It's done :-)
In g_combat.c I've created a new method:
/*
===================
GetPositionOfDeath
===================
Get the position where the bot has died and put it to the g_local.h to use it for the respawn.
*/
void GetPositionOfDeath (gentity_t *self, gentity_t *attacker)
{
// Did a teammate kill us or did we kill ourselves?
if ( (OnSameTeam( self, attacker ) && self != attacker )|| self == attacker )
{
return;
}
// Copy Vector to g_local.h to use it there for the respawn.
VectorCopy(self->r.currentOrigin, self->client->pers.positionOfDeath);
VectorCopy(self->r.currentAngles, self->client->pers.angleOfDeath);
}
This method is called by player_die():
if ( client->sess.spectatorClient == self->s.number ) {
Cmd_Score_f( g_entities + i );
}
}
// Here is it
GetPositionOfDeath (self, attacker);
self->takedamage = qtrue; // can still be gibbed
self->s.weapon = WP_NONE;
self->s.powerups = 0;
self->r.contents = CONTENTS_CORPSE;
OK, also you need the following extention of the clientPersistant_t in g_local.h:
// Position of Death
vec3_t positionOfDeath;
vec3_t angleOfDeath;
And finally you have to alter ClientSpawn() in g_client.c like this:
// health will count down towards max_health
ent->health = client->ps.stats[STAT_HEALTH] = client->ps.stats[STAT_MAX_HEALTH] + 25;
// If you want to do it also with the angles, then you have to do it the same way
if ( client->pers.positionOfDeath[0] != 0 && client->pers.positionOfDeath[1] != 0 && client->pers.positionOfDeath[2] != 0 )
{
// Copy the new position to the spawn-origin to use spawn-origin for the other functions.
VectorCopy(client->pers.positionOfDeath, spawn_origin);
G_SetOrigin( ent, spawn_origin);
VectorCopy( spawn_origin, client->ps.origin );
}
else
{
G_SetOrigin( ent, spawn_origin );
VectorCopy( spawn_origin, client->ps.origin );
}
// the respawned flag will be cleared after the attack and jump keys come up
client->ps.pm_flags |= PMF_RESPAWNED;
It works! :-)
I don't know if it's the best solution and I just have done a short gameplay test, but so far it works.
Some problems are still there (dividing player and bot etc.) but I'm glad it's done so far.
Thanks to all of you for your help!
hc