Advertisement
Eddlm

Replacer

Oct 1st, 2017
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.14 KB | None | 0 0
  1.  
  2.     public static void ReplaceVehicle(Vehicle v, Model target, bool tuning)
  3.     {
  4.          if(DebugOutput) File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - Replacing"+v.DisplayName +" with "+target.ToString());
  5.  
  6.         //LivelyWorld.BlacklistedModels.Add(v.Model.ToString());
  7.         if (CanWeUse(v))
  8.         {
  9.             Vector3 pos = v.Position;
  10.             float speed = v.Speed;
  11.             float heading = v.Heading;
  12.             Ped ped = v.Driver;
  13.             bool HadDriver = LivelyWorld.CanWeUse(ped);
  14.             Vehicle possibletrailer = LivelyWorld.GetTrailer(v);
  15.  
  16.             if (CanWeUse(possibletrailer))
  17.             {
  18.                  if(DebugOutput) File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - truck had trailer");
  19.  
  20.                 Function.Call(Hash.DETACH_VEHICLE_FROM_TRAILER, v);
  21.                 possibletrailer.IsPersistent = true;
  22.                 Script.Wait(500);
  23.  
  24.             }
  25.             v.Delete();
  26.  
  27.             Vehicle veh = World.CreateVehicle(target, pos, heading);
  28.  
  29.             if (LivelyWorld.CanWeUse(veh))
  30.             {
  31.                  if(DebugOutput) File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - replacer car created");
  32.  
  33.                 veh.Speed = speed;
  34.  
  35.                 if (!veh.CurrentBlip.Exists() && LivelyWorld.DebugBlips)
  36.                 {
  37.                      if(DebugOutput) File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - adding blip");
  38.  
  39.                     veh.AddBlip();
  40.                     veh.CurrentBlip.Sprite = BlipSprite.PersonalVehicleCar;
  41.                     veh.CurrentBlip.Scale = 0.7f;
  42.                     veh.CurrentBlip.Color = BlipColor.White;
  43.                     veh.CurrentBlip.IsShortRange = true;
  44.                     veh.CurrentBlip.Name = veh.FriendlyName;
  45.                 }
  46.  
  47.                 if (tuning) LivelyWorld.RandomTuning(veh, LivelyWorld.IsNightTime(), false);
  48.                 //LivelyWorld.ReplacerTime = Game.GameTime + 30000;
  49.  
  50.  
  51.                 if (LivelyWorld.CanWeUse(ped)) ped.SetIntoVehicle(veh, VehicleSeat.Driver);
  52.                 else
  53.                     if (HadDriver)
  54.                 {
  55.                      if(DebugOutput) File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - creating driver for it");
  56.  
  57.                     veh.CreateRandomPedOnSeat(VehicleSeat.Driver);
  58.                     veh.Driver.IsPersistent = false;
  59.                     veh.EngineRunning = true;
  60.                     if (LivelyWorld.IsNightTime()) veh.LightsOn = true;
  61.                 }
  62.  
  63.                 if (LivelyWorld.CanWeUse(possibletrailer))
  64.                 {
  65.                      if(DebugOutput) File.AppendAllText(@"scripts\LivelyWorldDebug.txt", "\n" + DateTime.Now + " - arraching trailer to new car");
  66.  
  67.                     Function.Call(GTA.Native.Hash.ATTACH_VEHICLE_TO_TRAILER, veh, possibletrailer, 10);
  68.  
  69.                     possibletrailer.IsPersistent = false;
  70.                 }
  71.                 BlacklistedVehicles.Add(veh);
  72.  
  73.  
  74.                 veh.IsPersistent = false;
  75.             }
  76.  
  77.         }
  78.        
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement