[C#] TaskSequence - InvokeNative: execution failed

I was doing some testing as I am looking to create a script that would require some managing of peds. During this testing, I also had a 2nd player (my other computer) in the server with me. I had the other player standing near me, and I was trying to spawn 3 peds and perform a simple TaskSequence.

My other computer was able to do this just fine with no error, but on my computer I got the following error in the client console.

[   2193218] InvokeNative: execution failed: Error executing native 0x93b93a37987f1f3d at address 0x140a6f96e.

The native corresponds to one of the tasks in the tasksequence. I have tried changing tasks, moving them around, commenting some, etc. After I get this error, I’m unable to press the button and spawn any more – as if the script crashed.

I always get an error of this sort (with the respective native code) when I try this on my main computer. If my other computer is disconnected, I can do this just fine. If I connect to the server after my other computer, I can do this just fine (but then my other computer can’t do it).

Here’s the code I am using. I really hope somebody can help me out with this :sweat_smile:. Also, the “NetworkRequestControlOfEntity” returns true (never has to request it), and I still get the error.


            if (Game.IsControlJustReleased(0, Control.PhoneUp))
            {
                Ped first = await World.CreatePed(new Model(1004114196), new Vector3(2050f, 3450f, 44f)); // bodybuilding lady
                Ped second = await World.CreatePed(new Model(2119136831), new Vector3(2045f, 3450f, 44f)); // chinese man
                Ped third = await World.CreatePed(new Model(275618457), new Vector3(2040f, 3450f, 44f)); // mask man       

                Debug.WriteLine($"(1) {API.NetworkRequestControlOfEntity(second.Handle)}");
                while (!API.NetworkRequestControlOfEntity(second.Handle))
                {
                    await Delay(250);
                    API.NetworkRequestControlOfEntity(second.Handle);
                    Debug.WriteLine($"REQUESTED...");
                }
                Debug.WriteLine($"(2) {API.NetworkRequestControlOfEntity(second.Handle)}");

                TaskSequence ts = new TaskSequence();
                ts.AddTask.AchieveHeading(180f);
                ts.AddTask.GoTo(new Vector3(2030f, 3450f, 44f));
                ts.AddTask.FleeFrom(new Vector3(2045f, 3450f, 44f));
                ts.Close();

                first.Task.PerformSequence(ts);
                second.Task.PerformSequence(ts);
                third.Task.PerformSequence(ts);
            }

Just did another test where my other computer (the network host) is far away. That computer can still spawn the peds, but it will not execute the tasks.

My main computer and spawn and peds and do the task sequence when the other computer is far away… This is making me want to pull my hair out.

Edit: Did a little more testing – it seems to just be tasksequences that are doing this. So far, I’m able to run a normal task fine. If I do a task, it depends on who is closest to the ped. If someone far away tells the ped to run… the ped will run briefly, but will stop if someone else it close to the ped to “control” it I guess. Still looking into it…

GET_SCRIPT_TASK_STATUS to identify if the ped is still running the intended task.

It will play for a split second before stopping (if triggered by a further away player). Even with using that native (which I tested, and works), I would have to loop and spam from that further player. It would just be better to find out who has control and then play the task from that client I suppose.

Do you know if there is anyway to get NETWORK_REQUEST_CONTROL_OF_ENTITY to work? I put that in a loop to try and get control, but no luck.

I could also just have every client make the task play on that ped, which is what I have been doing for other things. I was just hoping there was a better way. :face_with_thermometer: