예제 #1
0
        private void CheckForDeliverTicketTrigger()
        {
            if (!Globals.HasTrafficTicketsInHand() && (ShouldEndPullover.HasValue && ShouldEndPullover.Value) && !Game.LocalPlayer.Character.HasScenario())
            {
                ShouldEndPullover = null;

                GameFiber.StartNew(() =>
                {
                    if (Game.LocalPlayer.Character.LastVehicle && !Game.LocalPlayer.Character.LastVehicle.HasDriver)
                    {
                        Game.DisplayNotification("The driver will wait until you are back in your vehicle before taking off");
                    }

                    while (Game.LocalPlayer.LastVehicle && !Game.LocalPlayer.LastVehicle.HasDriver)
                    {
                        GameFiber.Sleep(1000); //Wait for the player to enter their vehicle
                    }

                    Function.Log("Starting Ending pull over wait timer for ped to leave");
                    var stopAt = DateTime.Now.AddMilliseconds(4000); //have the sadPed drive off in 4 seconds if the traffic stop isnt over
                    while (DateTime.Now < stopAt)
                    {
                        GameFiber.Sleep(500);
                    }
                    try
                    {
                        lock (mPromptedCitations) mPromptedCitations.Clear();
                        var handle = Functions.GetCurrentPullover();
                        if (handle != null)
                        {
                            Functions.ForceEndCurrentPullover();
                        }
                    }
                    catch (Exception e)
                    {
                        Function.LogCatch(e.Message);
                    }
                });
            }
            else if (Globals.HasTrafficTicketsInHand() && !Game.LocalPlayer.Character.HasScenario()) //only run when we have tickets and we're not already doing WORLD_HUMAN_CLIPBOARD
            {
                var stopped = World.GetEntities(Game.LocalPlayer.Character.Position, 2.5f, GetEntitiesFlags.ConsiderAllPeds);
                if (stopped != null && stopped.Count() > 0)
                {
                    var pedsAboutToGetTheSmackDown = stopped.Select(x => x as Ped)
                                                     .Where(x => x.DistanceTo(Game.LocalPlayer.Character.FrontPosition) < 2f && Globals.GetTrafficCitationsInHandForPed(x) != null); //may have to add ordering by distance
                    foreach (var sadPed in pedsAboutToGetTheSmackDown)
                    {
                        if (Configs.GiveTicketsToPed.Any(x => x.IsPressed))
                        {
                            //The user wants to give the sad ped the ticket now..
                            GameFiber.StartNew(() =>
                            {
                                List <TrafficCitation> citations = Globals.GetTrafficCitationsInHandForPed(sadPed);
                                Globals.RemoveTrafficCitationsInHandForPed(sadPed);

                                //var item = new Rage.Object(new Model("prop_cs_documents_01"), Game.LocalPlayer.Character.Position);
                                var item = new Rage.Object(new Model("prop_cs_pamphlet_01"), Game.LocalPlayer.Character.GetOffsetPositionUp(3f));
                                item.AttachTo(Game.LocalPlayer.Character, Game.LocalPlayer.Character.GetBoneIndex(PedBoneId.RightThumb1), new Vector3(0.11f, -0.015f, 0f), new Rotator(-195f, 90f, 0f));
                                GameFiber.StartNew(delegate
                                {
                                    GameFiber.Sleep(1300);
                                    item.Detach();
                                    item.Delete();
                                });
                                Game.LocalPlayer.Character.Tasks.PlayAnimation("mp_common", "givetake1_b", 3f, AnimationFlags.None).WaitForCompletion();
                                if (Functions.GetCurrentPullover() != null)
                                {
                                    ShouldEndPullover = true;
                                }
                                if (sadPed != null && sadPed.IsValid() && citations != null && citations.Count > 0)
                                {
                                    // mark ped has been given citation
                                    sadPed.Metadata.citedByComputerPlus = true;
                                    // create court case for citation
                                    ComputerReportsController.createCourtCaseForCitations(citations, sadPed);
                                }
                            });
                            break;
                        }
                        else
                        {
                            //Prompt the user that they can deliver the ticket
                            OnFacingPedWithPendingTickets(null, sadPed, Globals.GetTrafficCitationsInHandForPed(sadPed));
                        }
                    }
                }
            }
            else if (Functions.GetCurrentPullover() == null && Globals.HasTrafficTicketsInHand())
            {
                Globals.ClearTrafficCitationsInHand();
                return;
            }
        }