Log in to reply
 

Spawning Customized Cars - C# SVDN3



  • Just some hopefully useful snippets for spawning cars in a script.

    Basic Vehicle Spawn
    There are many ways to spawn a vehicle, this is just one of those.
    Vehicle vehicle1 = World.CreateVehicle("roma", PP.Position + PP.ForwardVector * 3.0f, PP.Heading + 90);

    LicensePlate
    vehicle1.Mods.LicensePlate = "F-Roma";

    Vehicle Color (Colour)
    Function.Call(Hash.SET_VEHICLE_COLOURS, vehicle39, 62, 62); //primary and secondary paint
    vehicle15.Mods.PrimaryColor = VehicleColor.MetallicRacingGreen;
    Function.Call(Hash.SET_VEHICLE_MOD_COLOR_1, vehicle15, 1, 23, 0); //last argument is 0, 1 means metallic paint

    Vehicle Color (Colour) and Liveries
    vehicle15.Mods.Livery = 6; //1 less than Menyoo's number
    Function.Call(Hash.SET_VEHICLE_LIVERY, vehicle39, 6);
    Function.Call(Hash.SET_VEHICLE_MOD, vehicle15, 48, 1, false);
    //48 is for livery as a mod, not regular livery, this is a racing stripe, -1 none, 0 white, 1 black - in this case, same as Menyoo

    Modkits
    For modkits and correcting poorly designed cars that don't spawn properly
    vehicle39.Mods.InstallModKit();//mandatory
    Function.Call(Hash.SET_VEHICLE_MOD, vehicle39, 10, 0, false);// roof
    Function.Call(Hash.SET_VEHICLE_MOD, vehicle39, 11, 0, false); // engine
    Function.Call(Hash.SET_VEHICLE_MOD, vehicle15, 5, 1, false);//5 is for frame

    VehicleMod vehicleMod = vehicle39.Mods[VehicleModType.Spoilers]; vehicleMod.Index = 0;
    // or use Function.Call(Hash.SET_VEHICLE_MOD, vehicle39, 0, 0, false); // spoiler

    Persistence
    vehicle39.IsPersistent = true;

    Broken Door
    Function.Call(Hash.SET_VEHICLE_DOOR_BROKEN, Vehicle2, 5, true);

    Generic Car Spawn Function From A LemonUI menu
    Set as many parameters as you want. These are just a few examples.

    if (MyChoice == "Testarossa 1986") { CarModel = "testarossa"; PColor = 27; Plate = "1986 TR"; GenericCarSpawn(); }

    private void GenericCarSpawn()
    {Vehicle GTACar = World.CreateVehicle(CarModel, PP.Position + PP.ForwardVector * 3.0f, PP.Heading + 90);
    Function.Call(Hash.SET_VEHICLE_COLOURS, GTACar, PColor, SColor);
    GTACar.Mods.InstallModKit();
    GTACar.Mods.LicensePlate = Plate;
    GTACar.Mods.Livery = Livery;
    }

    #Mod Type
    Spoilers - 0
    Front Bumper - 1
    Rear Bumper - 2
    Side Skirt - 3
    Exhaust - 4
    Frame - 5
    Grille - 6
    Hood - 7
    Fender - 8
    Right Fender - 9
    Roof - 10
    Engine - 11
    Brakes - 12
    Transmission - 13
    Horns - 14 (modIndex from 0 to 51)
    Suspension - 15
    Armor - 16
    Front Wheels - 23
    Back Wheels - 24 //only for motocycles
    Plate holders - 25
    Trim Design - 27
    Ornaments - 28
    Dial Design - 30
    Steering Wheel - 33
    Shifter Leavers - 34
    Plaques - 35
    Hydraulics - 38
    Livery - 48


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.