1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-06 15:12:50 +02:00
parent 323a388a5d
commit 6d22d5f77c

View file

@ -170,58 +170,24 @@ if (Config.useContextMenu) then
local item = transferVehMenu:AddItem(model .. " " .. plate)
item.closeMenuOnClick = true
item.OnClick = function()
local nearbyPlayers = GetNearbyPlayersWithNames(5.0)
item.OnClick = function()
-- Finde den nächsten Spieler
local player = GetClosestPlayer(5.0)
if #nearbyPlayers == 0 then
Notification("Keine Spieler in der Nähe gefunden")
return
end
if player then
local targetPlayerId = GetPlayerServerId(player)
local playerName = GetPlayerName(player)
-- Spielerauswahl-Menü erstellen
local playerOptions = {}
for _, player in ipairs(nearbyPlayers) do
table.insert(playerOptions, {
title = player.name,
description = "Entfernung: " .. math.floor(player.distance * 10) / 10 .. "m",
metadata = {
["Spieler ID"] = player.serverId
},
args = {
serverId = player.serverId,
name = player.name
}
})
end
local success = CB:Trigger("VKC:transferVehicleOwnership", plate, targetPlayerId)
-- Stelle sicher, dass wir mindestens eine Option haben
if #playerOptions == 0 then
Notification("Keine Spieler in der Nähe gefunden")
return
end
lib.registerMenu({
id = 'transfer_vehicle_menu',
title = 'Fahrzeug übergeben',
position = 'top-right',
options = playerOptions,
onSelect = function(selected, scrollIndex, args)
if args and args.serverId then
local targetPlayer = args.serverId
local success = CB:Trigger("VKC:transferVehicleOwnership", plate, targetPlayer)
if success then
Notification("Du hast dein " .. model .. " an " .. args.name .. " übergeben")
else
Notification("Übergabe fehlgeschlagen")
end
else
Notification("Fehler bei der Spielerauswahl")
end
end
})
lib.showMenu('transfer_vehicle_menu')
if success then
Notification(string.format("Du hast dein %s an %s übergeben", model, playerName))
else
Notification("Übergabe fehlgeschlagen")
end
else
Notification("Kein Spieler in der Nähe gefunden")
end
end
end
@ -428,40 +394,6 @@ function GenerateKeymakerMenuNativeUI()
menuPoolNativeUI:RefreshIndex()
end
-- Funktion zum Abrufen von Spielern in der Nähe mit Namen
function GetNearbyPlayersWithNames(maxDistance)
local players = {}
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
for _, id in ipairs(GetActivePlayers()) do
if id ~= PlayerId() then
local targetPed = GetPlayerPed(id)
local targetCoords = GetEntityCoords(targetPed)
-- Verwende #(vector1 - vector2) für die Distanzberechnung
local distance = #(playerCoords - targetCoords)
if distance <= maxDistance then
local playerName = GetPlayerName(id)
table.insert(players, {
id = id,
serverId = GetPlayerServerId(id),
name = playerName,
distance = distance
})
end
end
end
-- Nach Entfernung sortieren
table.sort(players, function(a, b)
return a.distance < b.distance
end)
return players
end
function GenerateKeyInventoryNativeUI()
keyInvMenuNativeUI:Clear()
@ -502,57 +434,54 @@ function GenerateKeyInventoryNativeUI()
submenuTransferVehicle:AddItem(vehItem)
end
submenuTransferVehicle.OnItemSelect = function(menu, item, index)
local selectedVehicle = vehicleData[index]
local plate = selectedVehicle[1]
local model = GetLabelText(GetDisplayNameFromVehicleModel(selectedVehicle[2]))
if (model == "NULL") then
model = GetDisplayNameFromVehicleModel(selectedVehicle[2])
end
submenuTransferVehicle.OnItemSelect = function(menu, item, index)
local selectedVehicle = vehicleData[index]
local plate = selectedVehicle[1]
local model = GetLabelText(GetDisplayNameFromVehicleModel(selectedVehicle[2]))
if (model == "NULL") then
model = GetDisplayNameFromVehicleModel(selectedVehicle[2])
end
-- Spieler in der Nähe abrufen
local nearbyPlayers = GetNearbyPlayersWithNames(5.0)
-- Finde den nächsten Spieler
local player = GetClosestPlayer(5.0)
if #nearbyPlayers == 0 then
Notification("Keine Spieler in der Nähe gefunden")
return
end
if player then
local targetPlayerId = GetPlayerServerId(player)
local playerName = GetPlayerName(player)
-- Erstelle ein neues NativeUI-Menü für die Spielerauswahl
local playerSelectMenu = NativeUI.CreateMenu("Spieler auswählen", "Wähle einen Spieler für die Fahrzeugübergabe")
menuPoolNativeUI:Add(playerSelectMenu)
local success = CB:Trigger("VKC:transferVehicleOwnership", plate, targetPlayerId)
for _, player in ipairs(nearbyPlayers) do
local playerItem = NativeUI.CreateItem(player.name, "Entfernung: " .. math.floor(player.distance * 10) / 10 .. "m")
playerSelectMenu:AddItem(playerItem)
end
playerSelectMenu.OnItemSelect = function(menu, item, index)
local targetPlayer = nearbyPlayers[index].serverId
local success = CB:Trigger("VKC:transferVehicleOwnership", plate, targetPlayer)
if success then
Notification("Du hast dein " .. model .. " an " .. nearbyPlayers[index].name .. " übergeben")
if success then
lib.notify({
title = "Fahrzeug übergeben",
description = "Du hast dein " .. model .. " an " .. playerName .. " übergeben",
position = "top",
type = "success",
icon = "car"
})
else
lib.notify({
title = "Fahrzeug übergeben",
description = "Übergabe fehlgeschlagen",
position = "top",
type = "error",
icon = "car"
})
end
else
Notification("Übergabe fehlgeschlagen")
lib.notify({
title = "Fahrzeug übergeben",
description = "Kein Spieler in der Nähe gefunden",
position = "top",
type = "error",
icon = "car"
})
end
menuPoolNativeUI:CloseAllMenus()
menuOpen = false
end
playerSelectMenu.OnMenuClosed = function(menu)
menuOpen = false
end
menuPoolNativeUI:CloseAllMenus()
playerSelectMenu:Visible(true)
menuOpen = true
end
local submenuShowKeys = menuPoolNativeUI:AddSubMenu(keyInvMenuNativeUI, Config.Strings.NUI.keysTitle, Config.Strings.NUI.keysDesc)
submenuShowKeys.ParentItem:RightLabel(">")
submenuShowKeys.Subtitle.Text._Text = "~b~" .. Config.Strings.NUI.keysTitle
@ -728,8 +657,6 @@ function ToggleLockOnVehicle(vehicle, lock)
Citizen.Wait(150)
SetVehicleLights(vehicle, 0)
Citizen.Wait(150)
SetVehicleLights(vehicle, 0)
Citizen.Wait(150)
SetVehicleLights(vehicle, 2)
Citizen.Wait(150)
SetVehicleLights(vehicle, 0)
@ -787,7 +714,6 @@ AddEventHandler("VKC:vehicleTransferNotif", function(plate, model)
end)
function IsVehicleOwner(vehicle)
if (not DoesEntityExist(vehicle)) then
print("^1[ERROR] Parameter \"vehicle\" was nil or vehicle did not exist while triggering export \"IsVehicleOwner\"!")
@ -1025,3 +951,4 @@ if Config.useNativeUI then
originalGenerateKeyInventoryNativeUI()
end
end