public static void HandleSetCustomPullover(object sender, CustomPulloverEvent customPulloverEvent)
 {
     Functions.SetCustomPulloverLocation(customPulloverEvent);
 }
        public static void SetCustomPulloverLocation(CustomPulloverEvent customPulloverEvent)
        {
            Blip driverBlip = customPulloverEvent.PulledDriver.AttachBlip();

            driverBlip.Flash(500, -1);
            driverBlip.Color = System.Drawing.Color.Yellow;
            if (Tools.HavingChance(2, 10))
            {
                customPulloverEvent.PulledDriver.CanAttackFriendlies = true;
            }
            Vehicle playerPatrolCar = PedsManager.LocalPlayer().CurrentVehicle;
            int     checkpoint      = 0;

            try
            {
                Vector3 checkPointPosition = PedsManager.LocalPlayer().GetOffsetPosition(new Vector3(0f, 8f, -1f));
                checkpoint = NativeFunction.Natives.CREATE_CHECKPOINT <int>(46, checkPointPosition.X, checkPointPosition.Y, checkPointPosition.Z, checkPointPosition.X, checkPointPosition.Y, checkPointPosition.Z, 3.5f, 255, 0, 0, 255, 0);;
                float xOffset       = 0;
                float yOffset       = 0;
                float zOffset       = 0;
                bool  SuccessfulSet = false;
                while (true)
                {
                    GameFiber.Wait(70);
                    Game.DisplaySubtitle("Set your desired ~o~pullover ~s~location. Hold ~b~Enter ~s~when done.", 100);
                    checkPointPosition = PedsManager.LocalPlayer().GetOffsetPosition(new Vector3((float)xOffset + 0.5f, (float)(yOffset + 8), (float)(-1 + zOffset)));
                    if (false == CustomPulloverEventHandler.IsAlreadyFollowing)
                    {
                        break;
                    }
                    if (false == FunctionsLSPDFR.IsPlayerPerformingPullover())
                    {
                        Game.DisplayNotification("You cancelled the ~b~Traffic Stop.");
                        break;
                    }
                    if (false == PedsManager.LocalPlayer().IsInVehicle(playerPatrolCar, false))
                    {
                        break;
                    }

                    if (KeysManager.IsKeyDownRightNowComputerCheck(Configuration.Instance.ReadKey(CustomPulloverEventHandler.K_POS_RESET, "NumPad5")))
                    {
                        xOffset = 0;
                        yOffset = 0;
                        zOffset = 0;
                    }
                    if (KeysManager.IsKeyDownRightNowComputerCheck(Configuration.Instance.ReadKey(CustomPulloverEventHandler.K_POS_FORWARD, "NumPad8")))
                    {
                        yOffset++;
                    }
                    if (KeysManager.IsKeyDownRightNowComputerCheck(Configuration.Instance.ReadKey(CustomPulloverEventHandler.K_POS_BACK, "NumPad2")))
                    {
                        yOffset--;
                    }
                    if (KeysManager.IsKeyDownRightNowComputerCheck(Configuration.Instance.ReadKey(CustomPulloverEventHandler.K_POS_RIGHT, "NumPad6")))
                    {
                        xOffset++;
                    }
                    if (KeysManager.IsKeyDownRightNowComputerCheck(Configuration.Instance.ReadKey(CustomPulloverEventHandler.K_POS_LEFT, "NumPad4")))
                    {
                        xOffset--;
                    }
                    if (KeysManager.IsKeyDownRightNowComputerCheck(Configuration.Instance.ReadKey(CustomPulloverEventHandler.K_POS_UP, "NumPad9")))
                    {
                        zOffset++;
                    }
                    if (KeysManager.IsKeyDownRightNowComputerCheck(Configuration.Instance.ReadKey(CustomPulloverEventHandler.K_POS_DOWN, "NumPad3")))
                    {
                        zOffset--;
                    }

                    if (KeysManager.IsKeyDownRightNowComputerCheck(System.Windows.Forms.Keys.Enter))
                    {
                        SuccessfulSet = true;
                        break;
                    }

                    NativeFunction.Natives.DELETE_CHECKPOINT(checkpoint);
                    checkpoint = NativeFunction.Natives.CREATE_CHECKPOINT <int>(46, checkPointPosition.X, checkPointPosition.Y, checkPointPosition.Z, checkPointPosition.X, checkPointPosition.Y, checkPointPosition.Z, 3f, 255, 0, 0, 255, 0);
                    NativeFunction.Natives.SET_CHECKPOINT_CYLINDER_HEIGHT(checkpoint, 2f, 2f, 2f);
                }
                NativeFunction.Natives.DELETE_CHECKPOINT(checkpoint);

                if (SuccessfulSet)
                {
                    try
                    {
                        playerPatrolCar.BlipSiren(true);
                        Game.LocalPlayer.Character.Tasks.PlayAnimation("friends@frj@ig_1", "wave_c", 1f, AnimationFlags.SecondaryTask | AnimationFlags.UpperBodyOnly);
                    }
                    catch { }
                    while (true)
                    {
                        GameFiber.Yield();
                        if (Vector3.Distance(customPulloverEvent.PulledDriver.Position, PedsManager.LocalPlayer().Position) > 25f)
                        {
                            Game.DisplaySubtitle("~h~~r~Stay close to the vehicle.", 700);
                        }

                        if (false == FunctionsLSPDFR.IsPlayerPerformingPullover())
                        {
                            Game.DisplayNotification("You cancelled the ~b~Traffic Stop.");
                            break;
                        }

                        if (false == PedsManager.LocalPlayer().IsInVehicle(playerPatrolCar, false) || false == CustomPulloverEventHandler.IsAlreadyFollowing)
                        {
                            break;
                        }


                        Rage.Task drivetask = customPulloverEvent.PulledDriver.Tasks.DriveToPosition(checkPointPosition, 12f, VehicleDrivingFlags.DriveAroundVehicles | VehicleDrivingFlags.DriveAroundObjects | VehicleDrivingFlags.AllowMedianCrossing | VehicleDrivingFlags.YieldToCrossingPedestrians);
                        GameFiber.Wait(700);
                        if (false == drivetask.IsActive || Vector3.Distance(customPulloverEvent.PulledDriver.Position, checkPointPosition) < 1.5f) //exit if driver end task or is away from the expected position
                        {
                            break;
                        }
                    }
                    if (customPulloverEvent.pulledVehicle.Exists())
                    {
                        if (customPulloverEvent.PulledDriver.Exists())
                        {
                            customPulloverEvent.PulledDriver.Tasks.PerformDrivingManeuver(VehicleManeuver.Wait);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                NativeFunction.Natives.DELETE_CHECKPOINT(checkpoint);
                Game.LogTrivial("---------- EXCEPTION ---------");
                Game.LogTrivial(e.Message);
                Game.LogTrivial("---------- END  ---------");
            }
            finally
            {
                if (driverBlip.IsValid() && driverBlip.Exists())
                {
                    driverBlip.Delete();
                }
                CustomPulloverEventHandler.IsAlreadyFollowing = false;
            }
        }