public async Task BuyVehicle(IPlayer player, int shopid, string hash) { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); if (player == null || !player.Exists || shopid <= 0 || hash == "") { return; } ulong fHash = Convert.ToUInt64(hash); int charId = User.GetPlayerOnline(player); if (charId == 0 || fHash == 0) { return; } int Price = ServerVehicleShops.GetVehicleShopPrice(shopid, fHash); bool PlaceFree = true; Position ParkOut = ServerVehicleShops.GetVehicleShopOutPosition(shopid); Rotation RotOut = ServerVehicleShops.GetVehicleShopOutRotation(shopid); foreach (IVehicle veh in Alt.Server.GetVehicles().ToList()) { if (veh.Position.IsInRange(ParkOut, 2f)) { PlaceFree = false; break; } } if (!PlaceFree) { HUDHandler.SendNotification(player, 3, 5000, $"Der Ausladepunkt ist belegt."); return; } int rnd = new Random().Next(100000, 999999); if (ServerVehicles.ExistServerVehiclePlate($"NL{rnd}")) { BuyVehicle(player, shopid, hash); return; } if (!CharactersInventory.ExistCharacterItem(charId, "Bargeld", "inventory") || CharactersInventory.GetCharacterItemAmount(charId, "Bargeld", "inventory") < Price) { HUDHandler.SendNotification(player, 4, 5000, $"Du hast nicht genügend Bargeld dabei ({Price}$)."); return; } CharactersInventory.RemoveCharacterItemAmount(charId, "Bargeld", Price, "inventory"); ServerVehicles.CreateVehicle(fHash, charId, 0, 0, false, 25, ParkOut, RotOut, $"NL{rnd}", 134, 134); CharactersInventory.AddCharacterItem(charId, $"Fahrzeugschluessel NL{rnd}", 2, "inventory"); HUDHandler.SendNotification(player, 2, 5000, $"Fahrzeug erfolgreich gekauft."); if (!CharactersTablet.HasCharacterTutorialEntryFinished(charId, "buyVehicle")) { CharactersTablet.SetCharacterTutorialEntryState(charId, "buyVehicle", true); HUDHandler.SendNotification(player, 1, 2500, "Erfolg freigeschaltet: Mobilität"); } stopwatch.Stop(); if (stopwatch.Elapsed.Milliseconds > 30) { Alt.Log($"{charId} - BuyVehicle benötigte {stopwatch.Elapsed.Milliseconds}ms"); } } catch (Exception e) { Alt.Log($"{e}"); } }
internal static void OpenVehicleShop(IPlayer player, string shopname, int shopId) { if (player == null || !player.Exists || shopId <= 0) { return; } var array = ServerVehicleShops.GetVehicleShopItems(shopId); player.EmitLocked("Client:VehicleShop:OpenCEF", shopId, shopname, array); }