Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

[C#] Scripthook.net adding mods to a vehicle


Andy16823
 Share

Recommended Posts

Hello, i work currently on a mod for saving vehicles. I use C# and scripthook.net. My problemm currently is that i dont know how i can get the installed mods and how i can attach them after i spawned the new vehicle.

 

this is what i currently tryed

// Saving the vehicle
public GarageVehicle(String name, String plate, GTA.Vehicle vehicle)
        {
            this.Name = name;
            this.Plate = plate;
            this.Vehicle = vehicle;
            this.Model = vehicle.Model;
            this.Mods = new Mods();
            this.Mods.FrontBumper = vehicle.Mods[VehicleModType.FrontBumper].Index;
            this.Mods.RearBumper = vehicle.Mods[VehicleModType.RearBumper].Index;
            this.Mods.Sides = vehicle.Mods[VehicleModType.SideSkirt].Index;
            this.Mods.Hood = vehicle.Mods[VehicleModType.Hood].Index;
        }

// loading
foreach (var vehicle in this.Vehicles)
            {
                UIMenuItem vMenuItem = new UIMenuItem(vehicle.Name);
                vMenuItem.Activated += (o, e) =>
                {
                    GTA.Vehicle v = GTA.World.CreateVehicle(vehicle.Model, Location);
                    v.Mods[VehicleModType.FrontBumper].Index = vehicle.Mods.FrontBumper;
                    v.Mods[VehicleModType.RearBumper].Index = vehicle.Mods.RearBumper;
                    v.Mods[VehicleModType.SideSkirt].Index = vehicle.Mods.Sides;
                    v.Mods[VehicleModType.Hood].Index = vehicle.Mods.Hood;
                };
                this.garageBehavior.UIMenu.AddItem(vMenuItem);
            }

 

thanks for your help :)

Edited by Andy16823
Link to comment
Share on other sites

This is how I do it for the main mod collection. This doesn't include any of the colours, neons, tyre smoke etc...

 

Note: This is for ScriptHookVDotNet v2.0, so if you're using v3.0, then you'll need to use the equivalent changed value for VehicleMod. No idea what that is, I don't use v3.0.

 

You will need to add using System.Linq; for the ToList() functionality.

 

Declare as Global variables

List<VehicleMod> VehicleMods;
List<int> ModCollection;

In your Class Constructor or some initialisation function

Array vMods = Enum.GetValues(typeof(VehicleMod));
VehicleMods = ((VehicleMod[])vMods).ToList()

Saving a car

// Init the ModCollection
ModCollection = new List<int>();

// Collect the mod values
for (int i = 0; i < VehicleMods.Count; i++)
{
	ModCollection.Add(vehicle.GetMod(VehicleMods[i]));
}

Restoring a car

// This causes the game to assign a valid modkit ID to a vehicle
Function.Call(Hash.SET_VEHICLE_MOD_KIT, vehicle, 0);

// Assign the stored mods
for (int i = 0; i < VehicleMods.Count; i++)
{
	if (ModCollection[i] != -1) vehicle.SetMod(VehicleMods[i], ModCollection[i], false);
}

I use this in my Driver Information System mod and it seems to work fine. You also have a collection of Extras to store, plus a collection of VehicleToggleMods

Edited by LeeC22
Link to comment
Share on other sites

thanks for the anwser. I allready got a other solution for it :

 

        public void InstallMods(Vehicle vehicle)
        {
            vehicle.Mods.InstallModKit();
            vehicle.Mods[VehicleModType.Spoilers].Index = this.Spoilers;
            vehicle.Mods[VehicleModType.FrontBumper].Index = this.FrontBumper;
            vehicle.Mods[VehicleModType.RearBumper].Index = this.RearBumper;
            vehicle.Mods[VehicleModType.SideSkirt].Index = this.SideSkirt;
            vehicle.Mods[VehicleModType.Exhaust].Index = this.Exhaust;
            vehicle.Mods[VehicleModType.Frame].Index = this.Frame;
            vehicle.Mods[VehicleModType.Grille].Index = this.Grille;
            vehicle.Mods[VehicleModType.Hood].Index = this.Hood;
            vehicle.Mods[VehicleModType.Fender].Index = this.Fender;
            vehicle.Mods[VehicleModType.RightFender].Index = this.RightFender;
            vehicle.Mods[VehicleModType.Roof].Index = this.Roof;
            vehicle.Mods[VehicleModType.Engine].Index = this.Engine;
            vehicle.Mods[VehicleModType.Brakes].Index = this.Brakes;
            vehicle.Mods[VehicleModType.Transmission].Index = this.Transmission;
            vehicle.Mods[VehicleModType.Horns].Index = this.Horns;
            vehicle.Mods[VehicleModType.Suspension].Index = this.Suspension;
            vehicle.Mods[VehicleModType.Armor].Index = this.Armor;
            vehicle.Mods[VehicleModType.Suspension].Index = this.Suspension;
            vehicle.Mods[VehicleModType.FrontWheel].Index = this.FrontWheel;
            vehicle.Mods[VehicleModType.RearWheel].Index = this.RearWheel;
            vehicle.Mods[VehicleModType.PlateHolder].Index = this.PlateHolder;
            vehicle.Mods[VehicleModType.VanityPlates].Index = this.VanityPlates;
            vehicle.Mods[VehicleModType.TrimDesign].Index = this.TrimDesign;
            vehicle.Mods[VehicleModType.Ornaments].Index = this.Ornaments;
            vehicle.Mods[VehicleModType.Dashboard].Index = this.Dashboard;
            vehicle.Mods[VehicleModType.DialDesign].Index = this.DialDesign;
            vehicle.Mods[VehicleModType.DoorSpeakers].Index = this.DoorSpeakers;
            vehicle.Mods[VehicleModType.Seats].Index = this.Seats;
            vehicle.Mods[VehicleModType.SteeringWheels].Index = this.SteeringWheels;
            vehicle.Mods[VehicleModType.ColumnShifterLevers].Index = this.ColumnShifterLevers;
            vehicle.Mods[VehicleModType.Speakers].Index = this.Speakers;
            vehicle.Mods[VehicleModType.Trunk].Index = this.Trunk;
            vehicle.Mods[VehicleModType.Hydraulics].Index = this.Hydraulics;
            vehicle.Mods[VehicleModType.EngineBlock].Index = this.EngineBlock;
            vehicle.Mods[VehicleModType.AirFilter].Index = this.AirFilter;
            vehicle.Mods[VehicleModType.Struts].Index = this.Struts;
            vehicle.Mods[VehicleModType.ArchCover].Index = this.ArchCover;
            vehicle.Mods[VehicleModType.Aerials].Index = this.Aerials;
            vehicle.Mods[VehicleModType.Trim].Index = this.Trim;
            vehicle.Mods[VehicleModType.Tank].Index = this.Tank;
            vehicle.Mods[VehicleModType.Windows].Index = this.Windows;
            vehicle.Mods[VehicleModType.Livery].Index = this.Livery;
        }

so the problemm ist you need to call "vehicle.Mods.InstallModKit();" before. After this you can attach the mods with seting the index value

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.