Where are animations defined?

Davina1961

Newbie
Joined
May 17, 2006
Messages
144
Reaction score
0
I am wondering where the animations are defined for character models. for instance can I use the MP animations with a combine or human model?

Any tips?
 
i believe each entity has their own setanimation function that defines what animations to play and when to play them , you can find this in the player.cpp on line 1699. but i dont think thats what you're looking for , your problem seems to be more asset related. could you elaborate on what you're trying to achieve ?
 
Make sure your model includes the mp animations ("QC File" Model Section ;P)
 
Basiclly I have modified a set animation function based on the HL2MP code in HL2_PLAYER.CPP however it doesnt work smoothly, as you would expect seeing as it was written for HL2MP which uses a differet shared set of animations. Prehaps I can recompile one of the models and use something like

$pushd "../male_anims"

?? What do you think? Would this work?

EDIT: The way HL2MP uses a different set of animations for players is that it has a different file for Male_shared etc that jsut redirects you to the new set of animations which is male_anims.mdl so what I did is copied over all these files into my mod folder and changed my set animation code back to how it used to be eg, instead of ACT_RUN I use ACT_HL2MP_RUN.

Now I dont have any animations playing for anything. lol any ideas?

EDIT: The more I look into this the more I'm thinking that simply using the MP animations wont fix all my problems however If anyone has any tips on getting these to work in SP I would love to hear it. prehaps things like ACT_HL2MP_IDLE only work in CHL2MP_Player base?

Prehaps I can add these to activitylist.cpp?

The reason I wanted to use the mp animations is because I'm having trouble with getting certain animations to work for my 3rd person player model.

For instance I have no animation playing for running with the crowbar or attacking with the crowbar.

in the section of the code where you have:

Code:
if ( speed > 0 )
				{
					idealActivity = m_fIsSprinting ? ACT_WALK_AIM_AGITATED : ACT_RUN_AIM_AGITATED;
				}
				else
				{
					idealActivity = ACT_IDLE_AIM_AGITATED;
				}

I think I should add another similar function saying if the speed is more than 0 but also the crowbar is equiped and then I can direct it to a different ACT_WALK.

So how can I add to the line:

if ( speed > 0 )

to make it check if the crowbar or another weapon is selected?

Sorry if that has started to not make sense anymore.
 
Hmm I cant seem to edit that last post. Anyway what I'm looking for is how I can test if the player has a weapon equiped eg pistol in an if statment. If anyone can help with this Id really appreciate it.
 
im not sure if this will work , im trying it out right now . you can add the if statement into preThink in the player class and then use GetActiveWeapon()->GetClassname() to get the class name of the current weapon , that function returns a const char so you should be able to look up the class name of the pistol and compare.
btw does anyone know whats the difference between postThink and preThink ? is prethink called before drawing ? .

edit :

ok this seems to work , i put this into the post think of the player class

Code:
if(HasWeapons()&&!strcmp(GetActiveWeapon()->GetClassname(),"weapon_pistol"))
Msg(" you have selected the pistol ");

im sure its not the most efficient way to do this but its the only way that i could come up with .
 
Ahh thanks you so much. I was close with what I had been trying. what does !strcmp meen?

Also why does this need to go in post think. why doesnt it work in my set animation function?
 
the think functions are called once every frame , im not sure about when the setAnimation is called . strcmp is a c++ function that compares 2 char arrays , i thought it would return true if the two strings were the same but it returned false so i just put a not infront .

edit:
Returns an integral value indicating the relationship between the strings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite.

that clears it all up :)
 
neither "speed" or "idealactivity" work in post think.

they both bring up undeclared identifier errors.

I wanted to use this.

if( speed > 0 && idealActivity == ACT_RANGE_ATTACK1 && HasWeapons()&&!strcmp(GetActiveWeapon()->GetClassname(),"weapon_pistol"))

{

idealActivity = ACT_RUN_AIM_AGITATED;

}
 
yeah thats because speed is defined in the setAnimation function and it isnt global . what you should do is declare a new PLAYER_ANIM for your custom animation and then handle it in an if statement , check out line 4421 in player.cpp
you could have it as
Code:
if( HasWeapons()&&!strcmp(GetActiveWeapon()->GetClassname(),"weapon_pistol"))
{
setAnimation(PLAYER_MYENUM);
}
in postThink and then in the setAnimation do something like this
Code:
if (playerAnim == PLAYER_MYENUM&&speed > 0 && idealActivity == ACT_RANGE_ATTACK1 )
{
  idealActivity = ACT_RUN_AIM_AGITATED;
}
 
It wont let me use setAnimation in Post think,

In the example you suggested in player.cpp it has the line,


VPROF( "CBasePlayer:: PostThink-Animation" );

so I tried to use this in the same manor in post think in hl2_player.cpp like this,

Code:
if ( IsAlive() )
		{
			VPROF( "CHL2_Player::PostThink-Animation" );
	//newplayeranim
  if( HasWeapons()&&!strcmp(GetActiveWeapon()->GetClassname(),"weapon_pistol"))
{

	setAnimation(PLAYER_SMG);
}

and it still wont let me use setAnimation but also causes lots of problems with other CHL2_PLAYER ITEMS like CHL2_PLAYER::Activate local function definitions are illegal etc

note that PLAYER_SMG is the new enum I declared in shareddefs.h. thats the right place to declare it right?

Any Ideas?
 
I'm really fustrated. Ive got the hl2mp aniamtions working in singleplayer, turns out in the code for each of the weapons it translates each activity

e.g ACT_IDLE ACT_IDLE_SMG1,

So after copying the male_anims you can translate ACT_IDLE to ACT_HL2MP_IDLE,

everything works fine accept the gesture range attack. HL2MP only uses one attack aniamtion for each weapon, GESTURE_RANGE_ATTACK. in the hl2 weapons files it translates, in smg1 for eg,

ACT_HLMP_GESTURE_RANGE_ATTACK, to ACT_HL2MP_GESTURE_RANGE_ATTACK_SMG1

and

ACT_RANGE_ATTACK1, to ACT_RANGE_ATTACK_SMG1,

with The ones with the smg1 extension referencing to the aniamtions in male_anims.

then in the set aniamtion function after allready setting the shooting activity to ACT_HLMP_GESTURE_RANGE_ATTACK it says;


if ( idealActivity == ACT_HL2MP_GESTURE_RANGE_ATTACK )
{
RestartGesture( Weapon_TranslateActivity( idealActivity ) );

// FIXME: this seems a bit wacked
Weapon_SetActivity( Weapon_TranslateActivity( ACT_RANGE_ATTACK1 ), 0 );

return;

thing is there is no animation in male_anims for ACT_RANGE_ATTACK_SMG1 and when I do this in my singleplayer version. changing things like ACT_HLMP_GESTURE_RANGE_ATTACK to
ACT_GESTURE_RANGE_ATTACK1 so that it works in singleplayer It tells me theres an unhandled animation event as you would expect seeing as that animation doesnt exist. So how come in the mp code they use it yet it does the correct animation.

If I just ignore all this and keep the shooting animation as ACT_GESTURE_RANGE_ATTACK1 and ignore the weapon_Setactivity thing it still doesnt work correctly. The animation for hl2mp shooting is strange. take a look at it in model viewer if you can. its like the ragdoll pose twitching. as though it is more like a macro that affects any of the animations when you shoot.

Anybody got any ideas about this? , before I rip the rest of my hair out.
 
On second thoughts, changing THIS;

if ( idealActivity == ACT_GESTURE_RANGE_ATTACK1 )
{
RestartGesture( Weapon_TranslateActivity( idealActivity ) );

// FIXME: this seems a bit wacked
Weapon_SetActivity( Weapon_TranslateActivity( ACT_RANGE_ATTACK1 ), 0 );

changing ACT_RANGE_ATTACK1 to idealActivity does play the shooting animation which is like a recoil however when you aim up it tries to rotate the model about 90 degrees so he is lying on his back facing the sky and visa versa if you aim down etc. it does this very quickly as if the animation event is in someway linked to the position you are aiming. its very odd. Could this have anything to do with how the view model animation works when shooting ?
 
Back
Top