Playdead problems


(raffles) #1

Hi,
I’m trying to mimic the playdead command in shrub and I have this code:

void PlayDead( gentity_t *ent ) {

	if( ent->client->playingdead == 0 ) {
	ent->client->playingdead = 1;

    ent->client->ps.pm_time = BG_AnimScriptEvent( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_ET_DEATH, qfalse, qtrue );
	} else if( self->client->playingdead == 1 ) {
	ent->client->playingdead = 0;

	ent->client->ps.pm_time = BG_AnimScriptEvent( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_ET_REVIVE, qfalse, qtrue );
	}
}

This is in g_utils.c. For some reason if I try to use this fuction the game crashes.

If I comment out the bit that plays the animation it’s okay, so obviously I have done something stupid.

Anyone have any idea?

Thanks


(Lanz) #2

Ok, just replying about what I see in the code. I hope you havent bound that to a key. Because then it would cycle between the ANIM_ET_DEATH and ANIM_ET_REVIVE every frame as long as you hold that key down.


(bacon) #3

You could try adding a flag instead then use something like the code found in PM_Footsteps (bg_pmove.c)

if ( pm->ps->pm_flags & PMF_FLAILING ) {
			animResult = BG_AnimScriptAnimation( pm->ps, pm->character->animModelInfo, ANIM_MT_FLAILING, qtrue );

			if( !pm->ps->pm_time )
				pm->ps->pm_flags &= ~PMF_FLAILING;	// the eagle has landed
		} else if ( !pm->ps->pm_time && !(pm->ps->pm_flags & PMF_LIMBO) ) { // DHM - Nerve :: before going to limbo, play a wounded/fallen animation
			if ( pm->ps->groundEntityNum == ENTITYNUM_NONE ) {
				// takeoff!
				pm->ps->pm_flags |= PMF_FLAILING;
				animResult = BG_AnimScriptAnimation( pm->ps, pm->character->animModelInfo, ANIM_MT_FLAILING, qtrue );
			} else {
				animResult = BG_AnimScriptAnimation( pm->ps, pm->character->animModelInfo, ANIM_MT_FALLEN, qtrue );
			}
		}

Then something like this (from ReviveEntity; g_weapon.c)

// DHM - Nerve :: Play revive animation
		BG_AnimScriptEvent( &traceEnt->client->ps, traceEnt->client->pers.character->animModelInfo, ANIM_ET_REVIVE, qfalse, qtrue );
		traceEnt->client->ps.pm_flags |= PMF_TIME_LOCKPLAYER;
		traceEnt->client->ps.pm_time = 2100;

(raffles) #4

The real problem is when I use BG_AnimScriptEvent() the game crashes, can sort out flags later, but there is no point if I can’t play the animations the entire function is designed for.


(bacon) #5

Just tried this and it semi-works, the only problem is the player “twitches” when he’s playing dead.

void B_PlayDead( gentity_t *ent ) {

	if ( ent->client && ent->flags & B_PLAYINGDEAD ) {
		BG_AnimScriptEvent( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_ET_REVIVE, qfalse, qtrue );
		ent->client->ps.pm_flags |= PMF_TIME_LOCKPLAYER;
		ent->client->ps.pm_time = 2100;
		return;
	} else {
		if ( ent->client->ps.pm_flags & PMF_FLAILING ) {
			BG_AnimScriptAnimation( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_MT_FLAILING, qtrue );

			if( !ent->client->ps.pm_time )
				ent->client->ps.pm_flags &= ~PMF_FLAILING;	// the eagle has landed
		} else {
			if ( ent->client->ps.groundEntityNum == ENTITYNUM_NONE ) {
				// takeoff!
				ent->client->ps.pm_flags |= PMF_FLAILING;
				BG_AnimScriptAnimation( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_MT_FLAILING, qtrue );
			} else {
				BG_AnimScriptAnimation( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_MT_FALLEN, qtrue );
			}
		}
		return;
	}
}

(raffles) #6

Thanks Bacon, is it OK if I use that code?

Edit:
Just tried it and the game still crashed? Obviously it has to do with me putting it in g_utils.c, can’t think of anything else - I’ll try it somewhere else in a minute. Where did you put this code?

Edit 2:
Tried moving it to g_combat and also tried commenting out the BG_AnimScriptAnimations, but the game still crashed, anything I should have done which I probably haven’t due to my lack of knowledge of C++?


(bacon) #7

I put it in a new file I created called g_bacon.c
You could try making a new file called g_raffles.c or something and add this to it:


#include "g_local.h"

void B_PlayDead( gentity_t *ent ) { 

   if ( ent->client && ent->flags & B_PLAYINGDEAD ) { 
      BG_AnimScriptEvent( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_ET_REVIVE, qfalse, qtrue ); 
      ent->client->ps.pm_flags |= PMF_TIME_LOCKPLAYER; 
      ent->client->ps.pm_time = 2100; 
      return; 
   } else { 
      if ( ent->client->ps.pm_flags & PMF_FLAILING ) { 
         BG_AnimScriptAnimation( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_MT_FLAILING, qtrue ); 

         if( !ent->client->ps.pm_time ) 
            ent->client->ps.pm_flags &= ~PMF_FLAILING;   // the eagle has landed 
      } else { 
         if ( ent->client->ps.groundEntityNum == ENTITYNUM_NONE ) { 
            // takeoff! 
            ent->client->ps.pm_flags |= PMF_FLAILING; 
            BG_AnimScriptAnimation( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_MT_FLAILING, qtrue ); 
         } else { 
            BG_AnimScriptAnimation( &ent->client->ps, ent->client->pers.character->animModelInfo, ANIM_MT_FALLEN, qtrue ); 
         } 
      } 
      return; 
   } 
}

In g_cmds.c I have:

/*
=================
PlayDead
=================
*/
// put this anywhere as long as it's not in any other functions and is before clientcommand
void Cmd_Playdead_f( gentity_t *ent ) {
	if ( ent->flags & B_PLAYINGDEAD )
		ent->flags &= ~B_PLAYINGDEAD;
	else
		ent->flags |= B_PLAYINGDEAD;

	B_PlayDead( ent );
}
// place this after the "imready command"
} else if (Q_stricmp( cmd, "playdead") == 0) {
		Cmd_Playdead_f( ent );
		return;

And at the end of clientthink_real (g_active.c) I have this:

if ( ent->flags & B_PLAYINGDEAD )
		B_PlayDead( ent );     // play a "revive me" animation when we're playing dead

In g_local I’ve defined B_PLAYINGDEAD but I don’t know how many flags you have so I won’t give you that (easy) code.


(raffles) #8

Yet, the game still crashes! Sorry to bother you, Bacon, obviously there is nothing you can do as you aren’t having this problem.

Ah well.

P.S.
As before, the game still crashes after I comment out the animations, so I don’t know what’s wrong now.