Jump to content
ALPHIVE

How loop an animation ?

Recommended Posts

Hi everybody !

 

Do you know how to loop an animation ?

 

For exemple, i want that the soldier "MIKE" does an animation like if he talked to someone, but i want he repeat this forever, how can i do this ?

 

Thank you for you help guys !

Share this post


Link to post
Share on other sites

Hey, 

Try this:

 

while {true} do {

MIKE switchMove "AmovPercMstpSrasWrflDnon_Salute" ;

};

 

This will make him salute forever, just replace the animation inside the quotes with the animation you want.

Share this post


Link to post
Share on other sites

Use the eventHandler AnimDone.

MIKE switchMove "AmovPercMstpSrasWrflDnon_Salute";
MIKE addEventHandler [ "AnimDone", {
	params[ "_unit", "_anim" ];
	
	if ( _anim == "AmovPercMstpSrasWrflDnon_Salute" ) then {
		_unit switchMove "AmovPercMstpSrasWrflDnon_Salute";
	};
}];

And change the animation for what ever you are using.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi guys thank you for you help !

 

@Alert23 ok i will try this asap !

 

@Larrow i place your script in sqf like anim.sqf, and in the init of the unit i place the script sentence execution ? or do i place your script directly in the init of the character ?

 

thank you guys for help !

Share this post


Link to post
Share on other sites
26 minutes ago, ALPHIVE said:

i place your script in sqf like anim.sqf, and in the init of the unit i place the script sentence execution ? or do i place your script directly in the init of the character ?

Either as its specifically named to execute for the unit MIKE.

If you place it in the units init then you could replace MIKE with THIS if you wanted.

If you want to move it to a script file then you could make it reusable for any unit. e.g..

anim.sqf

params[ "_unit" ];

_unit switchMove "AmovPercMstpSrasWrflDnon_Salute";
_unit addEventHandler [ "AnimDone", {
	params[ "_unit", "_anim" ];
	
	if ( _anim == "AmovPercMstpSrasWrflDnon_Salute" ) then {
		_unit switchMove "AmovPercMstpSrasWrflDnon_Salute";
	};
}];

MIKEs init

_nul = [ this ] execVM "anim.sqf";

 

Share this post


Link to post
Share on other sites
On 2017/6/17 at 2:41 AM, ALPHIVE said:

@Larrow the character does the action but doesnt repeat the animation :(

@Larrow

 

I am honored to point out Larrow the God 's little bug.  

 

Mickey executed the  anim.sqf , and he gets a handler "AnimDone" performance which is "Do Salute again".

So you observed Mickey salutes TWICE .not ONCE. (Because 2 anims are too close to differ )

After Mickey did the second Salute, the whole program is done. Nothing will happen .

 

So you should add one line to make Mickey looply execute anim.sqf like this :

 

params[ "_unit" ];
_unit switchMove "AmovPercMstpSrasWrflDnon_Salute";
_unit addEventHandler [ "AnimDone", {
	params[ "_unit", "_anim" ];
	if ( _anim == "AmovPercMstpSrasWrflDnon_Salute" ) then {  //Make sure function is not break out by other anims 
                _unit execVM "anim.sqf"; //LOOP       
	};
}];

Of course , anim.sqf can be more practical:

anim.sqf:

params[ "_unit","_fncanim" ];

_unit switchMove _fncanim;
_unit addEventHandler [ "AnimDone", {
	params[ "_unit", "_anim" ];
	if ( _anim == _fncanim ) then {
	        [_unit,_fncanim] execVM "anim.sqf";
	};
}];

MIKEs init

_nul = [ this,"ANIMCLASS" ] execVM "anim.sqf"; 

or make anybody do anim in  trigger, trigger act:

 

[ _nul = [ _x , "ANIMCLASS" ] execVM "anim.sqf" ] foreach thislist ;

 

Share this post


Link to post
Share on other sites

Sorry I thought I had replied to this, must have got distracted as its still sitting here in recovery...

 

The animation I used was a bad example as it does not transition out, I was just being lazy and just copied the one posted previously.

You will also need to give the unit time to transition out  OR a transition out animation before replaying the animation, depending on the animation/command used.

You can also experiment with the different commands playMove, playMoveNow instead of switchMove to give you smooth transitions between the animations.

 

If you were to place a systemchat in the previous code to see what animation had finished, you would of noticed the name was different and the animation actually played is "AmovPercMstpSrasWrflDnon_SaluteIn". We can make the unit transition out using "AmovPercMstpSrasWrflDnon_Saluteout".

For example, straight in the units init..

if ( local this ) then {		
	_nul = this params[ "_unit" ];
	
	_unit playMove "AmovPercMstpSrasWrflDnon_Salute";
	_unit addEventHandler [ "AnimDone", {
		params[ "_unit", "_anim" ];
		systemChat format[ "animDone - %1", _anim ];
		
		switch ( _anim ) do {
			case "amovpercmstpsraswrfldnon_salutein" : {
				_unit playMove "AmovPercMstpSrasWrflDnon_Saluteout";
			};
			case "amovpercmstpsraswrfldnon_saluteout" : {
				_unit playMove "AmovPercMstpSrasWrflDnon_Salute";
			};
		};
	}];
};

 

1 hour ago, CHINA Nothing said:

After Mickey did the second Salute, the whole program is done. Nothing will happen .

This is not correct. The eventHandler will continuously fire each time an animation has finished. The problem was just the animation name that was checked and no transition.

 

57 minutes ago, CHINA Nothing said:

params[ "_unit" ];
_unit switchMove "AmovPercMstpSrasWrflDnon_Salute";
_unit addEventHandler [ "AnimDone", {
	params[ "_unit", "_anim" ];
	if ( _anim == "AmovPercMstpSrasWrflDnon_Salute" ) then {  //Make sure function is not break out by other anims 
                _unit execVM "anim.sqf"; //LOOP       
	};
}];

Of course , anim.sqf can be more practical:

anim.sqf:


params[ "_unit","_fncanim" ];

_unit switchMove _fncanim;
_unit addEventHandler [ "AnimDone", {
	params[ "_unit", "_anim" ];
	if ( _anim == _fncanim ) then {
	        [_unit,_fncanim] execVM "anim.sqf";
	};
}];

This is a bad way of doing it as each time the script loops you are adding yet another eventHandler to the unit.

Share this post


Link to post
Share on other sites

And the second wont work as the variable _fncanim won't be passed inside the _EH

  • Like 1

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×