forked from Simnation/Main
ed
This commit is contained in:
parent
323a388a5d
commit
6d22d5f77c
1 changed files with 59 additions and 132 deletions
|
@ -170,59 +170,25 @@ 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 #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
|
if success then
|
||||||
Notification("Du hast dein " .. model .. " an " .. args.name .. " übergeben")
|
Notification(string.format("Du hast dein %s an %s übergeben", model, playerName))
|
||||||
else
|
else
|
||||||
Notification("Übergabe fehlgeschlagen")
|
Notification("Übergabe fehlgeschlagen")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Notification("Fehler bei der Spielerauswahl")
|
Notification("Kein Spieler in der Nähe gefunden")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
|
||||||
|
|
||||||
lib.showMenu('transfer_vehicle_menu')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
playerMenu:SetPosition(screenPosition)
|
playerMenu:SetPosition(screenPosition)
|
||||||
|
@ -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,7 +434,7 @@ 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]))
|
||||||
|
@ -510,49 +442,46 @@ submenuTransferVehicle.OnItemSelect = function(menu, item, index)
|
||||||
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
|
|
||||||
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
|
if success then
|
||||||
Notification("Du hast dein " .. model .. " an " .. nearbyPlayers[index].name .. " übergeben")
|
lib.notify({
|
||||||
|
title = "Fahrzeug übergeben",
|
||||||
|
description = "Du hast dein " .. model .. " an " .. playerName .. " übergeben",
|
||||||
|
position = "top",
|
||||||
|
type = "success",
|
||||||
|
icon = "car"
|
||||||
|
})
|
||||||
else
|
else
|
||||||
Notification("Übergabe fehlgeschlagen")
|
lib.notify({
|
||||||
|
title = "Fahrzeug übergeben",
|
||||||
|
description = "Übergabe fehlgeschlagen",
|
||||||
|
position = "top",
|
||||||
|
type = "error",
|
||||||
|
icon = "car"
|
||||||
|
})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue