Exemple #1
0
        public static void TaskDriveToEntity(Ped driver, Vehicle vehicle, Entity target, bool getClose)
        {
            int  drivingLoopCount       = 0;
            bool transportVanTeleported = false;
            int  waitCount       = 0;
            bool forceCloseSpawn = false;

            // Get close to player with various checks
            try
            {
                GameFiber.StartNew(delegate
                {
                    while (!forceCloseSpawn)
                    {
                        GameFiber.Yield();
                        if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(EntryPoint.SceneManagementKey))
                        {
                            GameFiber.Sleep(300);
                            if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(EntryPoint.SceneManagementKey))
                            {
                                GameFiber.Sleep(1000);
                                if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(EntryPoint.SceneManagementKey))
                                {
                                    forceCloseSpawn = true;
                                }
                                else
                                {
                                    Game.DisplayNotification("Hold down the ~b~Scene Management Key ~s~to force a close spawn.");
                                }
                            }
                        }
                    }
                });

                Task driveToPed = null;
                driver.Tasks.PerformDrivingManeuver(VehicleManeuver.GoForwardStraight).WaitForCompletion(500);

                while (Vector3.Distance(vehicle.Position, target.Position) > 35f)
                {
                    if (!target.Exists() || !target.IsValid())
                    {
                        return;
                    }

                    vehicle.Repair();
                    if (driveToPed?.IsActive != true)
                    {
                        driver.Tasks.DriveToPosition(target.Position, 15f, VehicleDrivingFlags.FollowTraffic | VehicleDrivingFlags.DriveAroundVehicles | VehicleDrivingFlags.DriveAroundObjects | VehicleDrivingFlags.AllowMedianCrossing | VehicleDrivingFlags.YieldToCrossingPedestrians);
                    }

                    NativeFunction.Natives.SET_DRIVE_TASK_DRIVING_STYLE(driver, 786607);
                    NativeFunction.Natives.SET_DRIVER_AGGRESSIVENESS(driver, 0f);
                    NativeFunction.Natives.SET_DRIVER_ABILITY(driver, 1f);
                    GameFiber.Wait(600);
                    waitCount++;
                    if (waitCount == 55)
                    {
                        Game.DisplayHelp("Service taking too long? Hold down ~b~" + EntryPoint.KeyConvert.ConvertToString(EntryPoint.SceneManagementKey) + " ~s~to speed it up.", 5000);
                    }

                    //If van isn't moving
                    if (vehicle.Speed < 2f)
                    {
                        drivingLoopCount++;
                    }

                    //if van is very far away
                    if (Vector3.Distance(target.Position, vehicle.Position) > EntryPoint.SceneManagementSpawnDistance + 65f)
                    {
                        drivingLoopCount++;
                    }

                    //If Van is stuck, relocate it
                    if (drivingLoopCount >= 33 && drivingLoopCount <= 38 && EntryPoint.AllowWarping)
                    {
                        Vector3 SpawnPoint;
                        float   Heading;
                        bool    UseSpecialID = true;
                        float   travelDistance;
                        int     wC = 0;
                        while (true)
                        {
                            GetSpawnPoint(target.Position, out SpawnPoint, out Heading, UseSpecialID);
                            travelDistance = Rage.Native.NativeFunction.Natives.CALCULATE_TRAVEL_DISTANCE_BETWEEN_POINTS <float>(SpawnPoint.X, SpawnPoint.Y, SpawnPoint.Z, target.Position.X, target.Position.Y, target.Position.Z);
                            wC++;
                            if (Vector3.Distance(target.Position, SpawnPoint) > EntryPoint.SceneManagementSpawnDistance - 15f && travelDistance < (EntryPoint.SceneManagementSpawnDistance * 4.5f))
                            {
                                var spawnDirection = (target.Position - SpawnPoint);
                                spawnDirection.Normalize();

                                var headingToPlayer = MathHelper.ConvertDirectionToHeading(spawnDirection);

                                if (Math.Abs(MathHelper.NormalizeHeading(Heading) - MathHelper.NormalizeHeading(headingToPlayer)) < 150f)
                                {
                                    break;
                                }
                            }
                            if (wC >= 400)
                            {
                                UseSpecialID = false;
                            }
                            GameFiber.Yield();
                        }

                        Game.Console.Print("Relocating because service was stuck...");
                        vehicle.Position = SpawnPoint;

                        vehicle.Heading  = Heading;
                        drivingLoopCount = 39;
                    }
                    // if van is stuck for a 2nd time or takes too long, spawn it very near to the car
                    else if (((drivingLoopCount >= 70 || waitCount >= 110) && EntryPoint.AllowWarping) || forceCloseSpawn)
                    {
                        Game.Console.Print("Relocating service to a close position");

                        Vector3 SpawnPoint = World.GetNextPositionOnStreet(target.Position.Around2D(15f));

                        int waitCounter = 0;
                        while ((SpawnPoint.Z - target.Position.Z < -3f) || (SpawnPoint.Z - target.Position.Z > 3f) || (Vector3.Distance(SpawnPoint, target.Position) > 26f))
                        {
                            waitCounter++;
                            SpawnPoint = World.GetNextPositionOnStreet(target.Position.Around(20f));
                            GameFiber.Yield();
                            if (waitCounter >= 500)
                            {
                                SpawnPoint = target.Position.Around(20f);
                                break;
                            }
                        }
                        Vector3 directionFromVehicleToPed = (target.Position - SpawnPoint);
                        directionFromVehicleToPed.Normalize();

                        float vehicleHeading = MathHelper.ConvertDirectionToHeading(directionFromVehicleToPed);
                        vehicle.Heading  = vehicleHeading + 180f;
                        vehicle.Position = SpawnPoint;

                        transportVanTeleported = true;

                        break;
                    }
                }

                forceCloseSpawn = true;
                //park the van
                Game.HideHelp();
                if (!getClose)
                {
                    while (((Vector3.Distance(target.Position, vehicle.Position) > 19f && (vehicle.Position.Z - target.Position.Z < -2.5f)) || (vehicle.Position.Z - target.Position.Z > 2.5f)) && !transportVanTeleported)
                    {
                        if (!target.Exists() || !target.IsValid())
                        {
                            return;
                        }

                        Rage.Task parkNearcar = driver.Tasks.DriveToPosition(target.Position, 6f, VehicleDrivingFlags.DriveAroundVehicles | VehicleDrivingFlags.DriveAroundObjects | VehicleDrivingFlags.AllowMedianCrossing | VehicleDrivingFlags.YieldToCrossingPedestrians);
                        parkNearcar.WaitForCompletion(900);

                        if (Vector3.Distance(target.Position, vehicle.Position) > 60f)
                        {
                            Vector3 SpawnPoint = World.GetNextPositionOnStreet(target.Position.Around(10f));

                            int waitCounter = 0;
                            while ((SpawnPoint.Z - target.Position.Z < -3f) || (SpawnPoint.Z - target.Position.Z > 3f) || (Vector3.Distance(SpawnPoint, target.Position) > 26f))
                            {
                                waitCounter++;
                                SpawnPoint = World.GetNextPositionOnStreet(target.Position.Around(20f));
                                GameFiber.Yield();
                                if (waitCounter >= 500)
                                {
                                    SpawnPoint = target.Position.Around(20f);
                                    break;
                                }
                            }
                            Vector3 directionFromVehicleToPed = (target.Position - SpawnPoint);
                            directionFromVehicleToPed.Normalize();

                            float vehicleHeading = MathHelper.ConvertDirectionToHeading(directionFromVehicleToPed);
                            vehicle.Heading  = vehicleHeading + 180f;
                            vehicle.Position = SpawnPoint;

                            transportVanTeleported = true;
                        }
                    }
                }
                else
                {
                    while ((Vector3.Distance(target.Position, vehicle.Position) > 17f) || transportVanTeleported)
                    {
                        if (!target.Exists() || !target.IsValid())
                        {
                            return;
                        }
                        Rage.Task parkNearSuspect = driver.Tasks.DriveToPosition(target.Position, 6f, VehicleDrivingFlags.FollowTraffic | VehicleDrivingFlags.DriveAroundVehicles | VehicleDrivingFlags.DriveAroundObjects | VehicleDrivingFlags.AllowMedianCrossing | VehicleDrivingFlags.YieldToCrossingPedestrians);
                        parkNearSuspect.WaitForCompletion(800);
                        transportVanTeleported = false;
                        if (Vector3.Distance(target.Position, vehicle.Position) > 50f)
                        {
                            vehicle.Position = World.GetNextPositionOnStreet(target.Position.Around(12f));
                        }
                    }
                    GameFiber.Sleep(600);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
            {
                // If we don't catch everything we got, we will crash the plug-in
                // That is what analyzers would not understand
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
Exemple #2
0
        private static void driveToPosition(Ped driver, Vehicle veh, Vector3 pos)
        {
            Ped  playerPed              = Game.LocalPlayer.Character;
            int  drivingLoopCount       = 0;
            bool transportVanTeleported = false;
            int  waitCount              = 0;
            bool forceCloseSpawn        = false;

            GameFiber.StartNew(delegate
            {
                while (!forceCloseSpawn)
                {
                    GameFiber.Yield();
                    if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(System.Windows.Forms.Keys.H)) // || Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(multiTransportKey))
                    {
                        GameFiber.Sleep(500);
                        if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(System.Windows.Forms.Keys.H))// || Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(multiTransportKey))
                        {
                            GameFiber.Sleep(500);
                            if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(System.Windows.Forms.Keys.H))// || Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(multiTransportKey))
                            {
                                forceCloseSpawn = true;
                            }
                            else
                            {
                                Game.DisplayNotification("Hold down the ~b~H ~s~to force a close spawn.");
                            }
                        }
                    }
                }
            });
            Rage.Task driveToPed = null;
            NativeFunction.Natives.SET_DRIVER_AGGRESSIVENESS(driver, 0f);
            NativeFunction.Natives.SET_DRIVER_ABILITY(1f);
            while (Vector3.Distance(veh.Position, pos) > 35f)
            {
                veh.Repair();
                if (driveToPed != null && !driveToPed.IsActive)
                {
                    driveToPed = driver.Tasks.DriveToPosition(pos, MathHelper.ConvertKilometersPerHourToMetersPerSecond(60f), VehicleDrivingFlags.DriveAroundVehicles | VehicleDrivingFlags.DriveAroundObjects | VehicleDrivingFlags.AllowMedianCrossing | VehicleDrivingFlags.YieldToCrossingPedestrians);
                }
                GameFiber.Wait(600);

                waitCount++;
                //If van isn't moving
                if (!veh.IsBoat)
                {
                    if (veh.Speed < 0.2f)
                    {
                        driver.Tasks.PerformDrivingManeuver(veh, VehicleManeuver.ReverseStraight, 700).WaitForCompletion();
                        drivingLoopCount += 2;
                        driver.Tasks.DriveToPosition(pos, MathHelper.ConvertKilometersPerHourToMetersPerSecond(60f), VehicleDrivingFlags.DriveAroundVehicles | VehicleDrivingFlags.DriveAroundObjects | VehicleDrivingFlags.AllowMedianCrossing | VehicleDrivingFlags.YieldToCrossingPedestrians).WaitForCompletion(100);
                    }
                    if (veh.Speed < 2f)
                    {
                        drivingLoopCount++;
                    }
                    //if van is very far away
                    if ((Vector3.Distance(pos, veh.Position) > spawnDistance + 70f))
                    {
                        drivingLoopCount++;
                    }
                    //If Van is stuck, relocate it

                    if ((drivingLoopCount == 30) || (drivingLoopCount == 31) || (drivingLoopCount == 32) || (drivingLoopCount == 33))
                    {
                        SpawnPoint sp = SpawnPointExtensions.GetVehicleSpawnPointTowardsPositionWithChecks(suspectVehicle.Position, spawnDistance);
                        Game.Console.Print("Relocating because k9 was stuck...");
                        veh.Position = sp;

                        veh.Heading      = sp;
                        drivingLoopCount = 34;
                        Game.DisplayHelp("K9 taking too long? Hold down ~b~H ~s~to speed it up.", 5000);
                    }
                    // if van is stuck for a 2nd time or takes too long, spawn it very near to the suspect
                    else if ((drivingLoopCount >= 55) || waitCount >= 90 || forceCloseSpawn)
                    {
                        Game.Console.Print("Relocating to a closer position");

                        Vector3 SpawnPoint = World.GetNextPositionOnStreet(pos.Around2D(15f));

                        int waitCounter = 0;
                        while ((SpawnPoint.Z - pos.Z < -3f) || (SpawnPoint.Z - pos.Z > 3f) || (Vector3.Distance(SpawnPoint, pos) > 25f))
                        {
                            waitCounter++;
                            SpawnPoint = World.GetNextPositionOnStreet(pos.Around2D(15f));
                            GameFiber.Yield();
                            if (waitCounter >= 500)
                            {
                                SpawnPoint = pos.Around2D(15f);
                                break;
                            }
                        }
                        veh.Position = SpawnPoint;
                        Vector3 directionFromVehicleToPed = (pos - SpawnPoint);
                        directionFromVehicleToPed.Normalize();

                        float vehicleHeading = MathHelper.ConvertDirectionToHeading(directionFromVehicleToPed);
                        veh.Heading            = vehicleHeading;
                        transportVanTeleported = true;

                        break;
                    }
                }
                else
                {
                    NativeFunction.Natives.REQUEST_COLLISION_AT_COORD(veh.Position.X, veh.Position.Y, veh.Position.Z);
                    NativeFunction.Natives.REQUEST_ADDITIONAL_COLLISION_AT_COORD(veh.Position.X, veh.Position.Y, veh.Position.Z);

                    if (waitCount > 85)
                    {
                        break;
                    }
                    if (veh.Speed < 0.2f)
                    {
                        NativeFunction.Natives.SET_VEHICLE_FORWARD_SPEED(veh, 15f);
                        GameFiber.Wait(700);
                    }
                }
            }

            forceCloseSpawn = true;
            //park the van
            int reverseCount = 0;

            Game.HideHelp();
            while ((Vector3.Distance(pos, veh.Position) > 21f) && !transportVanTeleported)
            {
                Rage.Task parkNearSuspect = driver.Tasks.DriveToPosition(pos, MathHelper.ConvertKilometersPerHourToMetersPerSecond(30f), VehicleDrivingFlags.DriveAroundVehicles | VehicleDrivingFlags.DriveAroundObjects | VehicleDrivingFlags.AllowMedianCrossing | VehicleDrivingFlags.YieldToCrossingPedestrians);
                parkNearSuspect.WaitForCompletion(800);
                transportVanTeleported = false;
                if (Vector3.Distance(pos, veh.Position) > 75f)
                {
                    Vector3 SpawnPoint = World.GetNextPositionOnStreet(pos.Around(12f));
                    veh.Position = SpawnPoint;
                }
                if (veh.Speed < 0.2f)
                {
                    reverseCount++;
                    if (reverseCount == 3)
                    {
                        driver.Tasks.PerformDrivingManeuver(veh, VehicleManeuver.ReverseStraight, 1700).WaitForCompletion();
                        reverseCount = 0;
                    }
                }

                if ((veh.IsBoat && veh.DistanceTo(pos) < 25) || ExtensionMethods.IsPointOnWater(pos))
                {
                    break;
                }
            }
            GameFiber.Wait(600);
        }
Exemple #3
0
        public static void MakePedFollowPlayer()
        {
            Blip PedBlip;

            GameFiber.StartNew(delegate
            {
                pedfollowing = GetNearestValidPed();
                if (!pedfollowing)
                {
                    return;
                }
                PedBlip       = pedfollowing.AttachBlip();
                PedBlip.Color = System.Drawing.Color.Yellow;

                PedBlip.Flash(400, -1);
                EnableFollow         = true;
                FollowItem.Text      = "Stop follow";
                CallTaxiItem.Enabled = false;
                GrabItem.Enabled     = false;
                if (TransportToHospitalItem != null)
                {
                    TransportToHospitalItem.Enabled = false;
                }
                if (EntryPoint.IsLSPDFRPlusRunning)
                {
                    API.LSPDFRPlusFuncs.AddCountToStatistic(Main.PluginName, "People made to follow you");
                }
                while (pedfollowing.Exists())
                {
                    GameFiber.Yield();
                    if (!pedfollowing.Exists())
                    {
                        break;
                    }
                    if (EnableFollow)
                    {
                        if (Vector3.Distance(Game.LocalPlayer.Character.Position, pedfollowing.Position) > 2.3f)
                        {
                            FollowTask = pedfollowing.Tasks.FollowNavigationMeshToPosition(Game.LocalPlayer.Character.GetOffsetPosition(Vector3.RelativeBack * 1.5f), pedfollowing.Heading, 1.6f);
                            FollowTask.WaitForCompletion(600);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (pedfollowing.Exists())
                {
                    pedfollowing.Tasks.StandStill(7000);
                }
                EnableFollow    = false;
                FollowItem.Text = "Follow";
                if (PedBlip.Exists())
                {
                    PedBlip.Delete();
                }
                CallTaxiItem.Enabled = true;
                GrabItem.Enabled     = true;
                if (TransportToHospitalItem != null)
                {
                    TransportToHospitalItem.Enabled = true;
                }
            });
        }
Exemple #4
0
        public void EndTrafficStop()
        {
            GameFiber.StartNew(delegate
            {
                try
                {
                    if (DriverPickedUp || PassengerPickedUp)
                    {
                        if (DriverPickedUp && PassengerPickedUp)
                        {
                            //done
                        }
                        else if (DriverPickedUp)
                        {
                            if (!Functions.IsPedArrested(Passenger) && !Passenger.IsDead)
                            {
                                if (!Passenger.IsInVehicle(veh, false))
                                {
                                    Passenger.Tasks.FollowNavigationMeshToPosition(veh.GetOffsetPosition(Vector3.RelativeLeft * 2f), veh.Heading - 90f, 1.4f);
                                    Passenger.Tasks.EnterVehicle(veh, 7000, -1).WaitForCompletion();
                                }
                            }
                        }
                        else if (PassengerPickedUp)
                        {
                            if (!Functions.IsPedArrested(Driver) && !Driver.IsDead)
                            {
                                if (!Driver.IsInVehicle(veh, false))
                                {
                                    Driver.Tasks.FollowNavigationMeshToPosition(veh.GetOffsetPosition(Vector3.RelativeLeft * 2f), veh.Heading - 90f, 1.4f);
                                    Driver.Tasks.EnterVehicle(veh, 7000, -1).WaitForCompletion();
                                }
                            }
                        }
                    }



                    else
                    {
                        bool DriverInVehicle = Driver.IsInVehicle(veh, false);


                        bool PassengerInVehicle = Passenger.IsInVehicle(veh, false);

                        if (Functions.IsPedArrested(Driver) && Functions.IsPedArrested(Passenger))
                        {
                        }
                        else if (Functions.IsPedArrested(Driver) && !Passenger.IsDead)
                        {
                            if (!PassengerInVehicle)
                            {
                                Passenger.Tasks.FollowNavigationMeshToPosition(veh.GetOffsetPosition(Vector3.RelativeLeft * 2f), veh.Heading - 90f, 1.4f);
                                Passenger.Tasks.EnterVehicle(veh, 7000, -1).WaitForCompletion();
                            }
                        }
                        else if (Functions.IsPedArrested(Passenger) && !Driver.IsDead)
                        {
                            if (!DriverInVehicle)
                            {
                                Driver.Tasks.FollowNavigationMeshToPosition(veh.GetOffsetPosition(Vector3.RelativeLeft * 2f), veh.Heading - 90f, 1.4f).WaitForCompletion(3500);
                                Driver.Tasks.EnterVehicle(veh, 7000, -1).WaitForCompletion();
                            }
                        }
                        else
                        {
                            if (!DriverInVehicle || !PassengerInVehicle)
                            {
                                if (!DriverInVehicle && !PassengerInVehicle && !Driver.IsDead && !Passenger.IsDead)
                                {
                                    Driver.Tasks.FollowNavigationMeshToPosition(veh.GetOffsetPosition(Vector3.RelativeLeft * 2f), veh.Heading - 90f, 1.4f);
                                    Passenger.Tasks.FollowNavigationMeshToPosition(veh.GetOffsetPosition(Vector3.RelativeRight * 2f), veh.Heading - 90f, 1.4f);
                                    GameFiber.Wait(3500);
                                    driverEnter    = Driver.Tasks.EnterVehicle(veh, 7000, -1);
                                    passengerEnter = Passenger.Tasks.EnterVehicle(veh, 7000, 0);
                                    while (driverEnter.IsActive || passengerEnter.IsActive)
                                    {
                                        GameFiber.Yield();
                                    }
                                }
                                else if (!DriverInVehicle && !Driver.IsDead)
                                {
                                    Driver.Tasks.FollowNavigationMeshToPosition(veh.GetOffsetPosition(Vector3.RelativeLeft * 2f), veh.Heading - 90f, 1.4f).WaitForCompletion(3500);
                                    Driver.Tasks.EnterVehicle(veh, 7000, -1).WaitForCompletion();
                                }
                                else if (!PassengerInVehicle && !Passenger.IsDead)
                                {
                                    Passenger.Tasks.FollowNavigationMeshToPosition(veh.GetOffsetPosition(Vector3.RelativeRight * 2f), veh.Heading - 90f, 1.4f);
                                    Passenger.Tasks.EnterVehicle(veh, 7000, 0).WaitForCompletion();
                                }
                            }
                        }
                    }

                    if (veh.HasDriver && veh.Driver != Game.LocalPlayer.Character)
                    {
                        veh.Driver.Tasks.PerformDrivingManeuver(VehicleManeuver.GoForwardStraight).WaitForCompletion(600);
                        veh.Driver.Tasks.CruiseWithVehicle(18f);
                        Rage.Native.NativeFunction.Natives.SET_DRIVE_TASK_DRIVING_STYLE(veh.Driver, 786603);
                    }
                }
                catch (Exception e) { Game.LogTrivial(e.ToString()); }
                finally
                {
                    TrafficStopActive = false;
                    ReadyForCleanup   = true;
                }
            });
        }