Files
2026-07-16 09:35:32 +02:00

67 lines
1.8 KiB
Lua

-- d4rk_tablet — Bridge Client
-- Tablet (Web-iframe) öffnen, Auth-Token an die NUI übergeben, Waypoint setzen.
local isOpen = false
local function closeTablet()
if not isOpen then return end
isOpen = false
SetNuiFocus(false, false)
SendNUIMessage({ action = 'close' })
end
local function openTablet()
if isOpen then return end
-- Token vom Server holen (Server-zu-Server zum Backend)
local auth = lib.callback.await('d4rk_tablet:getAuth', false)
if not auth or not auth.token then
lib.notify({ title = 'MDT', description = 'Kein Zugriff (kein Behörden-Job?).', type = 'error' })
return
end
isOpen = true
SetNuiFocus(true, true)
SendNUIMessage({
action = 'open',
webUrl = Config.WebUrl,
token = auth.token,
user = auth.user,
})
end
RegisterCommand(Config.OpenCommand, openTablet, false)
RegisterKeyMapping(Config.OpenCommand, 'MDT öffnen', 'keyboard', '')
-- Aus der Web-App (via NUI-Shell) kommende Aktionen
RegisterNUICallback('close', function(_, cb)
closeTablet()
cb({ ok = true })
end)
RegisterNUICallback('setWaypoint', function(data, cb)
if data and data.x and data.y then
SetNewWaypoint(data.x + 0.0, data.y + 0.0)
lib.notify({ title = 'MDT', description = 'Wegpunkt gesetzt.', type = 'success' })
end
cb({ ok = true })
end)
-- ESC schließt das Tablet
CreateThread(function()
while true do
if isOpen then
if IsControlJustReleased(0, 322) then -- ESC
closeTablet()
end
Wait(0)
else
Wait(250)
end
end
end)
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() and isOpen then
SetNuiFocus(false, false)
end
end)