public static void DisplayVehicleDetailsNotification(VehicleDetails vehdetails) { if (vehdetails == null) { return; } string subtitle; if (vehdetails.veh.Exists()) { subtitle = vehdetails.veh.LicensePlate; } else { subtitle = ""; } GameFiber.StartNew(delegate { GameFiber.Wait(3000); Game.DisplayNotification("3dtextures", "mpgroundlogo_cops", "Vehicle Details", subtitle, "Insurance: " + vehdetails.InsuranceStatus.ToColouredString() + "~n~~s~Registration: " + vehdetails.RegistrationStatus.ToColouredString()); }); }
private static void LowPriority() { GameFiber.StartNew(delegate { while (true) { GameFiber.Wait(100); foreach (Ped flaggeddriver in FlaggedDrivers.ToArray()) { if (flaggeddriver.Exists()) { if (flaggeddriver.DistanceTo(Game.LocalPlayer.Character) > 300f) { flaggeddriver.IsPersistent = false; //flaggeddriver.Dismiss(); FlaggedDrivers.Remove(flaggeddriver); } else if (Functions.IsPlayerPerformingPullover()) { if (Functions.GetPulloverSuspect(Functions.GetCurrentPullover()) == flaggeddriver) { FlaggedDrivers.Remove(flaggeddriver); } } else if (Functions.GetActivePursuit() != null) { if (Functions.GetPursuitPeds(Functions.GetActivePursuit()).Contains(flaggeddriver)) { FlaggedDrivers.Remove(flaggeddriver); } } } else { FlaggedDrivers.Remove(flaggeddriver); } } if (CurrentSpeedCheckerState != SpeedCheckerStates.Speedgun && Game.LocalPlayer.Character.Inventory.EquippedWeapon != null && Game.LocalPlayer.Character.Inventory.EquippedWeapon.Asset == speedgunWeapon && !Game.LocalPlayer.Character.CurrentVehicle.Exists()) { CurrentSpeedCheckerState = SpeedCheckerStates.Speedgun; DisplayMaxSpeedMessage(); } if (CurrentSpeedCheckerState == SpeedCheckerStates.FixedPoint && Game.LocalPlayer.Character.IsInAnyVehicle(false)) { Entity[] WorldVehicles = World.GetEntities(CheckPointPosition, 7, GetEntitiesFlags.ConsiderAllVehicles | GetEntitiesFlags.ExcludePlayerVehicle); foreach (Vehicle veh in WorldVehicles) { if (veh.Exists() && veh != Game.LocalPlayer.Character.CurrentVehicle && veh.DistanceTo(CheckPointPosition) <= 6.5f) { bool ShowVehicleNotification = false; TargetModel = veh.Model.Name; TargetModel = char.ToUpper(TargetModel[0]) + TargetModel.Substring(1).ToLower(); if (SpeedUnit == "MPH") { TargetSpeed = (int)Math.Round(MathHelper.ConvertMetersPerSecondToMilesPerHour(veh.Speed)); } else { TargetSpeed = MathHelper.ConvertMetersPerSecondToKilometersPerHourRounded(veh.Speed); } if (TargetSpeed >= SpeedToColourAt) { SpeedColour = Color.Red; if (PlayFlagBlip) { if (!VehiclesBlipPlayedFor.Contains(veh)) { VehiclesBlipPlayedFor.Add(veh); FlagBlipPlayer.Play(); ShowVehicleNotification = true; } } } else { SpeedColour = Color.White; } //TargetSpeedLimit = GetSpeedLimit(veh.Position, SpeedUnit); TargetFlag = ""; TargetLicencePlate = veh.LicensePlate; FlagsTextColour = Color.White; if ((TrafficPolicerHandler.rnd.Next(101) <= FlagChance || VehiclesFlagged.Contains(veh)) && !veh.HasSiren && !VehiclesNotFlagged.Contains(veh)) { if (!VehiclesFlagged.Contains(veh)) { VehiclesFlagged.Add(veh); } if (!VehicleDetails.IsVehicleInDetailsDatabase(veh)) { VehicleDetails.AddVehicleToDetailsDatabase(veh, 25); } if (veh.IsStolen || VehicleDetails.GetInsuranceStatusForVehicle(veh) != EVehicleDetailsStatus.Valid) { if (veh.IsStolen) { TargetFlag = "Stolen"; FlagsTextColour = Color.Red; } else if (VehicleDetails.GetInsuranceStatusForVehicle(veh) != EVehicleDetailsStatus.Valid) { TargetFlag = "Uninsured"; FlagsTextColour = Color.Red; } } else { if (veh.HasDriver && veh.Driver.Exists()) { if (Functions.GetPersonaForPed(veh.Driver).Wanted) { TargetFlag = "Owner Wanted"; FlagsTextColour = Color.Red; } else if (Functions.GetPersonaForPed(veh.Driver).ELicenseState == LSPD_First_Response.Engine.Scripting.Entities.ELicenseState.Suspended) { TargetFlag = "Licence Suspended"; FlagsTextColour = Color.Red; } else if (Functions.GetPersonaForPed(veh.Driver).ELicenseState == LSPD_First_Response.Engine.Scripting.Entities.ELicenseState.Expired) { TargetFlag = "Licence Expired"; FlagsTextColour = Color.Orange; } else if (Functions.GetPersonaForPed(veh.Driver).Birthday.Month == DateTime.Now.Month && Functions.GetPersonaForPed(veh.Driver).Birthday.Day == DateTime.Now.Day) { TargetFlag = "Owner's Birthday"; FlagsTextColour = Color.Green; } if (TargetFlag != "") { if (!FlaggedDrivers.Contains(veh.Driver)) { if (!veh.Driver.IsPersistent) { FlaggedDrivers.Add(veh.Driver); veh.Driver.IsPersistent = true; } } } } } if (PlayFlagBlip) { if (TargetFlag != "") { if (!VehiclesBlipPlayedFor.Contains(veh)) { VehiclesBlipPlayedFor.Add(veh); FlagBlipPlayer.Play(); ShowVehicleNotification = true; } } } } if (TargetFlag == "") { VehiclesNotFlagged.Add(veh); } if (ShowVehicleNotification) { Game.DisplayNotification("ナンバー: ~b~" + TargetLicencePlate + "~n~~s~車種: ~b~" + TargetModel + "~n~~s~速度: " + (SpeedColour == Color.Red ? "~r~" : "") + TargetSpeed + " " + SpeedUnit + "~n~~s~Flags: ~r~" + TargetFlag); } } } } else if (CurrentSpeedCheckerState == SpeedCheckerStates.Average && Game.LocalPlayer.Character.IsInAnyVehicle(false)) { if (SpeedUnit == "MPH") { AverageSpeedCheckCurrentSpeed = (int)Math.Round(MathHelper.ConvertMetersPerSecondToMilesPerHour(Game.LocalPlayer.Character.CurrentVehicle.Speed)); } else { AverageSpeedCheckCurrentSpeed = MathHelper.ConvertMetersPerSecondToKilometersPerHourRounded(Game.LocalPlayer.Character.CurrentVehicle.Speed); } if (MeasuringAverageSpeed) { AverageSpeedCheckDistance += Vector3.Distance(LastAverageSpeedCheckReferencePoint, Game.LocalPlayer.Character.CurrentVehicle.Position); LastAverageSpeedCheckReferencePoint = Game.LocalPlayer.Character.CurrentVehicle.Position; AverageSpeedCheckSecondsPassed = ((float)AverageSpeedCheckStopwatch.ElapsedMilliseconds) / 1000; } } } }); }
/// <summary> /// The main loop of the plugin /// </summary> internal static void mainLoop() { Game.LogTrivial("Traffic Policer.Mainloop started"); Game.LogTrivial("Loading Traffic Policer settings..."); loadValuesFromIniFile(); registerCallouts(); isSomeoneFollowing = false; NextEventStopwatch.Start(); driversConsidered = new List <Ped>(); vehiclesTicketedForParking = new List <Vehicle>(); isSomeoneRunningTheLight = false; eventCreator(); RoadSigns.RoadSignsMainLogic(); if (SpeedChecker.ToggleSpeedCheckerKey != Keys.None) { SpeedChecker.Main(); } Game.LogTrivial("Traffic Policer by Albo1125 has been loaded successfully!"); GameFiber.StartNew(delegate { GameFiber.Wait(12000); uint startnot = Game.DisplayNotification("~g~Traffic Officer ~b~" + DivisionUnitBeat + " ~s~reporting for duty!"); GameFiber.Sleep(6000); Game.RemoveNotification(startnot); IsBritishPolicingScriptRunning = IsLSPDFRPluginRunning("British Policing Script", new Version("0.8.0.0")); IsLSPDFRPlusRunning = IsLSPDFRPluginRunning("LSPDFR+", new Version("1.4.0.0")); //Low priority loop while (true) { GameFiber.Wait(1000); if (IsBritishPolicingScriptRunning || IsLSPDFRPlusRunning) { foreach (Ped ped in PedsToChargeWithDrinkDriving.ToArray()) { if (!ped.Exists()) { PedsToChargeWithDrinkDriving.Remove(ped); } else if (Functions.IsPedArrested(ped) && PedsToChargeWithDrinkDriving.Contains(ped)) { PedsToChargeWithDrinkDriving.Remove(ped); if (IsBritishPolicingScriptRunning) { API.BritishPolicingScriptFunctions.CreateNewCourtCase(ped, "drink driving", true, "Fined " + TrafficPolicerHandler.rnd.Next(150, 800).ToString() + " pounds and disqualified from driving for " + TrafficPolicerHandler.rnd.Next(12, 25).ToString() + " months"); } else if (IsLSPDFRPlusRunning) { API.LSPDFRPlusFunctions.CreateCourtCase(Functions.GetPersonaForPed(ped), "driving under the influence of alcohol", 100, API.LSPDFRPlusFunctions.DetermineFineSentence(390, 1000) + " License suspended for " + TrafficPolicerHandler.rnd.Next(1, 7) + " months."); } } } foreach (Ped ped in PedsToChargeWithDrugDriving.ToArray()) { if (!ped.Exists()) { PedsToChargeWithDrugDriving.Remove(ped); } else if (Functions.IsPedArrested(ped) && PedsToChargeWithDrugDriving.Contains(ped)) { PedsToChargeWithDrugDriving.Remove(ped); if (IsBritishPolicingScriptRunning) { API.BritishPolicingScriptFunctions.CreateNewCourtCase(ped, "drug driving", true, "Fined " + TrafficPolicerHandler.rnd.Next(150, 800).ToString() + " pounds and disqualified from driving for " + TrafficPolicerHandler.rnd.Next(12, 25).ToString() + " months"); } else if (IsLSPDFRPlusRunning) { API.LSPDFRPlusFunctions.CreateCourtCase(Functions.GetPersonaForPed(ped), "driving under the influence of drugs", 100, API.LSPDFRPlusFunctions.DetermineFineSentence(390, 1000) + " License suspended for " + TrafficPolicerHandler.rnd.Next(1, 7) + " months."); } } } foreach (GameFiber fiber in AmbientEventGameFibersToAbort.ToArray()) { AmbientEventGameFibersToAbort.Remove(fiber); if (fiber != null) { if (fiber.IsAlive) { fiber.Abort(); } } } } } }); GameFiber.StartNew(delegate { while (true) { GameFiber.Yield(); if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(parkModifierKey) || (parkModifierKey == Keys.None)) { if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(parkingTicketKey)) { ParkingTicket parkingTicket = new ParkingTicket(); } } if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(drugsTestModifierKey) || (drugsTestModifierKey == Keys.None)) { if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(drugsTestKey)) { if (!PerformingImpairmentTest) { Impairment_Tests.DrugTestKit.testNearestPedForDrugs(); } } } if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(Impairment_Tests.Breathalyzer.BreathalyzerModifierKey) || (Impairment_Tests.Breathalyzer.BreathalyzerModifierKey == Keys.None)) { if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(Impairment_Tests.Breathalyzer.BreathalyzerKey)) { if (!PerformingImpairmentTest) { Impairment_Tests.Breathalyzer.TestNearestPedForAlcohol(); } } } if (Functions.IsPlayerPerformingPullover()) { if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(trafficStopFollowModifierKey) || (trafficStopFollowModifierKey == Keys.None)) { if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(trafficStopFollowKey)) { if (!isSomeoneFollowing) { TrafficStopAssist.followMe(); } else { isSomeoneFollowing = false; } } } if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(trafficStopMimicModifierKey) || (trafficStopMimicModifierKey == Keys.None)) { if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(trafficStopMimicKey)) { if (!isSomeoneFollowing) { TrafficStopAssist.mimicMe(); } else { isSomeoneFollowing = false; } } } if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownRightNowComputerCheck(CustomPulloverLocationModifierKey) || (CustomPulloverLocationModifierKey == Keys.None)) { if (Albo1125.Common.CommonLibrary.ExtensionMethods.IsKeyDownComputerCheck(CustomPulloverLocationKey)) { if (!isSomeoneFollowing) { TrafficStopAssist.SetCustomPulloverLocation(); } else { Game.LogTrivial("Already doing custom pullover location."); } } } if (!isSomeoneRunningTheLight) { TrafficStopAssist.checkForceRedLightRun(); } } } }); while (true) { GameFiber.Yield(); TrafficStopAssist.checkForYieldDisable(); if (AutoVehicleDoorLock) { TrafficStopAssist.LockPlayerDoors(); } VehicleDetails.CheckForTextEntry(); } }