skyrayfox Posted June 9, 2015 Share Posted June 9, 2015 [Tutorial] Creating synchronized animations (GTALua) I couldn't find any any posts about this on the forums so I managed to figure it out myself. I wanted to sync two ped animations together, so here it is in GTALua code!: streaming.RequestAnimDict("[email protected][email protected]")scene1 = natives.PED.CREATE_SYNCHRONIZED_SCENE(playerPosition.x,playerPosition.y,playerPosition.z-1, 0.0, 0.0, 180.0, 2)natives.PED.SET_SYNCHRONIZED_SCENE_LOOPED(scene1, false)natives.AI.TASK_SYNCHRONIZED_SCENE(targetPed, scene1, "[email protected][email protected]", "flee_backward_shopkeeper", 1000.0, -4.0, 64, 0, 0x447a0000, 0)natives.AI.TASK_SYNCHRONIZED_SCENE(playerPed, scene1, "[email protected][email protected]", "flee_backward_thief", 1000.0, -4.0, 1, 0, 0x447a0000, 0)natives.PED.SET_SYNCHRONIZED_SCENE_PHASE(scene1, 0.0) How does it work? First we request the animation dictionary. In GTALua we can use the wrapper function that will request and load the animations for us before we can use them. Use STREAMING::REQUEST_ANIM_DICT() native instead if not using GTALua: streaming.RequestAnimDict("[email protected][email protected]") Then we need to set up the animation scene. We will center the animation on our player but you can use any coordinates you want. Both Peds will be teleported there once the scene starts. scene1 = natives.PED.CREATE_SYNCHRONIZED_SCENE(playerPosition.x,playerPosition.y,playerPosition.z-1, 0.0, 0.0, 180.0, 2) We can choose to loop the animations if we want. Then we can set up the animations for the player and target ped, refer to the animation list for animationDictionaries and animationNames. For this example we will use a mugging animation. Values after the animation names are currently unknown. natives.PED.SET_SYNCHRONIZED_SCENE_LOOPED(scene1, false)natives.AI.TASK_SYNCHRONIZED_SCENE(targetPed, scene1, "[email protected][email protected]", "flee_backward_shopkeeper", 1000.0, -4.0, 64, 0, 0x447a0000, 0)natives.AI.TASK_SYNCHRONIZED_SCENE(playerPed, scene1, "[email protected][email protected]", "flee_backward_thief", 1000.0, -4.0, 1, 0, 0x447a0000, 0) Finally we can start the animations from the beginning (0.0 is the time I assume). You can change the second argument value if you want to start the animations later, from the middle or end etc. natives.PED.SET_SYNCHRONIZED_SCENE_PHASE(scene1, 0.0) Of course you may also need to update your GTALua natives used in this example to accept proper values. Check if TASK_SYNCHRONIZED_SCENE is accepting string values for 3rd and 4th argument in native_call_layout.ini file: TASK_SYNCHRONIZED_SCENE=aassffaafa)v . Synchronized animations for Peds and Objects Sync animations also work for peds and objects! Here's a synced animation of Franklin opening the door to his house. It works the same way except we need to replace the second ped with the "door " object (door model hash is "520341586") and use PLAY_SYNCHRONIZED_ENTITY_ANIM() native instead: streaming.RequestModel(520341586)object = natives.OBJECT.CREATE_OBJECT(520341586, playerPosition.x,playerPosition.y,playerPosition.z, true, true, false)streaming.RequestAnimDict("[email protected]_home")scene = natives.PED.CREATE_SYNCHRONIZED_SCENE(playerPosition.x,playerPosition.y,playerPosition.z, 0.0, 0.0, 180.0, 2)natives.AI.TASK_SYNCHRONIZED_SCENE(playerPed, scene, "[email protected]_home", "franklin_enters_old_home", 1000.0, -1000.0, 0, 0, 0x447a0000, 0)natives.ENTITY.PLAY_SYNCHRONIZED_ENTITY_ANIM(object, scene, "franklin_enters_old_home_door", "[email protected]_home", 1000.0, -1000.0, 0, 0x447a0000) Hopefully somebody will find this useful! qwerasdzxc, sodanakin, Ben Lahyene and 5 others 8 Link to comment Share on other sites More sharing options...
ffzero58 Posted June 9, 2015 Share Posted June 9, 2015 This would be great. Do you know how many synchronized animations are there to use? Otherwise we can look through the Decompiled scripts. Looks like synched scenes share the same anim dict. I am hoping to find a way to allow animations to occur while still in control of your vehicle. I may make a new thread on this. Link to comment Share on other sites More sharing options...
Freakyy Posted June 10, 2015 Share Posted June 10, 2015 Very nice tutorial! Do you mind if I add it to the wiki? Link to comment Share on other sites More sharing options...
sodanakin Posted June 10, 2015 Share Posted June 10, 2015 Thank you very much for this will be using this for sure! Link to comment Share on other sites More sharing options...
skyrayfox Posted June 10, 2015 Author Share Posted June 10, 2015 This would be great. Do you know how many synchronized animations are there to use? Otherwise we can look through the Decompiled scripts. Looks like synched scenes share the same anim dict. No idea but it should work with all animations, even ones that aren't meant to be synced together. Very nice tutorial! Do you mind if I add it to the wiki? Go ahead ! Link to comment Share on other sites More sharing options...
dehan Posted June 12, 2015 Share Posted June 12, 2015 (edited) That's awesome!, Do you know how we can change the duration it ends? Of course natives.PED.SET_SYNCHRONIZED_SCENE_PHASE(scene1, 0.0) works for starting later, but what about ending earlier? Edited June 12, 2015 by dehan Link to comment Share on other sites More sharing options...
skyrayfox Posted June 12, 2015 Author Share Posted June 12, 2015 That's awesome!, Do you know how we can change the duration it ends? Of course natives.PED.SET_SYNCHRONIZED_SCENE_PHASE(scene1, 0.0) works for starting later, but what about ending earlier? I don't know of any natives for that so I use a GTALua timer that clears ped tasks when I want. For example this one stops the animation after 10 seconds: timer.Simple(10000, function() natives.AI.CLEAR_PED_TASKS_IMMEDIATELY(playerPed)end, "") Link to comment Share on other sites More sharing options...
dehan Posted June 13, 2015 Share Posted June 13, 2015 (edited) Edit: You may be able to use ENTITY::STOP_SYNCHRONIZED_ENTITY_ANIM (C++) -- That's awesome!, Do you know how we can change the duration it ends? Of course natives.PED.SET_SYNCHRONIZED_SCENE_PHASE(scene1, 0.0) works for starting later, but what about ending earlier? I don't know of any natives for that so I use a GTALua timer that clears ped tasks when I want. For example this one stops the animation after 10 seconds:timer.Simple(10000, function() natives.AI.CLEAR_PED_TASKS_IMMEDIATELY(playerPed)end, "") Yeah, ended up doing that haha. Cheers Edited June 13, 2015 by dehan Link to comment Share on other sites More sharing options...
MrPancakes Posted June 13, 2015 Share Posted June 13, 2015 Very thorough tutorial, helped me alot. Thanks bro. Link to comment Share on other sites More sharing options...
MrGTAmodsgerman Posted June 14, 2015 Share Posted June 14, 2015 [Tutorial] Creating synchronized animations (GTALua) Thank you for this tutorial. 1.But what is about set a animation on the actual character like Franklin...? 2.And how to stop a animation? 3.How can i view a animation to know what what is? Thank you in the future. Link to comment Share on other sites More sharing options...
stormy.scp Posted June 15, 2015 Share Posted June 15, 2015 [Tutorial] Creating synchronized animations (GTALua) Thank you for this tutorial. 1.But what is about set a animation on the actual character like Franklin...? 2.And how to stop a animation? 3.How can i view a animation to know what what is? Thank you in the future. See: 1) GTALua code if IsKeyDown(KEY_F10) then natives.STREAMING.REQUEST_ANIM_DICT("[email protected][email protected]@[email protected][email protected]"); if natives.STREAMING.HAS_ANIM_DICT_LOADED("[email protected][email protected]@[email protected][email protected]") then print("loaded"); //GTALua console natives.AI.TASK_PLAY_ANIM(natives.PLAYER.PLAYER_PED_ID(), "[email protected][email protected]@[email protected][email protected]", "getup_l_0", 8.0, -8.0, -1, 10, 0, false, false, false); natives.STREAMING.REMOVE_ANIM_DICT("[email protected][email protected]@[email protected][email protected]"); end end 3) Download and install the ActorManager mod (copy files to "GTA5 \ scripts" folder) if you can't find the "AnimationIndex.txt" in that folder then start the game, press F6 and check again open that file, there is the list of animations keep that open, easier to work if you use windowed mode or second monitor now go to "Preview Animatons", stay on Anim index, press Num5, switch to the opened txt file, select the anim you need type in the number, zero not needed, press enter go down in the menu (with Num2), select Play (Num5) voilá Now back to the code: In the txt the anims have two part: 1) anim dict name 2) anim name There is a " " (space) between them, be careful when selecting. for example this is what I used in the code above: 05721 [email protected][email protected]@[email protected][email protected] getup_l_-180 anim dict name: "[email protected][email protected]@[email protected][email protected]" anim name: "getup_l_-180" As you can see in the code the anim name is used only once as the second parameter of TASK_PLAY_ANIM The parameters for this: http://www.dev-c.com/nativedb/func/info/ea47fe3719165b94 Scroll down to TASK_PLAY_ANIM or insert this on the searchbox and click "Find". Regards, Stormy Link to comment Share on other sites More sharing options...
ul1994 Posted June 21, 2015 Share Posted June 21, 2015 (edited) Thanks for the tutorial, skyrayfox. Can a synchronized scene accommodate arbitrary tasks (jump, pause, goto, sequences) under AI, or is it reserved only for animations found in the dictionary? Edited June 21, 2015 by ul1994 Link to comment Share on other sites More sharing options...
amoshydra Posted June 24, 2015 Share Posted June 24, 2015 (edited) void TASK_PLAY_ANIM(Ped ped, char *animDictionary, char *animationName, float speed, float speedMultiplier, int freezeNSpeed, int bodyPartNFreeze, float playbackRate, BOOL lockX, BOOL lockY, BOOL lockZ) I found out that the 5th and 6th parameter served different purposes. They are previously named - int duration ---> int freezeNSpeed - int lastFrame ---> int bodyPartNFreeze [table]Value : freezeNSpeedBehaviour-1Default (see bodyPartNFreeze)0Not play at allSmall valueSlow down animation speedSufficiently large valueFreeze player control until specific time (ms) has passed.(No effect if bodyPartNFreeze is set to be controllable.)[/table]This parameter takes in duration in millisecond to disable player's control while animation is playing. [table]Value: bodyPartNFreezeBehaviourOdd numberLoop animation infinitelyEven numberFreeze animation at its last frameFor 0 to 31.Multiple of 4.Freeze animation at its last frame. Player is able to control.For 0 to 15For 0x0 to 0xFAnimate entire bodyFor 16 to 31For 0x10 to 0x1FAnimate upper bodyFor 32 to 47For 0x20 to 0x2FAnimate entire body. Player can navigate while animation is playing.For 48 to 63For 0x30 to 0x3FAnimate upper body only. Player can walk/run while animation is playing.For 0 to 255For 0x00 to 0xFFPlay animation as describe aboveFor 256 to 511For 0x100 to 0x1FFPlay garbled animation. This is similar to applying animal's animation to human ped.[/table] Edited June 24, 2015 by amoshydra Link to comment Share on other sites More sharing options...
Luucky Posted June 27, 2015 Share Posted June 27, 2015 (edited) Yo, I didn't wanna trash the forums makin' another thread, so I'm asking here.. Have any of you found a NATIVE, apart from the one above, that lets you for example disable or exclude a bone during the animation or at least blend out that body part so it continues its motion from the previous animation. To make it easy to visualize, imagine Michael holding a coffee cup in his one hand, and the other arm swings in the usual motion. Thanks in advance! Peace. Edited June 27, 2015 by Hryniu Link to comment Share on other sites More sharing options...
jordRiot Posted July 12, 2015 Share Posted July 12, 2015 Has anyone worked out what the last few parameters of CREATE_SYNCHRONIZED_SCENE are? I've set up a scene between two peds and they always teleport on top of each other and glitches. I need them to maintain both their positions! Any ideas?? Link to comment Share on other sites More sharing options...
ayylmao420 Posted August 1, 2015 Share Posted August 1, 2015 Anyone at all managed to do synchronized animations in scripthook dot net? Link to comment Share on other sites More sharing options...
DrDoom151 Posted August 6, 2015 Share Posted August 6, 2015 (edited) Any idea why I'm getting this error when trying to run your example synchronized scene? [LUA] GTALua/internal/extensions/CNativeReg.lua:70: CNativeReg:Call [AI/TASK_SYNCHRONIZED_SCENE]: Argument type mismatch (index 3 - got string expected number) Didn't change anything, as you can see: natives.AI.TASK_SYNCHRONIZED_SCENE(Suspect, scene1, "[email protected][email protected]", "flee_backward_shopkeeper", 1000.0, -4.0, 64, 0, 0x447a0000, 0) Edited August 6, 2015 by DrDoom151 Link to comment Share on other sites More sharing options...
darkphoenixxx Posted November 12, 2015 Share Posted November 12, 2015 Thank your for tutorial, its awesome! Link to comment Share on other sites More sharing options...
elsewhat Posted December 11, 2016 Share Posted December 11, 2016 Thanks for the excellent research. Have started the implementation of synchronized animation in Scene Director mod. Just released a beta which has a preview functionality of synchronized animations and will make them recordable in a scene soon MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
Dmitrysass Posted April 17, 2020 Share Posted April 17, 2020 That awesome) Link to comment Share on other sites More sharing options...