LemonUI3 - C# Code Snippets for Vehicle Management and Spawning
-
LemonUI allows you to easily build highly customized, highly personalized menus to spawn your vehicle addons. You can, like myself, have hundreds of addons, assuming your system is configured properly and can handle it. This post is not for people who are 100% satisfied with the excellent and popular Add-On Vehicle Spawner by @IKT. This is for people who like to DIY and want full control over categories and want to spawn models fully customized without having to use their Trainer to do so. Having said that, you can use LemonUI menus as trainers as well. For example in the video, we decide we want to change the livery after spawn.
The snippets below are for anyone who is already familiar with LemonUI and are at an "advanced beginner" level - sorry for the oxymoron. In this example we're using the NativeListItem<String> because it lends itself well to this approach. You can also use the "Classic" menu style, where each line is one selection only.
This is where all your Porsche models, for example, will be listed. You select which parameters you want to modify.
public void PorscheList(object sender, EventArgs e) //Porsche models are listed here, no limit
{
String MyChoice = List9.SelectedItem;
if (MyChoice == "2014 911Turbo") { CarModel = "PTS14"; Livery = 6; Plate = "2014 911"; GenericCarSpawn(); } //This is where the GenericCarSpawn is called
.... the list continues with all your models`another example, for a Ferrari this time:
if (MyChoice == "575M Maranello") { CarModel = "575M"; PColor = 43; Plate = "F 575M"; GenericCarSpawn(); }
#region Generic Car Spawn
//Declarations, placed here or elsewhere, your choice
public static String CarModel { get; set; }
public static int PColor { get; set; }
public static int SColor { get; set; }
public static int Livery { get; set; }
public static String Plate { get; set; }
You can have extras here as well, but that's for a future tutorial - they are more complicated given they can be toggled. In other words, they don't lend themselves to a one size fits all generic solution.
And this is the one function you will need to spawn 99% of your cars. The other 1% is for models that need special attention due to poor modding.
private void GenericCarSpawn()
//Spawn Function
{Vehicle GTACar = World.CreateVehicle(CarModel, PP.Position + PP.ForwardVector * 3.0f, PP.Heading + 90); SetRadioStation();
//radio is optional ofc.
Function.Call(Hash.SET_VEHICLE_COLOURS, GTACar, PColor, SColor);
GTACar.Mods.Livery = Livery;
//n.b. livery does not require modkit although some liveries do just to make life complicated.
GTACar.Mods.InstallModKit();
GTACar.Mods.LicensePlate = Plate;
}
#endregion