public async Task resetTuningToNormal(IPlayer player, IVehicle vehicle) { try { if (player == null || !player.Exists || vehicle == null || !vehicle.Exists) { return; } if (player.GetCharacterMetaId() <= 0 || vehicle.GetVehicleId() <= 0) { return; } ServerVehicles.SetVehicleModsCorrectly(vehicle); } catch (Exception e) { Alt.Log($"{e}"); } }
public async Task DoGarageAction(IPlayer player, int garageid, string action, int vehID) { try { if (player == null || !player.Exists || action == "" || vehID <= 0 || garageid <= 0) { return; } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int charId = User.GetPlayerOnline(player); if (charId <= 0) { return; } var vehicle = Alt.Server.GetVehicles().ToList().FirstOrDefault(x => x.GetVehicleId() == (ulong)vehID); if (action == "storage") { //Fahrzeug einparken if (vehicle == null) { return; } if (!vehicle.Position.IsInRange(player.Position, 50f)) { return; } //var gData = ServerGarages.ServerGarageSlots_.FirstOrDefault(x => vehicle.Position.IsInRange(new Position(x.posX, x.posY, x.posZ), 15f) && x.garageId == garageid); //Position garagePos = new Position(gData.posX, gData.posY, gData.posZ); //Alt.Log($"StorageVeh: {gData} - {gData.garageId} - {garagePos} - {garagePos.ToString()}"); //if (garagePos == null || garagePos == new Position(0, 0, 0)) return; ServerVehicles.SetVehicleInGarage(vehicle, true, garageid); HUDHandler.SendNotification(player, 2, 5000, $"Fahrzeug erfolgreich eingeparkt."); } else if (action == "take") { //Fahrzeug ausparken Position outPos = new Position(0, 0, 0); int curPid = 1; bool slotAreFree = true; foreach (var x in ServerGarages.ServerGarageSlots_.Where(x => x.garageId == garageid)) { foreach (var veh in Alt.Server.GetVehicles().ToList()) { if (veh.Position.IsInRange(ServerGarages.GetGarageSlotPosition(garageid, curPid), 2f)) { slotAreFree = false; curPid++; break; } else { slotAreFree = true; } } if (slotAreFree) { break; } } if (!slotAreFree) { HUDHandler.SendNotification(player, 4, 5000, $"Es ist kein Parkplatz mehr frei."); return; } if (vehicle != null) { HUDHandler.SendNotification(player, 4, 5000, $"Ein unerwarteter Fehler ist aufgetreten. [GARAGE-002]"); return; } var finalVeh = ServerVehicles.ServerVehicles_.FirstOrDefault(v => v.id == vehID); if (finalVeh == null) { HUDHandler.SendNotification(player, 4, 5000, $"Ein unerwarteter Fehler ist aufgetreten. [GARAGE-001]"); return; } var altVeh = await AltAsync.Do(() => Alt.CreateVehicle((uint)finalVeh.hash, ServerGarages.GetGarageSlotPosition(garageid, curPid), (ServerGarages.GetGarageSlotRotation(garageid, curPid)))); altVeh.LockState = VehicleLockState.Locked; altVeh.EngineOn = false; altVeh.NumberplateText = finalVeh.plate; altVeh.SetVehicleId((ulong)finalVeh.id); altVeh.SetVehicleTrunkState(false); ServerVehicles.SetVehicleModsCorrectly(altVeh); ServerVehicles.SetVehicleInGarage(altVeh, false, garageid); } if (!CharactersTablet.HasCharacterTutorialEntryFinished(charId, "useGarage")) { CharactersTablet.SetCharacterTutorialEntryState(charId, "useGarage", true); HUDHandler.SendNotification(player, 1, 2500, "Erfolg freigeschaltet: Keine Schäden"); } stopwatch.Stop(); if (stopwatch.Elapsed.Milliseconds > 30) { Alt.Log($"{charId} - DoGarageAction benötigte {stopwatch.Elapsed.Milliseconds}ms"); } } catch (Exception e) { Alt.Log($"{e}"); } }