130 lines
		
	
	
	
		
			3.4 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			130 lines
		
	
	
	
		
			3.4 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
local QBCore = exports['qb-core']:GetCoreObject()
 | 
						|
local isMenuOpen = false
 | 
						|
local currentRestaurant = nil
 | 
						|
local currentPage = 1
 | 
						|
 | 
						|
-- DrawText3D Funktion
 | 
						|
local function DrawText3D(x, y, z, text)
 | 
						|
    SetTextScale(0.35, 0.35)
 | 
						|
    SetTextFont(4)
 | 
						|
    SetTextProportional(1)
 | 
						|
    SetTextColour(255, 255, 255, 215)
 | 
						|
    SetTextEntry("STRING")
 | 
						|
    SetTextCentre(1)
 | 
						|
    AddTextComponentString(text)
 | 
						|
    SetDrawOrigin(x,y,z, 0)
 | 
						|
    DrawText(0.0, 0.0)
 | 
						|
    local factor = (string.len(text)) / 370
 | 
						|
    DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75)
 | 
						|
    ClearDrawOrigin()
 | 
						|
end
 | 
						|
 | 
						|
-- Event zum Öffnen der Speisekarte
 | 
						|
RegisterNetEvent('qb-menu:openRestaurantMenu')
 | 
						|
AddEventHandler('qb-menu:openRestaurantMenu', function(restaurant)
 | 
						|
    if isMenuOpen then return end
 | 
						|
    
 | 
						|
    currentRestaurant = restaurant
 | 
						|
    currentPage = 1
 | 
						|
    isMenuOpen = true
 | 
						|
    
 | 
						|
    SetNuiFocus(true, true)
 | 
						|
    SendNUIMessage({
 | 
						|
        action = "open",
 | 
						|
        menu = Config.Restaurants[restaurant],
 | 
						|
        page = 1
 | 
						|
    })
 | 
						|
end)
 | 
						|
 | 
						|
-- Funktion zum Schließen des Menüs
 | 
						|
function CloseMenu()
 | 
						|
    if isMenuOpen then
 | 
						|
        isMenuOpen = false
 | 
						|
        SetNuiFocus(false, false)
 | 
						|
        SendNUIMessage({
 | 
						|
            action = "close"
 | 
						|
        })
 | 
						|
        currentRestaurant = nil
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
-- Hauptschleife
 | 
						|
CreateThread(function()
 | 
						|
    while true do
 | 
						|
        Wait(0)
 | 
						|
        if isMenuOpen then
 | 
						|
            -- ESC-Taste zum Schließen
 | 
						|
            if IsControlJustPressed(0, 177) then -- 177 = ESC
 | 
						|
                CloseMenu()
 | 
						|
            end
 | 
						|
        else
 | 
						|
            Wait(1000)
 | 
						|
        end
 | 
						|
    end
 | 
						|
end)
 | 
						|
 | 
						|
-- Zweite Hauptschleife für Locations
 | 
						|
CreateThread(function()
 | 
						|
    while true do
 | 
						|
        local sleep = 1000
 | 
						|
        local playerPed = PlayerPedId()
 | 
						|
        local playerCoords = GetEntityCoords(playerPed)
 | 
						|
        local isNearMenu = false
 | 
						|
 | 
						|
        for restaurant, data in pairs(Config.Restaurants) do
 | 
						|
            local distance = #(playerCoords - data.location)
 | 
						|
            
 | 
						|
            if distance < 2.0 then
 | 
						|
                isNearMenu = true
 | 
						|
                sleep = 0
 | 
						|
                
 | 
						|
                if not isMenuOpen then
 | 
						|
                    DrawText3D(data.location.x, data.location.y, data.location.z + 1.0, "Drücke [E] um " .. data.label .. " zu öffnen")
 | 
						|
                    
 | 
						|
                    if IsControlJustReleased(0, 38) then
 | 
						|
                        TriggerEvent('qb-menu:openRestaurantMenu', restaurant)
 | 
						|
                        Wait(100)
 | 
						|
                    end
 | 
						|
                end
 | 
						|
            end
 | 
						|
        end
 | 
						|
 | 
						|
        if not isNearMenu and isMenuOpen then
 | 
						|
            CloseMenu()
 | 
						|
        end
 | 
						|
 | 
						|
        Wait(sleep)
 | 
						|
    end
 | 
						|
end)
 | 
						|
 | 
						|
-- NUI Callbacks
 | 
						|
RegisterNUICallback('close', function(data, cb)
 | 
						|
    CloseMenu()
 | 
						|
    cb('ok')
 | 
						|
end)
 | 
						|
 | 
						|
RegisterNUICallback('changePage', function(data, cb)
 | 
						|
    currentPage = data.page
 | 
						|
    SendNUIMessage({
 | 
						|
        action = "updatePage",
 | 
						|
        menu = Config.Restaurants[currentRestaurant],
 | 
						|
        page = currentPage
 | 
						|
    })
 | 
						|
    cb('ok')
 | 
						|
end)
 | 
						|
 | 
						|
-- Event Handler für das Schließen
 | 
						|
RegisterNetEvent('qb-menu:client:closeMenu')
 | 
						|
AddEventHandler('qb-menu:client:closeMenu', function()
 | 
						|
    CloseMenu()
 | 
						|
end)
 | 
						|
 | 
						|
-- Cleanup beim Resource Stop
 | 
						|
AddEventHandler('onResourceStop', function(resourceName)
 | 
						|
    if (GetCurrentResourceName() ~= resourceName) then return end
 | 
						|
    if isMenuOpen then
 | 
						|
        CloseMenu()
 | 
						|
    end
 | 
						|
end)
 | 
						|
 | 
						|
 |