Jump to content
Darkmyre

Ped not moving during callout

Recommended Posts

Working on my first plugin, and having a lot of trouble getting a callout to work. I have a couple of callouts based on the API examples on github that are working fine, but no matter what I try, when I accept the third callout the suspect spawns but never ever moves or does anything. My aim was to make the ped find a nearby vehicle and steal it triggering a pursuit (and wandering the streets looking for one if it cant find a vehicle). Can anyone offer any pointers on where I'm going wrong? (This is my first dabbling with C#, so well aware I'm probably making some really stupid error)

Spoiler

            Suspect suspect = (Suspect)GetPed("Suspect1");
            if (suspect.Exists()) { suspect.Tasks.Wander(); }

            if (pursuitInitiated && !Functions.IsPursuitStillRunning(pursuit))
            {
                End();
            }
            else if (!pursuitInitiated)
            {
                if (suspect == null || !suspect.Exists() || suspect.IsDead)
                {
                    Game.DisplaySubtitle("Suspect has fled the scene.", 5000);
                    End();
                }
                else if (car == null)
                {
                    suspect.Tasks.Wander();
                    Game.DisplayNotification("Checking for cars...");
                    Vehicle[] stolen = suspect.GetNearbyVehicles(16);
                    if (stolen != null && stolen.GetLength(0) > 0)
                    {
                        car = stolen[0];
                        Game.DisplayNotification(car.Model.Name);
                    } else
                    {
                        Game.DisplayNotification("No cars!");
                    }
                } else if (suspect.IsInAnyVehicle(false))
                {
                    Game.DisplayNotification("Entered vehicle");
                    base.DeleteBlip();
                    pursuit = Functions.CreatePursuit();
                    Functions.AddPedToPursuit(this.pursuit, suspect);
                 } else
                {
                    Game.DisplayNotification("Move to entity");
                    Game.DisplayNotification(car.Model.Name);
                    NativeFunction.CallByName<uint>("TASK_GO_TO_ENTITY", suspect, car, 10, 5, 150, 1073741824, 0);
                    if (car.Exists())
                    {
                        Game.DisplayNotification("Attempt to enter");
                        suspect.Tasks.EnterVehicle(car, -1);
                    }
                }
            }

 

 

Share this post


Link to post
Share on other sites

Hmm, this is pretty much the entirety of my Process() function, I'm not really sure what else would be relevant? (The only thing I havent included is the call to base.Process(); as I used the Inheritance api example as a starting point). I read in a couple of other topics the point about EnterVehicle(), and so had tried adding the call to TASK_GO_TO_ENTITY... but even the earlier call to suspect.Tasks.Wander() isn't doing anything, the suspect ped just stands there like a statue for the whole callout. I tried wrapping it all in a GameFiber and sleeping for 5-10 seconds after each task which didnt achieve anything. All the sections of the code are triggering correctly, as I'm seeing the notifications pop up for each step as expected, the tasks just aren't being triggered. Which leads me to believe either I've messed something up and am somehow accessing a different / invalid ped (I'd think that'd trigger some kind of fatal error though?), or I've totally misunderstood something basic about how the whole ped tasks work. Do I need to add something to make the ped execute the tasks once assigned? Should I be calling Tasks.Clear() before setting a new task?

I've even tried adding a call to Tasks.Wander when I first spawn the ped which also has him stand around doing nothing:

Spoiler

        public override bool OnBeforeCalloutDisplayed()
        {
            // first we check for agency
            if (Common.myAgency != "LSPD" && Common.myAgency != "County Sheriff" && Common.myAgency != "Highway Patrol") return false;
            base.OnBeforeCalloutDisplayed();

            //Create our ped in the world
            Suspect myPed = new Suspect("Suspect1", "a_m_y_mexthug_01", SpawnPoint, 0, true);

            //Now we have spawned them, check they actually exist and if not return false (preventing the callout from being accepted and aborting it)
            if (!myPed.Exists()) return false;

            Peds.Add(myPed);

            //If we made it this far both exist so let's warp the ped into the driver seat
            myPed.GiveNewWeapon("WEAPON_PISTOL", 500, true);
            myPed.Tasks.Wander();

            // Show the user where the pursuit is about to happen and block very close peds.
            this.ShowCalloutAreaBlipBeforeAccepting(SpawnPoint, 50f);
            this.AddMinimumDistanceCheck(5f, myPed.Position);

            // Set up our callout message and location
            this.CalloutMessage = "GTA In Progress";
            this.CalloutPosition = SpawnPoint;

            //Play the police scanner audio for this callout (available as of the 0.2a API)
            Functions.PlayScannerAudioUsingPosition("CITIZENS_REPORT CRIME_GRAND_THEFT_AUTO_03 IN_OR_ON_POSITION", SpawnPoint);
            return true;

        }

 

 

Share this post


Link to post
Share on other sites

Hmm, I'm definitely doing something wrong with the tasks. I tried tweaking it so none of the moving to entity / entering vehicle code triggers unless the player is on the scene, and set it to spawn a sentinel 10f away from the ped at the start. Now when I get to the scene, the ped starts moving over and reaches for the car, /then/ becomes immobile.

Share this post


Link to post
Share on other sites
On 11/28/2015, 8:08:52, Darkmyre said:

Hmm, I'm definitely doing something wrong with the tasks. I tried tweaking it so none of the moving to entity / entering vehicle code triggers unless the player is on the scene, and set it to spawn a sentinel 10f away from the ped at the start. Now when I get to the scene, the ped starts moving over and reaches for the car, /then/ becomes immobile.

Try this:

suspect.Tasks.EnterVehicle(car, 10000, -1).WaitForCompletion();

This will ensure no other code executes in that Game Fiber before the suspect is in the car. I think you may be overriding tasks, but I can't be sure because I only have a snippet of your code.

Other relevant code would be your (inherited?) Suspect class, as you may be overriding basic Ped behaviour.

Share this post


Link to post
Share on other sites

Hmm, that didn't seem to help either. I've even tried changing it to use the default Ped class which didnt change anything. Debating between starting over and just plain giving up at this point as I've clearly screwed something up at a pretty fundamental level lol.... thanks heaps for trying to help out

Edited by Darkmyre

Share this post


Link to post
Share on other sites
public override bool OnBeforeCalloutDisplayed()
        {
            // first we check for agency
            if (Common.myAgency != "LSPD" && Common.myAgency != "County Sheriff" && Common.myAgency != "Highway Patrol") return false;
            

            //Create our ped in the world
            Suspect myPed = new Suspect("Suspect1", "a_m_y_mexthug_01", SpawnPoint, 0, true);

            //Now we have spawned them, check they actually exist and if not return false (preventing the callout from being accepted and aborting it)
            if (!myPed.Exists()) return false;

            Peds.Add(myPed);

            //If we made it this far both exist so let's warp the ped into the driver seat
            myPed.GiveNewWeapon("WEAPON_PISTOL", 500, true);
            myPed.Tasks.Wander();

            // Show the user where the pursuit is about to happen and block very close peds.
            this.ShowCalloutAreaBlipBeforeAccepting(SpawnPoint, 50f);
            this.AddMinimumDistanceCheck(5f, myPed.Position);

            // Set up our callout message and location
            this.CalloutMessage = "GTA In Progress";
            this.CalloutPosition = SpawnPoint;

            //Play the police scanner audio for this callout (available as of the 0.2a API)
            Functions.PlayScannerAudioUsingPosition("CITIZENS_REPORT CRIME_GRAND_THEFT_AUTO_03 IN_OR_ON_POSITION", SpawnPoint);
            return base.OnBeforeCalloutDisplayed();

        }

Try that with returning the base.

Also, can you post your End() method? You need to be aware of the fact that calling your End method doesn't necessarily stop all your other methods: I recommend  adding some kind of boolean e.g. CalloutRunning that you set to false in your End method and make your logic loops break when it's set to false.

Share this post


Link to post
Share on other sites

Oddly, that just makes the callout basically do nothing - theres no ped or vehicle spawned when I get to the callout. My plugin is so messed up at the moment from trying random things, I think I'm going to just start over with a totally fresh VS solution... and probably ditch this particular callout because of all the frustration its caused me. I think some of my problems are probably coming from the fact I was just building on top of the inheritance api example, and some of the code in there I don't quite fully understand.

Thanks again for all your help Albo :)

Albo1125 likes this

Share this post


Link to post
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


×