Pages

Monday, November 18, 2013

[TUT] Animations

Animations can give yet another look to an modification. In this tutorial i will show what i know about animations in GTA IV, you can download the code of this tutorial right here and download the list of GTA IV animation right here.

We have an massive list of animations to use and thanks to the individuals involved in OpenIV development we can see those animations without having the game operating, it's extremely useful, you can uncover this choice in the OpenIV menu Tools > Animation Viewer:


In the next screen we can pick what type of animation we want preview:


Clicking in Ped animations (anim.img) we will be redirected to an screen that organizes the animations by their categories:


Clicking in one particular of the categories we will see an new screen with an Ped in center and the list of animations in the left side, if we click 1 of the animations the OpenIV will start off playing the animation in loop mode:



Now to make this occur in game we can do with generally two approaches:
  • Employing scripthook classes
  • Employing native approach calls


Making use of Scripthook classes to play animations

To play animations utilizing the scripthook we need to have:
  • An animation set: This object will establish the category of the animation
  • The Animation object that every single Ped have, or the Ped's Process.PlayAnimation object
Basic instance:


Right here I'm declaring the animation set of the category swimming, then playing the animation idle from this category, the quantity eight represents the speed of the playback, this param don't appears to have an effect on the playback all the time, appears to operate only in the begin.

Result:


Before use an animation it's exciting request the animations of the category, we can do this utilizing this native call:


Now let's enhance this, as we can see the player plays the animation till the animation reaches the finish then go back to regular animation, but what we require to do to make it automatically loop this animation? We need to use animation flags, based on this web site the animation flags that we have are:
  • Unknown01 - Don't come back to initial position after animation ends, we use this for animations that result in position change for the ped, for instance the land and roll animation
  • Unknown04 - Primarily based on translation it will make ped return to original position, in my tests don't modify anything
  • Unknown05 - We use this flag to loop the animation
  • Unknown06 - We use this to cease the ped in the final animation position, ped will play animation then quit frozen in the final frame of the animation
  • Unknown07 - Appears that makes player reset to Standing idle animation following the animation ends
  • Unknown09 - This 1 will make the animation be played only in ped's upper physique, legs wont be impacted, it is fascinating to be utilized while the ped is inside an automobile (Nevitro tip).
  • Unknown10 - Remove the achievable sound of the animation, some animations has sounds other people never
  • Unknown09 combined with Unknown11 (Unknown09 Or Unknown11) - Tip sent by Giovafr Giova, this will outcome in the play of the animation only in the upper body with the possibility to stroll while the anim is being played.

We have other flags but they appears to outcome in practically nothing like the Unknown04.

So, to make our player repeat the animation we need to use the flag Unknown05:


We can combine flags with the Or operator, for instance, if we want play the run animation of the swimming category we can use the flags: Unknown01 to do not come back to initial positionUnknown05 to repeat and Unknown10 to eliminate the animation sound:


Often this play method fails when we try to place with each other the flags (after some reloadscripts command calls), so if the factors are not happening as anticipated, reload the game and test once again.

This video shows the result with and without the flags:


To quit the animation I'm utilizing this:



Other exciting strategies of the Animation class

  • isPlaying - This method returns True when the animation is being played
  • GetCurrentAnimationTime - This method return the existing time of the animation



Detecting animations

We can use the isPlaying or the GetCurrentAnimationTime to figure out if the ped is playing an determined animation, but to make confident that we can detect the anim we need to get in touch with the technique REQUEST_ANIMS to load the animations of that animation category ahead of we attempt to detect the animation play:





Employing native approaches to play animations

To play animations employing the native calls we have this methods:

  • Process_PLAY_ANIM
  • Activity_PLAY_ANIM_FACIAL
  • Activity_PLAY_ANIM_NON_INTERRUPTABLE
  • Activity_PLAY_ANIM_Prepared_TO_BE_EXECUTED
  • Activity_PLAY_ANIM_SECONDARY
  • Job_PLAY_ANIM_SECONDARY_IN_Vehicle
  • Process_PLAY_ANIM_SECONDARY_NO_INTERRUPT
  • Task_PLAY_ANIM_SECONDARY_UPPER_Body
  • Job_PLAY_ANIM_UPPER_Physique
  • Process_PLAY_ANIM_WITH_Sophisticated_FLAGS
  • Process_PLAY_ANIM_WITH_FLAGS

The more interesting right here is the Task_PLAY_ANIM_SECONDARY_UPPER_Physique because that strategy will play the animation only in the upper physique of the ped, it really is useful when we need to have to play an animation while the player is walking or operating, example:


Very first param is the ped, second is the animation name, then comes the category name, quantity 8. represents the playback speed, I declared p1_Repeat and p4_... to make clear of what is the function of that parameter in the technique call, if we set those params to a single or correct we will enable them, they act like flags, the last param figure out the time in milliseconds that the animation will be played, if we set an time smaller than the total animation time the animation will end before attain final frame, this time is not precise since it is affected by game FPS.

The Activity_PLAY_ANIM_SECONDARY_IN_Automobile it's exciting too because we can use this to play animations whilst the ped is in an vehicle, the params are exact same of the Task_PLAY_ANIM_SECONDARY_UPPER_Body method.

I never will speak about the other anim strategies due to the fact they have similar final results of the Scripthook techniques.



Other exciting techniques related to animations

  • HAVE_ANIMS_LOADED - We can use to check if the REQUEST_ANIMS call finished the loading of the animations of the category, params: category name
  • IS_CHAR_PLAYING_ANIM - To check if player is playing an animation, params: ped, category name and animation name
  • GET_CHAR_ANIM_Current_TIME - Get the animation time, params: ped, category name, animation name and a pointer to an variable (of kind Single) to store the time:


SET_CHAR_ALL_ANIMS_SPEED - This one particular will set an new playback speed for all animations that the pPed is playing, params: ped and new speed multiplier (float quantity). For instance, to set player anims to 150% the regular we can do:


SET_CHAR_ANIM_SPEED - This one is similar to the one particular above, the difference is that this one particular will influence one particular animation only, params: ped, category name, animation name and speed multiplier


SET_CHAR_ANIM_Existing_TIME - We can use this technique to set the animation time, 1. is 100%, the end, is the start off, really beneficial to control the animation, we can make and fake reverse playback reducing the percent quantity, params: ped, category name, animation name and playback %/100 (from to 1.)


Demonstration of reverse playbackhttp://www.facebook.com/photo.php?v=355430167913263, in this video i play grenade_throw_overarm from .3 (30%) to .six (60%) and back to .3, also i use SET_CHAR_ANIM_SPEED and set it to .1 to make the movement far more smooth.


SET_CHAR_MOVE_ANIM_SPEED_MULTIPLIER - This one changes only the ped movement animations speed, params: ped and speed multiplier

SET_ANIM_GROUP_FOR_CHAR - This a single alterations the ped animations group, will have an effect on his walk, run, idle animation, etc., params: ped and animation group

To use this last a single we need to have to get in touch with the REQUEST_ANIMS to load the animations of the chosen movement category just before use the approach:


We need to have to be careful with this native get in touch with simply because if we set an invalid movement group we crash the game :)
Typically the names of the groups begins with move_, for instance: move_player, move_melee, move_rifle, etc.. You can download the list of animations and see the categories that begin with move_ right here.
pernas
[TUT] Animations
9out of 10 based on 10 ratings. 9 user reviews.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.