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) local item = transferVehMenu:AddItem(model .. " " .. plate)
item.closeMenuOnClick = true item.closeMenuOnClick = true
item.OnClick = function() item.OnClick = function()
local nearbyPlayers = GetNearbyPlayersWithNames(5.0) -- Finde den nächsten Spieler
local player = GetClosestPlayer(5.0)
if #nearbyPlayers == 0 then if player then
Notification("Keine Spieler in der Nähe gefunden") local targetPlayerId = GetPlayerServerId(player)
return local playerName = GetPlayerName(player)
end
-- Spielerauswahl-Menü erstellen local success = CB:Trigger("VKC:transferVehicleOwnership", plate, targetPlayerId)
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
-- Stelle sicher, dass wir mindestens eine Option haben if success then
if #playerOptions == 0 then Notification(string.format("Du hast dein %s an %s übergeben", model, playerName))
Notification("Keine Spieler in der Nähe gefunden") else
return Notification("Übergabe fehlgeschlagen")
end end
else
lib.registerMenu({ Notification("Kein Spieler in der Nähe gefunden")
id = 'transfer_vehicle_menu', end
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')
end end
end end
@ -428,40 +394,6 @@ function GenerateKeymakerMenuNativeUI()
menuPoolNativeUI:RefreshIndex() menuPoolNativeUI:RefreshIndex()
end 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() function GenerateKeyInventoryNativeUI()
keyInvMenuNativeUI:Clear() keyInvMenuNativeUI:Clear()
@ -502,57 +434,54 @@ function GenerateKeyInventoryNativeUI()
submenuTransferVehicle:AddItem(vehItem) submenuTransferVehicle:AddItem(vehItem)
end end
submenuTransferVehicle.OnItemSelect = function(menu, item, index) submenuTransferVehicle.OnItemSelect = function(menu, item, index)
local selectedVehicle = vehicleData[index] local selectedVehicle = vehicleData[index]
local plate = selectedVehicle[1] local plate = selectedVehicle[1]
local model = GetLabelText(GetDisplayNameFromVehicleModel(selectedVehicle[2])) local model = GetLabelText(GetDisplayNameFromVehicleModel(selectedVehicle[2]))
if (model == "NULL") then if (model == "NULL") then
model = GetDisplayNameFromVehicleModel(selectedVehicle[2]) model = GetDisplayNameFromVehicleModel(selectedVehicle[2])
end end
-- Spieler in der Nähe abrufen -- Finde den nächsten Spieler
local nearbyPlayers = GetNearbyPlayersWithNames(5.0) local player = GetClosestPlayer(5.0)
if #nearbyPlayers == 0 then if player then
Notification("Keine Spieler in der Nähe gefunden") local targetPlayerId = GetPlayerServerId(player)
return local playerName = GetPlayerName(player)
end
-- Erstelle ein neues NativeUI-Menü für die Spielerauswahl local success = CB:Trigger("VKC:transferVehicleOwnership", plate, targetPlayerId)
local playerSelectMenu = NativeUI.CreateMenu("Spieler auswählen", "Wähle einen Spieler für die Fahrzeugübergabe")
menuPoolNativeUI:Add(playerSelectMenu)
for _, player in ipairs(nearbyPlayers) do if success then
local playerItem = NativeUI.CreateItem(player.name, "Entfernung: " .. math.floor(player.distance * 10) / 10 .. "m") lib.notify({
playerSelectMenu:AddItem(playerItem) title = "Fahrzeug übergeben",
end description = "Du hast dein " .. model .. " an " .. playerName .. " übergeben",
position = "top",
playerSelectMenu.OnItemSelect = function(menu, item, index) type = "success",
local targetPlayer = nearbyPlayers[index].serverId icon = "car"
local success = CB:Trigger("VKC:transferVehicleOwnership", plate, targetPlayer) })
else
if success then lib.notify({
Notification("Du hast dein " .. model .. " an " .. nearbyPlayers[index].name .. " übergeben") title = "Fahrzeug übergeben",
description = "Übergabe fehlgeschlagen",
position = "top",
type = "error",
icon = "car"
})
end
else else
Notification("Übergabe fehlgeschlagen") lib.notify({
title = "Fahrzeug übergeben",
description = "Kein Spieler in der Nähe gefunden",
position = "top",
type = "error",
icon = "car"
})
end end
menuPoolNativeUI:CloseAllMenus() menuPoolNativeUI:CloseAllMenus()
menuOpen = false menuOpen = false
end 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) local submenuShowKeys = menuPoolNativeUI:AddSubMenu(keyInvMenuNativeUI, Config.Strings.NUI.keysTitle, Config.Strings.NUI.keysDesc)
submenuShowKeys.ParentItem:RightLabel(">") submenuShowKeys.ParentItem:RightLabel(">")
submenuShowKeys.Subtitle.Text._Text = "~b~" .. Config.Strings.NUI.keysTitle submenuShowKeys.Subtitle.Text._Text = "~b~" .. Config.Strings.NUI.keysTitle
@ -728,8 +657,6 @@ function ToggleLockOnVehicle(vehicle, lock)
Citizen.Wait(150) Citizen.Wait(150)
SetVehicleLights(vehicle, 0) SetVehicleLights(vehicle, 0)
Citizen.Wait(150) Citizen.Wait(150)
SetVehicleLights(vehicle, 0)
Citizen.Wait(150)
SetVehicleLights(vehicle, 2) SetVehicleLights(vehicle, 2)
Citizen.Wait(150) Citizen.Wait(150)
SetVehicleLights(vehicle, 0) SetVehicleLights(vehicle, 0)
@ -787,7 +714,6 @@ AddEventHandler("VKC:vehicleTransferNotif", function(plate, model)
end) end)
function IsVehicleOwner(vehicle) function IsVehicleOwner(vehicle)
if (not DoesEntityExist(vehicle)) then if (not DoesEntityExist(vehicle)) then
print("^1[ERROR] Parameter \"vehicle\" was nil or vehicle did not exist while triggering export \"IsVehicleOwner\"!") 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() originalGenerateKeyInventoryNativeUI()
end end
end end