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. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    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
      7. The Diamond Casino Heist
    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 IV 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 SA Mods
    10. GTA Vice City

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

      1. Guides & Strategies
      2. Help & Support
      3. GTA III 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

Captain Bot

Disabling Controls during task sequence?

Recommended Posts

Captain Bot

I've been trying to figure this one out for a couple of days now. what I'm trying to do is teleport to a location and run a task sequence then teleport back to original location .This is triggered when choosing an option from a tooltip. Both teleports and the task sequence runs fine but I want to disable look LR control during task sequence. When I put the  Game.DisableControlThisFrame(2, (GTA.Control)1); function in an if statement (on Tick) the control is only disabled after I teleport back to original location after task sequence has finished. Any Ideas out there where I'm going wrong?  Any help is greatly appreciated.

 

Thanks

 

(seqActive is set to 1 via an in-game mod menu.)

 

 

public int seqActive;

public int seqActive2;

public int countdown_value;

public void OnTick(object sender, EventArgs e)

{

 if (seqActive2 == 1)
            {
                Game.DisableControlThisFrame(2, (GTA.Control)1);
            }

  if (Game.IsControlPressed(2, GTA.Control.FrontendLeft) && near_mrkshp_02 && seqActive == 1)          
            {
                player.Heading = 145.75f;
                GameplayCamera.RelativeHeading = 1.0f;
                Game.FadeScreenOut(1000);
                Wait(995);
                GameplayCamera.RelativeHeading = 357.59f;
                Seq2();
                Wait(1000);
                player.Position = marker.mrkshp02_loc;
                Function.Call(Hash.SET_ENTITY_HEADING, player, 5.11f);
                GameplayCamera.RelativeHeading = 1.0f;
            }

}

           

 public void Seq2()
        {
            marker marker = new marker();          
            Ped player = Game.Player.Character;
            var plSeq = new TaskSequence();

            if (seqActive == 1)
            {
                 seqActive2 = 1;
                Wait(1000);
                SoundPlayer waveplayer2 = new SoundPlayer("C:/Program Files/Rockstar Games/Grand Theft Auto V/menyooStuff/Audio/ws001.wav");            
                Function.Call(Hash.REQUEST_ANIM_DICT, "[email protected]@on_the_toilet");
                while (!Function.Call<bool>(Hash.HAS_ANIM_DICT_LOADED, "[email protected]@on_the_toilet"))
                {
                    Wait(100);
                }
                Game.FadeScreenOut(1000);
                Wait(1000);

                GameplayCamera.RelativeHeading = 357.59f;
                player.Position = new Vector3(398.26228f, -1004.97778f, -99.004097f);
                Wait(500);
                Function.Call(Hash.SET_ENTITY_HEADING, player, 269.36f);              
                Wait(500);
                toilets.Retail_washroom();
                Wait(500);
                plSeq.AddTask.PlayAnimation("[email protected]@on_the_toilet", "trevonlav_backedup");
                plSeq.AddTask.PlayAnimation("[email protected]@on_the_toilet", "trevonlav_baseloop");
                plSeq.AddTask.PlayAnimation("[email protected]@on_the_toilet", "trevonlav_struggleloop");
                plSeq.AddTask.PlayAnimation("[email protected]@on_the_toilet", "trevonlav_baseloop");
                plSeq.Close();             
                player.AlwaysKeepTask = true;
                player.Task.PerformSequence(plSeq);
                Game.FadeScreenIn(1000);
                Wait(1500);
                waveplayer2.Play();
                Wait(1000);
                Function.Call(Hash._PLAY_AMBIENT_SPEECH1, player, "GET_UP_FROM_FALL", "SPEECH_PARAMS_FORCE", 0);
                Wait(5000);
                Puke_particle_toilet();
                Function.Call(Hash._PLAY_AMBIENT_SPEECH1, player, "GENERIC_FRUSTRATED_MED", "SPEECH_PARAMS_FORCE", 0);
                Wait(14000);
                Function.Call(Hash._PLAY_AMBIENT_SPEECH1, player, "GENERIC_FRUSTRATED_MED", "SPEECH_PARAMS_FORCE", 0);
                Wait(10000);
                Puke_particle_toilet();
                Function.Call(Hash._PLAY_AMBIENT_SPEECH1, player, "GENERIC_FRUSTRATED_MED", "SPEECH_PARAMS_FORCE", 0);
                Wait(8000);
                Function.Call(Hash._PLAY_AMBIENT_SPEECH1, player, "GENERIC_FRUSTRATED_MED", "SPEECH_PARAMS_FORCE", 0);
                // waveplayer2.Stop();
                Wait(3000);
                Game.FadeScreenOut(1000);
                Wait(1000);                                      
                player.Position = marker.mrkshp02_loc;
                Function.Call(Hash.SET_ENTITY_HEADING, player, 5.11f);
                GameplayCamera.RelativeHeading = 1.0f;
                Game.FadeScreenIn(1000);
                countdown_value = 0;
                UI.ShowSubtitle("Should be good for a while now", 5000);
                //seqActive2 = 0;
            }

            else
            {
                Game.FadeScreenOut(1000);
                Wait(2000);
                Function.Call(Hash.SET_ENTITY_HEADING, player, 5.11f);
                GameplayCamera.RelativeHeading = 1.0f;
                Game.FadeScreenIn(1000);
                countdown_value = 0;
                UI.ShowSubtitle("Should be good for a while now", 5000);
            }

Edited by Captain Bot
sloppy c&p

Share this post


Link to post
Share on other sites
Tanjitsu

Ok.

 

If you are using ScriptHookDotNet V3 then i added a lovely feature for you.
You can Instance scripts on demand.

Your issue is.
The disable control has to be run every frame to disable the control.
But you are using .Wait(),  wait stops this script running while its waiting. 
There fore the disable is not running during wait.

 

The simplest option is to separate the functionality.
1. Script to run every frame.
1. Script to run your sequence.

 

The old method is just to create loads of scripts but this is cumbersome.
So if you use V3 you can use...

 

[ScriptAttributes(NoDefaultInstance = true)]
public class Sequence : Script
{
  public Sequence()
  {
    Tick += OnTick;
  }

  private void OnTick(object sender, EventArgs e)
  {
    Do Sequence
    }
}

 

The NoDefaultInstance being set true tells script hook to not create this when it loads.
 

Then in your main script you do something like.

 

if (Game.IsControlPressed(2, GTA.Control.FrontendLeft) && near_mrkshp_02 && seqActive == 1)          
{
  Sequence sequence = Script.InstantiateScript<Sequence>();
}
  

This will create an instance of the script and start it on demand.
I suggest you look at the DotNet examples for the example instance script.

 

You should also run another instance for your Frames to disable the control on every frame even when you main script or your sequence is running.

 

 

Share this post


Link to post
Share on other sites
Captain Bot

Thanks for the reply.

I just started learning to code a few weeks ago but I think I understand what you mean. Turns out I'm using version 2 so first it looks like Ill be moving to version 3 to simplify things. When you say the wait is preventing it from running, do you mean that absolutely no wait function can exist while seqActive is set to 1 or just not within the if statement where seqActive is set as condition? Also I searched for dotnet instance examples and didn't find anything (probably due to my newbism) but I did find and study some info on ScriptAttributes. Again thank-you for the help and I'll try and wrap my head around the info you've provided.

Share this post


Link to post
Share on other sites
Tanjitsu

Hey,

 

Always happy to help out a new coder :)
 

ScriptHookDotNet - Examples  https://github.com/crosire/scripthookvdotnet/tree/master/examples

V3 is alot nicer to write, so i think it is worth moving your code over.

You will need to use Wait to get your script to execute commands at the right time.
Wait only makes your script wait at the point you place your Wait.

GTA will continue to run as its not tied to your script.

So if you say
Task.HandsUp(3000);

Wait(4000);

Task.HandsUp(3000);

 

Then you will have a 1 second gap between the first Task ending and the second task running because your script was asleep for 4 seconds and the task only ran for 3 seconds.

Sequences are different in that you en-queue a list of functions which will run one after another "in sequence".

So if your sequence will take 12 seconds to run, after you initiate your sequence you can set your script to wait for 12 seconds.
This will result in your script continuing at the same time the sequence is finishing.

Your issue with Wait is not the sequence but that you are trying to perform 2 functions at the same time.
1. Your sequence.

2. Disabling in-game commands.

 

The native to disable in-game command will only be active on the frame it is called. So you must call it every frame.

But if you tell your script to Wait. Then your script is no longer calling the native disable command while its waiting.

So you need to separate the 2.
1. A script which runs every frame and sends the native to disable a command for the time you want it disabled.
2. A script which runs a sequence and stops and starts as the sequence needs.

Basically to control advanced systems like sequences with timings you cant run everything from one instance of a script.

I separate my systems into the types of functions they are running.


Such as
1. a Script running every frame for things like disabling controls.

2. a Script running every frame for drawing UI on screen.

3. a Script running every 500 ms for updating my UI with new values.
4. a Script running the main thread of things like Sequences.

 

Then i can tell Script 4 to stop and start as much as it needs without effecting the UI being drawn ect.

Hope this made sense 😛



 

Share this post


Link to post
Share on other sites
Captain Bot

Ah, I think I'm beginning to understand. I was assuming that anything in an OnTick context runs continuously regardless of what is happening elsewhere in the script but what you're saying is to run multiple scripts simultaneously so any processes running at the same time don't conflict with one another.  I recall seeing a TUT outlining running multiple scripts. I think I'll give that a second look. Thanks for the link too. First I'll have to get SHVDN V3 ironed out. After finding and fixing all the reference paths and changes to the native functions I've finally got it to compile with no errors but I'm getting Unhandled exceptions and the script does not load when starting the game. I'll probably just rewrite the code in version 3. It will allow me to structure the code a little better and the practice definitely wouldn't hurt.

I'll post back and report how I managed with it.

Share this post


Link to post
Share on other sites
Tanjitsu
            Ped player = Game.Player.Character;
            var plSeq = new TaskSequence();

			Function.Call(Hash.REQUEST_ANIM_DICT, "[email protected]@on_the_toilet");
            while (!Function.Call<bool>(Hash.HAS_ANIM_DICT_LOADED, "[email protected]@on_the_toilet"))
            {
              Wait(100);
            }

			plSeq.AddTask.PlayAnimation("[email protected]@on_the_toilet", "trevonlav_backedup");
            plSeq.AddTask.PlayAnimation("[email protected]@on_the_toilet", "trevonlav_baseloop");
            plSeq.AddTask.PlayAnimation("[email protected]@on_the_toilet", "trevonlav_struggleloop");
            plSeq.AddTask.PlayAnimation("[email protected]@on_the_toilet", "trevonlav_baseloop");
			plSeq.Close();             
                
            if (seqActive == 1)
            {
                 seqActive2 = 1;
                Wait(1000);
                SoundPlayer waveplayer2 = new SoundPlayer("C:/Program Files/Rockstar Games/Grand Theft Auto V/menyooStuff/Audio/ws001.wav");            
                
                Game.FadeScreenOut(1000);
                Wait(1000);

                GameplayCamera.RelativeHeading = 357.59f;
                player.Position = new Vector3(398.26228f, -1004.97778f, -99.004097f);
                Wait(500);
                Function.Call(Hash.SET_ENTITY_HEADING, player, 269.36f);              
                Wait(500);
                toilets.Retail_washroom();
                Wait(500);
              
                player.AlwaysKeepTask = true;
                player.Task.PerformSequence(plSeq);	

I thought i could also mention while i remember to add that when using sequence's.
You don't need to make and use them "inline", you can create a bunch of sequences stored in variables.

Then call them anywhere in your script as you need. Its like have a box and you put the tasks inside the box.

Then you can choose to open the box when ever you want.

The only thing to remember is that a sequence becomes like a single Task. You cant add a none sequenced task to the middle of the sequence.

 

As for your errors, its good to start getting into the habit of checking your variable exists and is what you think before you use it.

var plSeq = new TaskSequence();
if (plSeq != null) 
{
	plSeq.AddTask.
}


Also when using natives, check to make sure you are providing the correct inputs... you have to be exact and provide everything expected.

Function.Call(Hash.SET_ENTITY_HEADING, player, 269.36f);    The Function does not expect the player Class

Function.Call(Hash.SET_ENTITY_HEADING, player.Handle, 269.36f);  It expects the Handle stored in the player class

 

If you add code like below

while (!Function.Call<bool>(Hash.HAS_ANIM_DICT_LOADED, "[email protected]@on_the_toilet"))
{
   Wait(100);
}

What happens if the Anim_Dict doesn't load ?
It will be stuck in the while loop forever.

 DateTime timeout = DateTime.UTCnow.AddSeconds(10);

while (!Function.Call<bool>(Hash.HAS_ANIM_DICT_LOADED, "[email protected]@on_the_toilet"))
{
  if (DateTime.UTCnow > timeout) break;
  
  Wait(100);
}

 

Share this post


Link to post
Share on other sites
Captain Bot

Thanks! All great info that I can use going forward.

 

I did put the sequences in their own class/methods and access them through sequence seq = new sequence(); and call them as seq.method(); Is this not the same as assigning them a variable? Or is the variable method better so I can verify the variable before it is executed?

 

Didn't know SET_ENTITY_HEADING was expecting the entity handle. NativeDB lists the overloads for it as (entity, float)

 

Quote

If you add code like below

while (!Function.Call<bool>(Hash.HAS_ANIM_DICT_LOADED, "[email protected]@on_the_toilet"))
{
   Wait(100);
}

What happens if the Anim_Dict doesn't load ?
It will be stuck in the while loop forever.

This was a c&p taken from some example code. I remember asking myself that question and was planning on using a break function with it but wasn't sure how to implement it yet. The DateTime timeout method  seems like a brilliant way to do this. I can see this coming in very handy

 

cheers

Share this post


Link to post
Share on other sites
Tanjitsu

https://github.com/crosire/scripthookvdotnet/blob/d0a6aa59b582a89f990b471b0ff48c899d3a7a3a/source/scripting_v3/GTA/Entities/Entity.cs#L306

Regarding the sequences, you cab do it however you find it easiest.

 

When you do 

var plSeq = new TaskSequence();

that is putting the tasks in a sequence called plSeq.

So i was just saying that once you build that sequence you can call that anytime you want to execute the tasks inside it.

it doesn't have to be built and run at the same time.
Although.... your uses an animation from a dictionary so you still need to confirm its loaded everytime you want to call that sequence 😛

Share this post


Link to post
Share on other sites
Captain Bot

After visiting the github link I understand. Thanks for all your help thus far😃

Share this post


Link to post
Share on other sites
Captain Bot

Just a quick update. Everything is running smoothly now 😁. I've even been able to simplify my code quite a bit using version 3. All your help is greatly appreciated

Cheers

Share this post


Link to post
Share on other sites
Tanjitsu

Glad too hear it worked out !!

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.