View Full Version : Playing player Animation/sequence

11-19-2008, 05:07 AM
My modeler has made and animation/sequence and im attempting to activate this in code the thing is when i use the code:

pOwner->SetSequence( pOwner->LookupSequence( "start_LtoR" ) );

The animation/sequence does not get played, does anyone know why this is and what must be done to get the player animation to play. I would prefer if there was an easier way of playing animation then going through that whole SetAnimation(PLAYER_watever) to ACT_watever thing

11-19-2008, 08:32 PM
Comon im sure there is a quicker way to set animation then going through the whole ACT thing it just takes to long, wat if i want the player to playt a simple animation surely there is a quicker way to do this

11-20-2008, 02:04 AM
I'd be interested in this, is their a wiki on setting animations using the act method? how bad is it?

11-20-2008, 11:06 AM
All the character animations are defined as ACT_ ... etc.

There's a few gotchas to character animation. Here's a checklist:

Register all your ACT lists in the activity enum under ai_activity.h
They also need to be registered with activitylist.cpp using the REGISTERED_SHARED_ACTIVITY macro. I believe you can just register an activity specific to a class, but I never really use that.
Try to always use ResetSequence because that's the way HL2MP does it. Reset sequence clears the frame counter and goes back to frame 0 as far as I know (and does other cleanup stuff related to animation?)
In your qc files if your sequence is not set to "loop" and you use SetSequence, your animation will only play once.
Also check the logic for your SetAnimation method. If you're doing HL2DM like we are, then you're going to run into situations where the animation gets reset for whatever reason. Also check the ResetAnimation method for conditions where your animation gets reset.

Here's a simple shortcut method I've written and added to the CHL2MP_Player (I've actually made it shared by client and server).

void CHL2MP_Player::PlaySequence( Activity idealActivity ){

// if this isn't called while attack is playing, the game will crash
SetActivity( idealActivity );

int idealSequence = SelectWeightedSequence( idealActivity );
// make sure it's a valid sequence
if (idealSequence == -1){
idealSequence = 0;
Warning("Attempted to play invalid sequence %i\n", idealSequence);

// check if this sequence is already playing
if ( GetSequence() == idealSequence )

m_flPlaybackRate = 1.0;

// If it's not already playing, loop it by resetting sequence and starting the cycle to 0
ResetSequence( idealSequence );
SetCycle( 0 );

This way all you need to do is send that method the Activity name and you're set.

An example sequence from our QC looks like this:

$sequence flourish_bow_basic "anim_bow_basic" ACT_BB_BOW1 1 fps 24

I hope that helps ;)

11-20-2008, 06:46 PM
Thats extremely helpful and i think u should seriously consider putting what uv posted on the source wiki i think many people would love to have this method. Although i worked out how to add anims using the OB sdk_playeranimstate but ur code is still much appreciated thankyou