Ejemplo n.º 1
0
        /// <summary>
        /// Spawns a copy of a vehicle.
        /// </summary>
        /// <param name="coordinates">Position of the new vehicle</param>
        /// <param name="heading">Heading of the new vehicle</param>
        /// <param name="oldVeh">Vehicle to copy</param>
        /// <returns>New vehicle handle</returns>
        public static GTA.Vehicle SpawnCopyVehicle(Vector3 coordinates, float heading, GTA.Vehicle oldVeh)
        {
            GTA.Vehicle veh = GTA.World.CreateVehicle(oldVeh.Model, coordinates, heading);

            try
            {
                // Plate
                veh.NumberPlate = oldVeh.NumberPlate;
                veh.NumberPlateType = oldVeh.NumberPlateType;

                // Wheels
                veh.WheelType = oldVeh.WheelType;

                // Mods
                bool customTire1 = Function.Call<bool>(Hash.GET_VEHICLE_MOD_VARIATION, oldVeh, 23);
                bool customTire2 = Function.Call<bool>(Hash.GET_VEHICLE_MOD_VARIATION, oldVeh, 24);  // Bike only

                if (Function.Call<int>(Hash.GET_NUM_MOD_KITS, oldVeh) != 0)
                {
                    veh.InstallModKit();

                    foreach (VehicleMod mod in Enum.GetValues(typeof(VehicleMod)))
                    {
                        if (mod == VehicleMod.FrontWheels)
                            veh.SetMod(VehicleMod.FrontWheels, oldVeh.GetMod(VehicleMod.FrontWheels), Function.Call<bool>(Hash.GET_VEHICLE_MOD_VARIATION, oldVeh, 23));
                        else if (mod == VehicleMod.BackWheels)
                            veh.SetMod(VehicleMod.FrontWheels, oldVeh.GetMod(VehicleMod.FrontWheels), Function.Call<bool>(Hash.GET_VEHICLE_MOD_VARIATION, oldVeh, 24));
                        else
                            veh.SetMod(mod, oldVeh.GetMod(mod), false);
                    }
                    foreach (VehicleToggleMod mod in Enum.GetValues(typeof(VehicleToggleMod)))
                        veh.ToggleMod(mod, oldVeh.IsToggleModOn(mod));
                    
                }
                veh.WindowTint = oldVeh.WindowTint;

                // Tire's smoke color
                veh.TireSmokeColor = oldVeh.TireSmokeColor;
                veh.CanTiresBurst = oldVeh.CanTiresBurst;

                // Neons
                foreach (VehicleNeonLight neon in Enum.GetValues(typeof(VehicleNeonLight)))
                    veh.SetNeonLightsOn(neon, oldVeh.IsNeonLightsOn(neon));

                // Color
                veh.ClearCustomPrimaryColor();
                veh.ClearCustomSecondaryColor();

                if (oldVeh.IsPrimaryColorCustom)
                    veh.CustomPrimaryColor = oldVeh.CustomPrimaryColor;
                if (oldVeh.IsSecondaryColorCustom)
                    veh.CustomSecondaryColor = oldVeh.CustomSecondaryColor;

                veh.PrimaryColor = oldVeh.PrimaryColor;
                veh.SecondaryColor = oldVeh.SecondaryColor;
                veh.PearlescentColor = oldVeh.PearlescentColor;
                veh.RimColor = oldVeh.RimColor;
                veh.DashboardColor = oldVeh.DashboardColor;
                veh.TrimColor = oldVeh.TrimColor;

                // Convertible
                // 0 -> up ; 1->lowering down ; 2->down ; 3->raising up
                if (oldVeh.IsConvertible)
                    veh.RoofState = oldVeh.RoofState;

                // Extra
                for (int i = 1; i < 15; i++)
                    veh.ToggleExtra(i, oldVeh.IsExtraOn(i));
                
                // Liveries
                veh.Livery = oldVeh.Livery;
                SetVehicleLivery2(veh, GetVehicleLivery2(oldVeh));

                // Misc
                veh.NeedsToBeHotwired = false;
                veh.IsStolen = false;
            }
            catch (Exception e)
            {
                Console.Write("Error: SpawnCopyVehicle - " + e.Message);
            }

            return veh;
        }