ahmeeed321 Posted June 9, 2019 Share Posted June 9, 2019 How can I make an animation play after another anim. I mean how to make player for example smoke then immediately drink after finishing smoking. I tried using this code bellow which is supposed to do drinking animation but when I test it, it only plays the last anim "hold_stand" Private Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown If e.Key = Keys.M Then BOTTLE = World.CreateObject(963479708, Player.Character.Position) BOTTLE.AttachToPed(Player.Character, Bone.RightHand, New Vector3(0.14F, 0.03F, 0.04F), New Vector3(2.21F, -0.12F, 0.0F)) Player.Character.Animation.Play(anims, "stand_create", 8.0F, animflags) #This one doesn't load Player.Character.Animation.Play(anims, "hold_stand", 8.0F, animflags) #This one loads end If Also how can I adjust the suitable vector for the object to fit in the hands. When I used this vector in the upper code for the bottle but it gets upside down in the hands. Is there any tools related to vectors of objects in hands Link to comment Share on other sites More sharing options...
Teki Posted June 10, 2019 Share Posted June 10, 2019 Hi, For the rotation it's the New Vector3(2.21F, -0.12F, 0.0F) in BOTTLE.AttachToPed(Player.Character, Bone.RightHand, New Vector3(0.14F, 0.03F, 0.04F), New Vector3(2.21F, -0.12F, 0.0F)) For animations you can use Tasks : (this is in C#) TaskSequence PleadTask = new TaskSequence(); PleadTask.AddTask.PlayAnimation(new AnimationSet("missray6"), "drop_knees", 8.0f); PleadTask.AddTask.PlayAnimation(new AnimationSet("missray6"), "plead_idle", 8.0f); Player.Character.Task.ClearAll(); Player.Character.Task.PerformSequence(PleadTask); PleadTask.Dispose(); ahmeeed321 1 Link to comment Share on other sites More sharing options...
ahmeeed321 Posted June 11, 2019 Author Share Posted June 11, 2019 12 hours ago, Teki said: Hi, For the rotation it's the New Vector3(2.21F, -0.12F, 0.0F) in BOTTLE.AttachToPed(Player.Character, Bone.RightHand, New Vector3(0.14F, 0.03F, 0.04F), New Vector3(2.21F, -0.12F, 0.0F)) For animations you can use Tasks : (this is in C#) TaskSequence PleadTask = new TaskSequence(); PleadTask.AddTask.PlayAnimation(new AnimationSet("missray6"), "drop_knees", 8.0f); PleadTask.AddTask.PlayAnimation(new AnimationSet("missray6"), "plead_idle", 8.0f); Player.Character.Task.ClearAll(); Player.Character.Task.PerformSequence(PleadTask); PleadTask.Dispose(); Pretty much thanks I appreciate your help. But I tried your method but it gave me an error in the game "error in script..." Here's what I used. I tried modifying the smoking spliff script in the example scripts of net scripthook but edited it to make the player drink instead of smoke. But it still gave me an error, do you notice any mistake? public class AnimationExample : Script { TaskSequence PleadTask = new TaskSequence(); bool bSmoking = false; GTA.Object bottle; GTA.Timer timer = new GTA.Timer(); // the timer will always show the elapsed gametime since the last Start() AnimationSet anims = new AnimationSet("[email protected]_spliff"); AnimationFlags animflags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09; public AnimationExample() { Interval = 1000; this.KeyDown += new GTA.KeyEventHandler(this.AnimationExample_KeyDown); this.Tick += new EventHandler(this.AnimationExample_Tick); } private void AnimationExample_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key != Keys.L) return; if (bSmoking) StopSmoking(); else StartSmoking(); } private void StartSmoking() { if (bSmoking) return; bSmoking = true; Player.Character.Weapons.Unarmed.Select(); PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_create"), "stand_create", 8.0f, animflags); PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_idle"), "drink_stand", 8.0f, animflags); Wait(1600); bottle = World.CreateObject(963479708, Player.Character.Position); bottle.AttachToPed(Player.Character, Bone.RightHand, new Vector3(0.14F, 0.03F, 0.04F), new Vector3(2.21F, -0.12F, 0.0F)); timer.Start(); } private void StopSmoking() { if (!bSmoking) return; bSmoking = false; if (bottle == null) return; bottle.Detach(); bottle.NoLongerNeeded(); } private void AnimationExample_Tick(object sender, EventArgs e) { if (bSmoking) { if (Player.Character.Weapons.CurrentType != Weapon.Unarmed) { StopSmoking(); } else if ((timer.ElapsedTime > 10000) && (Player.Character.isIdle)) { if (Player.Character.isInVehicle()) PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_idle"), "drink_stand", 8.0f, animflags); else PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_idle"), "drink_stand", 8.0f, animflags); timer.Start(); } } } } } Link to comment Share on other sites More sharing options...
Teki Posted June 11, 2019 Share Posted June 11, 2019 I see some errors : GTA.Timer timer = new GTA.Timer(); This should not be instanciated here but in the start function : GTA.Timer timer; (...) public AnimationExample() { timer = new GTA.Timer(); (...) GTA.Timer timer is the declaration so it will be available in your whole script. public AnimationExample() is your start function here, the first function started when your script is loaded. You can instanciate game objects here, in this case a GTA.Timer. Pretty much the same mistake with the TaskSequence. Just keep here the declaration : TaskSequence PleadTask; Then you will use this when you want your ped to do successives tasks : (In this case, your StartSmoking function) PleadTask = new TaskSequence(); // Instanciate PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_create"), "stand_create", 8.0f, animflags); // Add one task PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_idle"), "drink_stand", 8.0f, animflags); // Add another task Player.Character.Task.ClearAll(); // Clear the target tasks Player.Character.Task.PerformSequence(PleadTask); // Give task sequence to target PleadTask.Dispose(); // Dispose task sequence from memory Then when you only want to give one task to a ped you don't have to set a task sequence, just give him the task like this : (in the AnimationExample_Tick) Player.Character.Task.PlayAnimation(new AnimationSet("[email protected]_idle"), "drink_stand", 8.0f, animflags); This should make your script working. To go further you kept in your code this declaration : AnimationSet anims = new AnimationSet("[email protected]_spliff"); But you don't use this animation set. You could have put the "[email protected]_idle" in place of the "[email protected]_spliff" and the replace all new AnimationSet("[email protected]_idle") by anims. That's all i see, let me know if i'm not clear. ahmeeed321 1 Link to comment Share on other sites More sharing options...
ahmeeed321 Posted June 11, 2019 Author Share Posted June 11, 2019 (edited) 7 hours ago, Teki said: That's all i see, let me know if i'm not clear. I did your fixes but the script didn't really work. It didn't show any errors this time. It just didn't play the animations, It just spawned the bottle in the player's hand. That's all it did. My purpose from making this script is to make it exactly like smoking spliff script by hazardX but with drinking instead. In short, I want to make player take out bottle, drink, then stay holding the bottle(hold_stand animation) until the required time finish, then return drinking again(drink_stand). Just like this script bellow but it didn't work. It just spawned bottle without playing any animations using System; using System.Drawing; using System.Windows.Forms; using GTA; namespace bottle.net { public class AnimationExample : Script { bool bSmoking = false; GTA.Object bottle; GTA.Timer timer; AnimationFlags animflags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09; public AnimationExample() { Interval = 1000; timer = new GTA.Timer(); this.KeyDown += new GTA.KeyEventHandler(this.AnimationExample_KeyDown); this.Tick += new EventHandler(this.AnimationExample_Tick); } private void AnimationExample_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key != Keys.L) return; if (bSmoking) StopSmoking(); else StartSmoking(); } private void StartSmoking() { if (bSmoking) return; bSmoking = true; Player.Character.Weapons.Unarmed.Select(); TaskSequence PleadTask = new TaskSequence(); PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_create"), "stand_create", 8.0f, animflags); PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_hold"), "hold_stand", 8.0f, animflags); bottle = World.CreateObject(963479708, Player.Character.Position); bottle.AttachToPed(Player.Character, Bone.RightHand, new Vector3(0.14F, 0.03F, 0.04F), new Vector3(2.21F, -0.12F, 0.0F)); timer.Start(); } private void StopSmoking() { if (!bSmoking) return; bSmoking = false; if (bottle == null) return; bottle.Detach(); bottle.NoLongerNeeded(); } private void AnimationExample_Tick(object sender, EventArgs e) { if (bSmoking) { if (Player.Character.Weapons.CurrentType != Weapon.Unarmed) { StopSmoking(); } else if ((timer.ElapsedTime > 10000) && (Player.Character.isIdle)) { if (Player.Character.isInVehicle()) Player.Character.Task.PlayAnimation(new AnimationSet("[email protected]_idle"), "drink_stand", 8.0f, animflags); else Player.Character.Task.PlayAnimation(new AnimationSet("[email protected]_idle"), "drink_stand", 8.0f, animflags); } } } } } Edited June 11, 2019 by ahmeeed321 Link to comment Share on other sites More sharing options...
Teki Posted June 11, 2019 Share Posted June 11, 2019 Try with : Player.Character.Task.ClearAll(); Player.Character.Task.PerformSequence(PleadTask); PleadTask.Dispose(); After PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_hold"), "hold_stand", 8.0f, animflags); Link to comment Share on other sites More sharing options...
ahmeeed321 Posted June 11, 2019 Author Share Posted June 11, 2019 2 hours ago, Teki said: Try with : Player.Character.Task.ClearAll(); Player.Character.Task.PerformSequence(PleadTask); PleadTask.Dispose(); After PleadTask.AddTask.PlayAnimation(new AnimationSet("[email protected]_hold"), "hold_stand", 8.0f, animflags); It's still the same issue. Nothing changed Link to comment Share on other sites More sharing options...
Teki Posted June 12, 2019 Share Posted June 12, 2019 (edited) So i tested it and it works but there is an issue with the animation flag 11, it seems to act like an "allow override" so "stand_create" is instantly overriden by "hold_stand". You need flag 11 so the player is not stuck while playing anims, and i can't see a way to use task sequence with this flag. I also assumed you wanted to use "hold_stand" to make the player keep the bottle in hand and it only work with the animation flag 6 (it freeze the anim on the last frame) otherwise player go back to basic idle anim. So i made a workaround by tracking "stand_create" time, so i can spawn the bottle at a good timing (may need tweaking) and start the "hold_stand" right after. I did the same in the AnimationExample_Tick function because "drink_stand" will break "hold_stand". There is still the bottle position/rotation to be tweaked, and i kept the condition to change anim while in vehicle even if by now it will play the same anim as on foot. You may also find some problematic cases with the "hold_stand" pose So this is my modifications : using System; using System.Drawing; using System.Windows.Forms; using GTA; using GTA.Native; namespace bottle.net { public class AnimationExample : Script { bool bSmoking = false; GTA.Object bottle; GTA.Timer timer; AnimationFlags animflags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09; AnimationSet createAnim = new AnimationSet("[email protected]_create"); AnimationSet holdAnim = new AnimationSet("[email protected]_hold"); AnimationSet idleAnim = new AnimationSet("[email protected]_idle"); public AnimationExample() { Interval = 1000; timer = new GTA.Timer(); this.KeyDown += new GTA.KeyEventHandler(this.AnimationExample_KeyDown); this.Tick += new EventHandler(this.AnimationExample_Tick); } private void AnimationExample_KeyDown(object sender, GTA.KeyEventArgs e) { if (e.Key != Keys.Y) return; if (bSmoking) StopSmoking(); else StartSmoking(); } private void StartSmoking() { if (bSmoking) return; bSmoking = true; Player.Character.Weapons.Unarmed.Select(); float animTime = 0; Player.Character.Task.PlayAnimation(createAnim, "stand_create", 8.0f, animflags | AnimationFlags.Unknown06); Wait(0); while (createAnim.isPedPlayingAnimation(Player.Character, "stand_create") && animTime < 1) { animTime = createAnim.GetPedsCurrentAnimationTime(Player.Character, "stand_create"); if (bottle == null && animTime >= 0.2f) { bottle = World.CreateObject(963479708, Player.Character.Position); bottle.AttachToPed(Player.Character, Bone.RightHand, new Vector3(0.14F, 0.03F, 0.04F), new Vector3(2.21F, -0.12F, 0.0F)); // First Vector3 is position, second is rotation } Wait(0); } Player.Character.Task.PlayAnimation(holdAnim, "hold_stand", 8.0f, animflags | AnimationFlags.Unknown06); Wait(0); Function.Call("SET_CHAR_ANIM_CURRENT_TIME", Player.Character, holdAnim.Name, "hold_stand", 1.0f); timer.Start(); } private void StopSmoking() { if (!bSmoking) return; bSmoking = false; Player.Character.Task.PlayAnimation(holdAnim, "hold_stand", 8.0f, animflags); Wait(0); Function.Call("SET_CHAR_ANIM_CURRENT_TIME", Player.Character, holdAnim.Name, "hold_stand", 1.0f); if (bottle == null) return; bottle.Detach(); bottle.NoLongerNeeded(); bottle = null; } private void AnimationExample_Tick(object sender, EventArgs e) { if (bSmoking) { if (Player.Character.Weapons.CurrentType != Weapon.Unarmed) { StopSmoking(); } else if ((timer.ElapsedTime > 10000) && (Player.Character.isIdle)) { string animName = "drink_stand"; if (Player.Character.isInVehicle()) animName = "drink_stand"; float animTime = 0; Player.Character.Task.PlayAnimation(idleAnim, animName, 8.0f, animflags | AnimationFlags.Unknown06); Wait(0); while (idleAnim.isPedPlayingAnimation(Player.Character, animName) && animTime < 1) { animTime = idleAnim.GetPedsCurrentAnimationTime(Player.Character, animName); Wait(0); } Player.Character.Task.PlayAnimation(holdAnim, "hold_stand", 8.0f, animflags | AnimationFlags.Unknown06); Wait(0); Function.Call("SET_CHAR_ANIM_CURRENT_TIME", Player.Character, holdAnim.Name, "hold_stand", 1.0f); timer.Start(); } } } } } Edited June 12, 2019 by Teki Indentation failed in code brackets ahmeeed321 1 Link to comment Share on other sites More sharing options...
ahmeeed321 Posted June 12, 2019 Author Share Posted June 12, 2019 Thanks. Pretty much everything works perfectly now, That's exactly how I wanted it to be like. The only problem is the rotation of the object. Do you have any idea how can I know the suitable vector for an object? Teki 1 Link to comment Share on other sites More sharing options...
ahmeeed321 Posted June 13, 2019 Author Share Posted June 13, 2019 Nevermind. I found this vector in other mod for drinking whiskey and it kinda worked perfectly with this one GTA.Native.Function.Call("ATTACH_OBJECT_TO_PED", bottle, Player.Character, 1232, 0.1f, 0.06f, -0.23f, 0.0f, 0.0f, 0.0f, 0); But I still would love to know the trick to set a vector for an object without having to copy it from other mods Also do you know anyway to make bottle drop into ground after pressing Y key instead of floating in air. Thanks again and sorry for terrible explanation as I am not a native speaker Link to comment Share on other sites More sharing options...
Teki Posted June 13, 2019 Share Posted June 13, 2019 For rotation i only change values to see which one rotate the object in wich way then i tweak until i'm satisfied. When i tested the script the bottle was falling to the groud when released. I think objects are frozen when the game is using a lot of memory or cpu and the object is NoLongerNeeded. You can try this : bottle.Detach(); Wait(200); // Add this so the bottle have 200 milliseconds to touch the ground before being frozen. bottle.NoLongerNeeded(); bottle = null; ahmeeed321 1 Link to comment Share on other sites More sharing options...
ahmeeed321 Posted June 13, 2019 Author Share Posted June 13, 2019 That fixed it thanks. Also thanks for taking time to help me, there's very few kind people like you. I may modify this script for other animations like eating, smoking, etc. I will credit you if I upload any of them in modding sites Teki 1 Link to comment Share on other sites More sharing options...
Teki Posted June 14, 2019 Share Posted June 14, 2019 You're welcome. I would like to see your next scripts ! ahmeeed321 1 Link to comment Share on other sites More sharing options...