|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Rage; |
| 7 | +using LSPD_First_Response.Mod.API; |
| 8 | +using LSPD_First_Response.Mod.Callouts; |
| 9 | +using System.Windows.Forms.VisualStyles; |
| 10 | + |
| 11 | +namespace SSStuartCallouts.Callouts |
| 12 | +{ |
| 13 | + |
| 14 | + [CalloutInfo("AbandonedVehicle", CalloutProbability.Low)] |
| 15 | + |
| 16 | + public class AbandonedVehicle: Callout |
| 17 | + { |
| 18 | + private Ped Driver; |
| 19 | + private Vehicle AbandonedCar; |
| 20 | + private Blip AbandonedCarBlip; |
| 21 | + private Vector3 SpawnPoint; |
| 22 | + private LHandle Pursuit; |
| 23 | + private bool PursuitCreated; |
| 24 | + private bool EventCreated; |
| 25 | + private bool VehicleStolen; |
| 26 | + private Vehicle PlayerVehicle; |
| 27 | + private Vehicle BackupVehicle; |
| 28 | + private Blip BackupBlip; |
| 29 | + private Ped BackupPed; |
| 30 | + |
| 31 | + public int RandomNumber(int min, int max) |
| 32 | + { |
| 33 | + int random = new Random().Next(min, max); |
| 34 | + return random; |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | + public override bool OnBeforeCalloutDisplayed() |
| 39 | + { |
| 40 | + SpawnPoint = World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(2000f)); |
| 41 | + ShowCalloutAreaBlipBeforeAccepting(SpawnPoint, 50f); |
| 42 | + AddMinimumDistanceCheck(200f, SpawnPoint); |
| 43 | + CalloutMessage = "Abandoned Vehicle"; |
| 44 | + CalloutPosition = SpawnPoint; |
| 45 | + Functions.PlayScannerAudioUsingPosition("CITIZENS_REPORT_04 IN_OR_ON_POSITION", SpawnPoint); |
| 46 | + |
| 47 | + return base.OnBeforeCalloutDisplayed(); |
| 48 | + } |
| 49 | + |
| 50 | + public override bool OnCalloutAccepted() |
| 51 | + { |
| 52 | + List<string> vehicleList = new List<string> |
| 53 | + { |
| 54 | + "speedo", |
| 55 | + "sanchez2", |
| 56 | + "faggio", |
| 57 | + "granger", |
| 58 | + "rebel", |
| 59 | + "rebel2", |
| 60 | + "dloader", |
| 61 | + "voodoo2" |
| 62 | + }; |
| 63 | + |
| 64 | + AbandonedCar = new Vehicle(vehicleList[RandomNumber(0, vehicleList.Count)], SpawnPoint, RandomNumber(-180, 180)); |
| 65 | + AbandonedCar.IsPersistent = true; |
| 66 | + |
| 67 | + Driver = new Ped(AbandonedCar.GetOffsetPositionRight(5f)); |
| 68 | + Driver.IsPersistent = true; |
| 69 | + Driver.BlockPermanentEvents = true; |
| 70 | + Driver.IsVisible = false; |
| 71 | + |
| 72 | + AbandonedCarBlip = new Blip(AbandonedCar); |
| 73 | + AbandonedCarBlip.Color = System.Drawing.Color.Orange; |
| 74 | + AbandonedCarBlip.IsRouteEnabled = true; |
| 75 | + AbandonedCarBlip.Name = "Abandoned Vehicle"; |
| 76 | + |
| 77 | + EventCreated = false; |
| 78 | + PursuitCreated = false; |
| 79 | + VehicleStolen = false; |
| 80 | + |
| 81 | + return base.OnCalloutAccepted(); |
| 82 | + } |
| 83 | + |
| 84 | + public override void Process() |
| 85 | + { |
| 86 | + base.Process(); |
| 87 | + |
| 88 | + if (!EventCreated && Game.LocalPlayer.Character.DistanceTo(AbandonedCar) < 300f) |
| 89 | + { |
| 90 | + Game.DisplayNotification("The abandoned vehicle is a ~o~" + AbandonedCar.Model.Name); |
| 91 | + |
| 92 | + AbandonedCar.IsEngineOn = true; |
| 93 | + AbandonedCar.IndicatorLightsStatus = VehicleIndicatorLightsStatus.Both; |
| 94 | + if(RandomNumber(0,2) == 1) |
| 95 | + AbandonedCar.Doors[0].IsFullyOpen = true; |
| 96 | + |
| 97 | + EventCreated = true; |
| 98 | + |
| 99 | + } |
| 100 | + |
| 101 | + if (EventCreated && !VehicleStolen && Game.LocalPlayer.Character.IsInAnyVehicle(false)) |
| 102 | + PlayerVehicle = Game.LocalPlayer.Character.LastVehicle; |
| 103 | + |
| 104 | + if (EventCreated && !PursuitCreated && !VehicleStolen && (Game.LocalPlayer.Character.DistanceTo(PlayerVehicle) > 10f) && !Game.LocalPlayer.Character.IsInAnyVehicle(false)) |
| 105 | + { |
| 106 | + AbandonedCarBlip.DisableRoute(); |
| 107 | + Game.DisplayNotification("Inspect the vehicle"); |
| 108 | + if (!PlayerVehicle.IsOnScreen && !Game.LocalPlayer.Character.IsInAnyVehicle(false)) |
| 109 | + { |
| 110 | + int counterInvisible = 0; |
| 111 | + while (counterInvisible < 10) |
| 112 | + { |
| 113 | + GameFiber.Wait(100); |
| 114 | + if (PlayerVehicle.IsOnScreen) |
| 115 | + break; |
| 116 | + counterInvisible++; |
| 117 | + } |
| 118 | + if (counterInvisible == 10) |
| 119 | + VehicleStolen = true; |
| 120 | + |
| 121 | + if (VehicleStolen) |
| 122 | + { |
| 123 | + Driver.Position = PlayerVehicle.GetOffsetPositionRight(-2f); |
| 124 | + Driver.IsVisible = true; |
| 125 | + Driver.BlockPermanentEvents = true; |
| 126 | + |
| 127 | + Game.LogTrivial("Warping thief into vehicle"); |
| 128 | + Driver.WarpIntoVehicle(PlayerVehicle, -1); |
| 129 | + Game.LogTrivial("Assinging task to drive away"); |
| 130 | + Driver.Tasks.CruiseWithVehicle(100f); |
| 131 | + |
| 132 | + Pursuit = Functions.CreatePursuit(); |
| 133 | + Functions.AddPedToPursuit(Pursuit, Driver); |
| 134 | + Functions.RequestBackup(World.GetNextPositionOnStreet(Driver.Position.Around(100f)), LSPD_First_Response.EBackupResponseType.Pursuit, LSPD_First_Response.EBackupUnitType.AirUnit); |
| 135 | + Functions.SetPursuitIsActiveForPlayer(Pursuit, true); |
| 136 | + |
| 137 | + GameFiber.Wait(1500); |
| 138 | + Game.DisplayNotification("dia_police", "dia_police", "Dispatch", "", "Calling for backup to pick you up"); |
| 139 | + Functions.PlayScannerAudioUsingPosition("WE_HAVE CRIME_GRAND_THEFT_AUTO OUTRO_03 ASSISTANCE_REQUIRED IN_OR_ON_POSITION", Driver.Position); |
| 140 | + |
| 141 | + BackupVehicle = new Vehicle("police", World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(200f)), Game.LocalPlayer.Character.Heading); |
| 142 | + BackupVehicle.IsSirenOn = true; |
| 143 | + BackupVehicle.IsPersistent = true; |
| 144 | + |
| 145 | + BackupPed = new Ped("s_m_m_chemsec_01", BackupVehicle.GetOffsetPositionRight(2f), BackupVehicle.Heading); |
| 146 | + BackupPed.BlockPermanentEvents = true; |
| 147 | + BackupPed.IsPersistent = true; |
| 148 | + |
| 149 | + BackupBlip = new Blip(BackupPed); |
| 150 | + BackupBlip.Sprite = BlipSprite.PolicePatrol; |
| 151 | + BackupBlip.Color = System.Drawing.Color.LightSkyBlue; |
| 152 | + |
| 153 | + BackupPed.WarpIntoVehicle(BackupVehicle, -1); |
| 154 | + Game.LogTrivial("Task : Drive to player"); |
| 155 | + BackupPed.Tasks.DriveToPosition(Game.LocalPlayer.Character.Position, 100f, VehicleDrivingFlags.Emergency, 20f); |
| 156 | + while (BackupVehicle.DistanceTo(Game.LocalPlayer.Character) > 20f) |
| 157 | + { |
| 158 | + Game.LogTrivial("Distance to player > 20m"); |
| 159 | + GameFiber.Wait(2000); |
| 160 | + BackupPed.Tasks.Clear(); |
| 161 | + Game.LogTrivial("Task : Drive to player"); |
| 162 | + BackupPed.Tasks.DriveToPosition(Game.LocalPlayer.Character.Position, 80f, VehicleDrivingFlags.Emergency, 20f); |
| 163 | + } |
| 164 | + |
| 165 | + while (BackupVehicle.Speed > 1f) |
| 166 | + GameFiber.Wait(500); |
| 167 | + Game.LogTrivial("Speed < 1m/s Task : Clear"); |
| 168 | + BackupPed.Tasks.Clear(); |
| 169 | + if (!Game.LocalPlayer.Character.IsInAnyVehicle(false)) |
| 170 | + { |
| 171 | + Game.DisplaySubtitle("Hey, get in the car!", 5000); |
| 172 | + BackupPed.Tasks.ShuffleToAdjacentSeat(); |
| 173 | + BackupPed.IsPositionFrozen = true; |
| 174 | + BackupPed.StaysInVehiclesWhenJacked = true; |
| 175 | + BackupVehicle.IsSirenOn = false; |
| 176 | + |
| 177 | + while (!Game.LocalPlayer.Character.IsInAnyVehicle(false)) |
| 178 | + GameFiber.Wait(500); |
| 179 | + } |
| 180 | + |
| 181 | + BackupBlip.Delete(); |
| 182 | + BackupPed.Delete(); |
| 183 | + BackupPed = new Ped("s_m_y_cop_01", BackupVehicle.GetOffsetPositionFront(-20f), 0); |
| 184 | + BackupPed.WarpIntoVehicle(BackupVehicle, 0); |
| 185 | + BackupPed.BlockPermanentEvents = false; |
| 186 | + Functions.AddCopToPursuit(Pursuit, BackupPed); |
| 187 | + |
| 188 | + PursuitCreated = true; |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + else if (PursuitCreated && !Functions.IsPursuitStillRunning(Pursuit) || !Driver.IsAlive) |
| 194 | + { |
| 195 | + End(); |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + public override void End() |
| 200 | + { |
| 201 | + base.End(); |
| 202 | + |
| 203 | + if (AbandonedCarBlip.Exists()) AbandonedCarBlip.Delete(); |
| 204 | + if (AbandonedCar.Exists()) AbandonedCar.Dismiss(); |
| 205 | + if (Driver.Exists()) Driver.Dismiss(); |
| 206 | + if (Driver.Tasks != null) Driver.Tasks.Clear(); |
| 207 | + if (Game.LocalPlayer.Character.IsInVehicle(BackupVehicle, false)) |
| 208 | + { |
| 209 | + BackupPed.Tasks.PerformDrivingManeuver(VehicleManeuver.Wait).WaitForCompletion(); |
| 210 | + GameFiber.Wait(1000); |
| 211 | + Game.LocalPlayer.Character.Tasks.LeaveVehicle(LeaveVehicleFlags.LeaveDoorOpen).WaitForCompletion(); |
| 212 | + GameFiber.Wait(1000); |
| 213 | + } |
| 214 | + if (BackupPed.Tasks != null) BackupPed.Tasks.Clear(); |
| 215 | + if (BackupBlip.Exists()) BackupBlip.Delete(); |
| 216 | + if (BackupPed.Exists()) BackupPed.Dismiss(); |
| 217 | + if (BackupVehicle.Exists()) BackupVehicle.Dismiss(); |
| 218 | + if (PlayerVehicle.Exists()) PlayerVehicle.Dismiss(); |
| 219 | + if (Game.LocalPlayer.Character.Tasks != null) Game.LocalPlayer.Character.Tasks.Clear(); |
| 220 | + |
| 221 | + Game.DisplayNotification("[CALLOUT 'ABANDONED VEHICLE' ENDED]"); |
| 222 | + Game.LogTrivial("[SSStuart Callout] 'Abandoned Vehicle' callout has ended."); |
| 223 | + } |
| 224 | + } |
| 225 | +} |
0 commit comments