コード例 #1
0
    public void SpawnCarCommand(Client sender, VehicleHash model)
    {
        if (BannedVehicles.Contains(model))
        {
            sender.sendChatMessage("The vehicle ~r~" + model.ToString() + "~s~ is ~r~banned~s~!");
            return;
        }

        if (sender.vehicle != null && sender.vehicleSeat == -1)
        {
            NetHandle hv    = sender.vehicle.handle;
            var       owner = getVehicleOwner(hv);
            if (owner != null && VehicleHistory.ContainsKey(owner))
            {
                VehicleHistory[owner].Remove(hv);
            }
            sender.vehicle.delete();
        }

        var veh = API.createVehicle(model, sender.position, new Vector3(0, 0, sender.rotation.Z), 0, 0);

        veh.primaryColor     = Rnd.Next(158);
        veh.secondaryColor   = Rnd.Next(158);
        veh.numberPlate      = getRandomNumberPlate(sender);
        veh.numberPlateStyle = Rnd.Next(6);

        API.setPlayerIntoVehicle(sender, veh, -1);
    }
コード例 #2
0
ファイル: freeroam.cs プロジェクト: ciber96/ExampleResources
    public void SpawnCarCommand(Client sender, VehicleHash model)
    {
        if (API.isPlayerInAnyVehicle(sender))
        {
            sender.sendChatMessage("~r~Please exit your current vehicle first.");
            return;
        }
        if (BannedVehicles.Contains(model))
        {
            sender.sendChatMessage("The vehicle ~r~" + model.ToString() + "~s~ is ~r~banned~s~!");
            return;
        }

        var veh = API.createVehicle(model, sender.position, new Vector3(0, 0, sender.rotation.Z), 0, 0);

        veh.primaryColor     = Rnd.Next(158);
        veh.secondaryColor   = Rnd.Next(158);
        veh.numberPlate      = getRandomNumberPlate(sender);
        veh.numberPlateStyle = Rnd.Next(6);

        Handle(sender).VehicleHistory.Add(veh);
        if (Handle(sender).VehicleHistory.Count > 2)
        {
            API.deleteEntity(Handle(sender).VehicleHistory[0]);
            Handle(sender).VehicleHistory.RemoveAt(0);
        }

        API.setPlayerIntoVehicle(sender, veh, -1);
    }
コード例 #3
0
        public void AddVehicleToCarshop(Client sender, VehicleHash hash, VehicleClass vehicleClass, decimal cost, string type, string type2 = "Empty")
        {
            if (!sender.HasRank(ServerRank.AdministratorRozgrywki2))
            {
                sender.SendWarning("Nie posiadasz uprawnień do tworzenia pojazdu w salonie.");
                return;
            }

            if (Vehicles.Any(v => v.Hash == hash))
            {
                sender.SendError("Podany pojazd jest już dodany.");
                return;
            }

            MoneyValidator validator = new MoneyValidator();

            if (!validator.IsValid(cost))
            {
                sender.SendError("Wprowadzona kwota gotówki jest nieprawidłowa.");
                return;
            }

            CarshopType endType      = CarshopType.Empty;
            CarshopType endType2     = CarshopType.Empty;
            var         carshopTypes = ((CarshopType[])Enum.GetValues(typeof(CarshopType))).ToList();

            if (carshopTypes.All(carshopType => carshopType.GetDescription() != type && carshopType.GetDescription() != type2))
            {
                sender.SendError("Wprowadzony typ salonu jest nieprawidłowy.");
            }

            foreach (CarshopType item in carshopTypes)
            {
                if (item.GetDescription() == type)
                {
                    endType = item;
                }
                if (item.GetDescription() == type2)
                {
                    endType2 = item;
                }
            }

            if (endType2 != CarshopType.Empty)
            {
                endType = endType | endType2;
            }

            CarshopVehicleModel vehicle =
                new CarshopVehicleModel(hash.ToString(), hash, vehicleClass, cost, endType)
            {
                CreatorForumName = sender.GetAccountEntity().DbModel.Name
            };

            XmlHelper.AddXmlObject(vehicle, Path.Combine(Utils.XmlDirectory, "CarshopVehicles"), vehicle.Name);
        }
コード例 #4
0
        public static bool CreateRentedVehicle(VehicleHash vehModel, string rentedSocialClubName, Vector3 pos, Vector3 rot, int dim = 0)
        {
            try
            {
                Random r = new Random();
                if (vehModel.ToString() == "0")
                {
                    return(false);
                }
                var id = _repository.Current.Count > 0 ? _repository.Current.LastOrDefault().VehicleId + 1 : 1;

                var _veh = new Models.Vehicle
                {
                    VehicleOnMap             = API.shared.createVehicle(vehModel, pos, rot, r.Next(0, 125), r.Next(0, 125), dim),
                    VehicleId                = id,
                    Plate                    = "LS-" + id,
                    Dimension                = dim,
                    FactionId                = -1,
                    JobId                    = -1,
                    VehicleModelId           = vehModel,
                    Fuel                     = 100,
                    IsBlockedForTax          = false,
                    IsLocked                 = false,
                    LastPosition             = pos,
                    LastRotation             = rot,
                    ModColor1                = 0,
                    ModColor2                = 0,
                    Color1                   = 5,
                    Color2                   = 10,
                    PastMinutes              = 0,
                    OwnerSocialClubName      = null,
                    RentedTime               = DateTime.Now,
                    RentedPlayerSocialClubId = rentedSocialClubName,
                    Tax = 0,
                };

                _repository.Add(_veh);

                _veh.VehicleOnMap.numberPlate = _veh.Plate;
                for (int i = 0; i < 69; i++)
                {
                    //if (i == 24) { continue; }
                    //if (i == 23) { currentVehList.Items.LastOrDefault().Mods[i] = 0; currentVehList.Items.LastOrDefault().VehicleOnMap.setMod(i, 0); }
                    _veh.Mods[i] = -1;
                    //currentVehList.Items.LastOrDefault().VehicleOnMap.setMod(i, -1);
                }
                SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                API.shared.consoleOutput(LogCat.Warn, "Vehicle Creation Error: " + ex.ToString());
                return(false);
            }
        }
コード例 #5
0
ファイル: CarCommand.cs プロジェクト: DeadSurfer/igicore
        public override async Task RunCommand(Player player, List <string> args)
        {
            Tuple <Vector3, float> charPos = await player.Event(RpcEvents.GetCharacterPosition).Request <Vector3, float>();

            VehicleHash carName = VehicleHash.Elegy;
            var         dict    = Enum.GetValues(typeof(VehicleHash))
                                  .Cast <VehicleHash>()
                                  .ToDictionary(t => (uint)t, t => t.ToString().ToLower());

            if (args.FirstOrDefault() != null)
            {
                carName = dict.Where(d => d.Value == args[0].ToLower()).Select(d => d.Key).Cast <VehicleHash>().FirstOrDefault();
            }
            if (carName == 0)
            {
                carName = VehicleHash.Elegy;
            }
            Server.Log(carName.ToString());
            Car car = new Car
            {
                Id           = GuidGenerator.GenerateTimeBasedGuid(),
                Hash         = (uint)carName,
                Position     = charPos.Item1.GetPositionInFrontOfPed(charPos.Item2, 10f),
                PrimaryColor = new VehicleColor
                {
                    StockColor  = VehicleStockColor.HotPink,
                    CustomColor = new Color(),
                    IsCustom    = false
                },
                SecondaryColor = new VehicleColor
                {
                    StockColor  = VehicleStockColor.MattePurple,
                    CustomColor = new Color(),
                    IsCustom    = false
                },
                PearescentColor = VehicleStockColor.HotPink,
                Seats           = new List <VehicleSeat>(),
                Wheels          = new List <VehicleWheel>(),
                Windows         = new List <VehicleWindow>(),
                Doors           = new List <VehicleDoor>()
            };

            Server.Db.Cars.Add(car);
            await Server.Db.SaveChangesAsync();

            player
            .Event(RpcEvents.CarCreate)
            .Attach(car)
            .Trigger();
        }
コード例 #6
0
        public static VehicleEntity Create(FullPosition spawnPosition, VehicleHash hash, string numberPlate, int numberPlateStyle,
                                           int?creatorId, Color primaryColor, Color secondaryColor, float enginePowerMultiplier = 0f, float engineTorqueMultiplier = 0f,
                                           CharacterModel character = null, GroupModel groupModel = null)
        {
            VehicleModel vehicleModel = new VehicleModel
            {
                VehicleHash            = hash.ToString(),
                NumberPlate            = numberPlate,
                NumberPlateStyle       = numberPlateStyle,
                Character              = character,
                Group                  = groupModel,
                CreatorId              = creatorId,
                SpawnPositionX         = spawnPosition.Position.X,
                SpawnPositionY         = spawnPosition.Position.Y,
                SpawnPositionZ         = spawnPosition.Position.Z,
                SpawnRotationX         = spawnPosition.Rotation.X,
                SpawnRotationY         = spawnPosition.Rotation.Y,
                SpawnRotationZ         = spawnPosition.Rotation.Z,
                PrimaryColor           = primaryColor.ToHex(),
                SecondaryColor         = secondaryColor.ToHex(),
                EnginePowerMultiplier  = enginePowerMultiplier,
                EngineTorqueMultiplier = engineTorqueMultiplier,
                ItemsInVehicle         = new List <ItemModel>(),
                Milage                 = 0.0f,
            };

            vehicleModel.FuelTank        = GetFuelTankSize((VehicleClass)NAPI.Vehicle.GetVehicleClass(NAPI.Util.VehicleNameToModel(vehicleModel.VehicleHash)));
            vehicleModel.Fuel            = vehicleModel.FuelTank * 0.2f;
            vehicleModel.FuelConsumption = NAPI.Vehicle.GetVehicleMaxAcceleration(NAPI.Util.VehicleNameToModel(vehicleModel.VehicleHash)) / 0.2f;

            bool nonDbVehicle = character == null && groupModel == null;

            if (!nonDbVehicle)
            {
                RoleplayContext ctx = Singletons.RoleplayContextFactory.Create();
                using (VehiclesRepository repository = new VehiclesRepository(ctx))
                {
                    repository.Insert(vehicleModel);
                    repository.Save();
                }
            }

            return(new VehicleEntity(vehicleModel)
            {
                _nonDbVehicle = nonDbVehicle
            });
        }
コード例 #7
0
        public static bool CreateVehicle(VehicleHash vehModel, Client _Owner)
        {
            try
            {
                if (vehModel.ToString() == "0")
                {
                    return(false);
                }
                var id   = _repository.Current.Count > 0 ? _repository.Current.LastOrDefault().VehicleId + 1 : 1;
                var _veh = new Models.Vehicle
                {
                    VehicleOnMap        = API.shared.createVehicle(vehModel, _Owner.position, _Owner.rotation, 5, 10, _Owner.dimension),
                    VehicleId           = id,
                    Plate               = "LS-" + id,
                    Dimension           = _Owner.dimension,
                    FactionId           = -1,
                    JobId               = -1,
                    VehicleModelId      = vehModel,
                    Fuel                = 100,
                    IsBlockedForTax     = false,
                    IsLocked            = false,
                    LastPosition        = _Owner.position,
                    LastRotation        = _Owner.rotation,
                    ModColor1           = 0,
                    ModColor2           = 0,
                    Color1              = 5,
                    Color2              = 10,
                    PastMinutes         = 0,
                    OwnerSocialClubName = _Owner.socialClubName,
                    Tax = 0,
                };

                _repository.Add(_veh);
                _veh.VehicleOnMap.numberPlate = _veh.Plate;
                for (int i = 0; i < 69; i++)
                {
                    _veh.Mods[i] = -1;
                }
                SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                API.shared.consoleOutput(LogCat.Warn, "Vehicle Creation Error: " + ex.ToString());
                return(false);
            }
        }
コード例 #8
0
        public static async void SpawnVehicle(VehicleHash vehicle)
        {
            var model = new Model(vehicle);
            var veh   = await World.CreateVehicle(model, Game.PlayerPed.GetOffsetPosition(new Vector3(0f, 5f, 2f)), Game.PlayerPed.Heading);

            veh.NeedsToBeHotwired = false;
            veh.Mods.InstallModKit();
            veh.Mods[VehicleModType.Engine].Index       = veh.Mods[VehicleModType.Engine].ModCount - 1;
            veh.Mods[VehicleModType.Brakes].Index       = veh.Mods[VehicleModType.Brakes].ModCount - 1;
            veh.Mods[VehicleModType.Transmission].Index = veh.Mods[VehicleModType.Transmission].ModCount - 1;

            veh.Mods[VehicleToggleModType.Turbo].IsInstalled           = true;
            veh.Mods[VehicleToggleModType.XenonHeadlights].IsInstalled = true;


            veh.Rotation = Game.PlayerPed.Rotation + new Vector3(0f, 0f, 90f);
            API.SetVehicleEngineOn(veh.Handle, false, false, true);
            ChatUtil.SendMessageToClient("[VehicleSpawner]", "You spawned a " + vehicle.ToString(), 255, 255, 255);
        }
コード例 #9
0
ファイル: Sandbox.cs プロジェクト: kFxDaKing/RPServer
        public void Veh(Client player, string vehicleName = "")
        {
            if (player.HasData("PERSONAL_VEHICLE"))
            {
                Entity veh = player.GetData("PERSONAL_VEHICLE");
                veh.Delete();
                player.ResetData("PERSONAL_VEHICLE");
            }

            VehicleHash vehHash = NAPI.Util.VehicleNameToModel(vehicleName);

            if (vehHash.ToString().Equals("0"))
            {
                return;
            }
            Vehicle v = NAPI.Vehicle.CreateVehicle(vehHash, player.Position.Around(5), 0f, 0, 0);

            v.NumberPlate      = "STATIQUE";
            v.WindowTint       = 5;
            v.NumberPlateStyle = 2;
            player.SetData("PERSONAL_VEHICLE", v);
            NAPI.Chat.SendChatMessageToPlayer(player, "Spawned a " + vehicleName + ".");
        }
コード例 #10
0
        private async void checkChopInteraction()
        {
            if (isChoppingVehicle)
            {
                return;
            }

            isChoppingVehicle = true;
            try
            {
                var playerVeh = Game.PlayerPed.IsInVehicle() ? Game.PlayerPed.CurrentVehicle : Game.PlayerPed.LastVehicle;

                VehicleHash vehHash    = (VehicleHash)playerVeh.Model.Hash;
                bool        hasVehId   = playerVeh.HasDecor("Vehicle.ID");
                bool        isOwnedVeh = hasVehId && playerVeh.GetDecor <int>("Vehicle.ID") < 1000000;
                if (currentVehicleList.FindAll(o => o.ToString().Contains(vehHash.ToString())).Any() && !isOwnedVeh)
                {
                    float engineHealth = playerVeh.EngineHealth < 100 ? 100 : playerVeh.EngineHealth;
                    float bodyHealth   = playerVeh.BodyHealth < 100 ? 100 : playerVeh.BodyHealth;
                    playerVeh.LockStatus = VehicleLockStatus.Locked;
                    if (playerVeh.Occupants.Length != 0)
                    {
                        Log.ToChat("[Chopshop]", "Everyone out of the vehicle so chopping can begin", ConstantColours.Criminal);
                        while (playerVeh.Occupants.Length != 0)
                        {
                            await BaseScript.Delay(0);
                        }
                    }

                    await playerVeh.Doors.GetAll().ToList().ForEachAsync(async o =>
                    {
                        await BaseScript.Delay(800);
                        o.Open();
                    });

                    for (int i = 1; i < 12; i++)
                    {
                        if (playerVeh.Wheels[i] != null)
                        {
                            playerVeh.Wheels[i].Burst();
                        }
                    }

                    playerVeh.IsDriveable = false;
                    Log.Debug($"Engine health is {engineHealth}");
                    Log.Debug($"Body health is {bodyHealth}");
                    int vehicleReward = (int)Math.Round((getBasePriceForClass(playerVeh) * (engineHealth / rand.Next(500, 700)) * (bodyHealth / rand.Next(500, 700))) / 2, 0);
                    await BaseScript.Delay(2500);

                    playerVeh.Delete();
                    currentVehicleList.Remove(vehHash);
                    giveVehCompletionAward(vehicleReward);
                }
                else
                {
                    Log.ToChat("[Chopshop]", "This vehicle isn't wanted right now", ConstantColours.Criminal);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
            finally
            {
                isChoppingVehicle = false;
            }
        }
コード例 #11
0
 public void CreateVehicle(Client player, int c1, int c2, VehicleHash hash, int ownerid, int fix = 0)
 {
     Core.Player sender = Core.Player.Find(player);
     if (!sender.Equals(null) && sender.Adminlevel > 3)
     {
         Core.Player localp = Core.Player.Find(ownerid);
         if (localp != null)
         {
             EdenCore.VehicleList.Add(new EdenVehicle(hash, EdenCore.VehicleList.Count, API.createVehicle(hash, new Vector3(player.position.X + 5, player.position.Y, player.position.Z), player.rotation, c1, c2), ownerid, c1, c2, localp.Character.Name, player.position, true));
             API.sendChatMessageToPlayer(player, ownerid.ToString() + " ID'li oyuncuya " + hash.ToString() + " model bir araç verdiniz.");
         }
         else
         {
             API.sendChatMessageToPlayer(player, "Bu ID'de bir oyuncu bulunamadı.");  // replace error message function
         }
     }
     else
     {
         // not admin
     }
 }
コード例 #12
0
 private VehicleSetting ReadVehicleSettings( VehicleHash vehicle )
 {
     string vehicleStr = vehicle.ToString();
     if ( !this._vehicleModifiers.ContainsKey( vehicleStr ) )
     {
         float incTempMod = this._vehicleSettings.Read( "IncTempModifier", vehicleStr, IncTempModifier );
         float decTempMod = this._vehicleSettings.Read( "DecTempModifier", vehicleStr, DecTempModifier );
         this._vehicleModifiers.Add( vehicleStr, new VehicleSetting( incTempMod, decTempMod, vehicleStr ) );
     }
     return this._vehicleModifiers[ vehicleStr ];
 }
コード例 #13
0
        private void OnClientEventTrigger(Client sender, string eventName, object[] arguments)
        {
            if (eventName == "menu_handler_select_item")
            {
                if ((int)arguments[0] == 190)
                {
                    API.consoleOutput(arguments[1].ToString());
                    API.setEntityData(sender, "VehicleOfUsingShop", (int)arguments[1]);
                    List <string> Actions = new List <string>();
                    if (File.Exists("paints.xml"))
                    {
                        IEnumerable <XElement> Paints = xelement.Elements();
                        foreach (var p in Paints)
                        {
                            Actions.Add(p.Attribute("Name").Value.ToString());
                        }
                    }
                    API.triggerClientEvent(sender, "bettermenuManager", 191, "Concessionnaire", "Sélectionner une peinture:", false, Actions);
                }
                else if ((int)arguments[0] == 191)
                {
                    var    pnj = API.getEntityData(sender, "pnj");
                    double cx  = API.getEntityData(pnj, "cX");
                    double cy  = API.getEntityData(pnj, "cY");
                    double cz  = API.getEntityData(pnj, "cZ");

                    List <KeyValuePair <VehicleHash, int> > Products = new List <KeyValuePair <VehicleHash, int> >();
                    Products = API.getEntityData(sender, "ProductsOfUsingShop");
                    int VehicleChoise = API.getEntityData(sender, "VehicleOfUsingShop");
                    API.resetEntityData(sender, "ProductsOfUsingShop");
                    API.resetEntityData(sender, "VehicleOfUsingShop");
                    KeyValuePair <VehicleHash, int> veharray = Products[(int)VehicleChoise];
                    VehicleHash model = veharray.Key;
                    int         price = veharray.Value;
                    API.consoleOutput(model.ToString());
                    if ((int)model == 0)
                    {
                        API.sendNotificationToPlayer(sender, "~r~[ERREUR] ~s~Le véhicule que vous demandez n'est pas disponible."); return;
                    }
                    if (Money.TakeMoney(sender, price))
                    {
                        Vehicle car2  = API.createVehicle(model, new Vector3(cx, cy, cz), new Vector3(0, 0, 20), 111, 111);
                        string  plate = Vehicles.Vehicle.RandomPlate();
                        API.setVehicleNumberPlate(car2, plate);
                        API.setEntitySyncedData(car2, "Owner", sender.socialClubName);
                        API.setEntitySyncedData(car2, "OwnerName", sender.getSyncedData("Nom_Prenom"));
                        API.setEntitySyncedData(car2, "Plate", plate.ToString());
                        Items.Items.InventoryHolder ih = new Items.Items.InventoryHolder();
                        ih.Owner = car2.handle;
                        API.setEntityData(car2, "InventoryHolder", ih);
                        API.setEntitySyncedData(car2, "VEHICLE_FUEL", 100);
                        API.setEntitySyncedData(car2, "VEHICLE_FUEL_MAX", 100);
                        API.setEntityData(car2, "weight", 0);
                        API.setEntityData(car2, "weight_max", Vehicles.Vehicle.GetVehicleWeight(model));
                        API.setVehicleLocked(car2, true);
                        API.setEntitySyncedData(car2, "Locked", true);
                        string paint = xelement.Descendants("Vehicle").ElementAt((int)arguments[1]).Attribute("Color").Value;
                        int    color = Convert.ToInt32(paint);
                        API.setVehiclePrimaryColor(car2, color);
                        InsertVehicle(sender, model, plate, new Vector3(cx, cy, cz), color);
                        UpdatePlayerMoney(sender);
                        API.setVehicleEngineStatus(car2, false);
                        API.triggerClientEvent(sender, "display_subtitle", "Vendu! Voici les clefs de votre véhicule.", 3000);
                    }
                    else
                    {
                        API.triggerClientEvent(sender, "display_subtitle", "Désolé, vous n'avez pas assez d'argent sur vous!", 3000);
                    }
                }
            }
        }
コード例 #14
0
 public static void InsertVehicle(Client player, VehicleHash model, string plate, Vector3 position, int color)
 {
     try
     {
         if (player != null || plate != null || position != null)
         {
             string pos = "[[" + position.X.ToString() + "],[" + position.Y.ToString() + "],[" + position.Z.ToString() + "]]";;
             InsertQuery(String.Format("INSERT INTO vehicles ( side, classname, type, pid, plate, color, inventory, fuel, position, rotation, active) VALUES ('CIV','{0}','ground','{1}','{2}','{4}','[]','100','{3}','[[0],[0],[0]]','1')", model.ToString(), player.socialClubName, plate, pos, color));
         }
     }
     catch (Exception e)
     {
         API.shared.consoleOutput("~r~[ERROR] : ~s~" + e.ToString());
     }
 }