Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. DLC
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site Suggestions

ahmeeed321

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

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

Share this post


Link to post
Share on other sites
Teki

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

 

Share this post


Link to post
Share on other sites
ahmeeed321

 

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

    }

}

Share this post


Link to post
Share on other sites
Teki

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.

Share this post


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

Share this post


Link to post
Share on other sites
Teki

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

 

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
ahmeeed321

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?

Share this post


Link to post
Share on other sites
ahmeeed321

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

Share this post


Link to post
Share on other sites
Teki

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;

Share this post


Link to post
Share on other sites
ahmeeed321

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

Share this post


Link to post
Share on other sites
Teki

You're welcome. I would like to see your next scripts !

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 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.