Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Forum Support

    3. Suggestions

How to make an animation play after another animation using vb code language


ahmeeed321
 Share

Recommended Posts

ahmeeed321
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

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();

 

Link to comment
Share on other sites

 

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

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.

Link to comment
Share on other sites

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 by ahmeeed321
Link to comment
Share on other sites

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

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

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 by Teki
Indentation failed in code brackets
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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;
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.