Exemplo n.º 1
0
        public void SpawnVeh(IAltPlayer player, string vehicleName)
        {
            if (Misc.BlacklistedVehicle.Contains(Alt.Hash(vehicleName)))
            {
                player.SendChatMessage("{FF0000} Vehicle is blacklisted.");
                return;
            }

            if (!Enum.IsDefined(typeof(VehicleModel), Alt.Hash(vehicleName)))
            {
                player.SendChatMessage("{FF0000} Invalid vehicle model!");
                return;
            }

            if (Alt.GetAllVehicles().Any(veh => veh.Position.Distance(player.Position) < 3))
            {
                player.SendChatMessage("{FF0000} You are too close to a vehicle!");
                return;
            }

            if (player.LastVehicleSpawn.AddSeconds(10) > DateTime.Now)
            {
                player.SendChatMessage("{FF0000} You have to wait 10s before spawning a new vehicle!");
                return;
            }

            if (player.Vehicles.Count >= 3)
            {
                var target = player.Vehicles.OrderBy(veh => veh.SpawnTime).First();
                player.Vehicles.Remove(target);
                target.Remove();
                player.SendChatMessage("{FF0000} You can't have more than 3 vehicles. We removed your oldest one!");
            }

            if (player.IsInVehicle)
            {
                player.SendChatMessage("{FF0000} You are already in a vehicle we replaced it for you!");
                player.Vehicle.Remove();
                return;
            }

            lock (StatsHandler.StatsData)
            {
                StatsHandler.StatsData.VehiclesSpawned++;
            }

            var spawnedVeh = (AltVehicle)Alt.CreateVehicle(Alt.Hash(vehicleName),
                                                           player.Position + new Position(1, 0, 0), new Rotation(0, 0, player.Rotation.Yaw));

            player.SetIntoVehicle(spawnedVeh, 1);
            player.LastVehicleSpawn = DateTime.Now;
            player.Vehicles.Add(spawnedVeh);
            spawnedVeh.Owner = player;
            player.Emit("set_last_command");
        }