2026-04-14 17:41:39 +02:00

106 lines
3.2 KiB
Lua

local isNearElevator = false
local currentBuilding = nil
local currentFloor = nil
local showui = false
CreateThread(function()
while true do
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local nearestDist, nearestBuilding, nearestFloor
for _, building in ipairs(Config.Buildings) do
if building.floors then
for _, floor in ipairs(building.floors) do
local dist = #(playerCoords - vector3(floor.coords.x, floor.coords.y, floor.coords.z))
if not nearestDist or dist < nearestDist then
nearestDist = dist
nearestBuilding = building
nearestFloor = floor
end
end
end
end
if nearestDist and nearestDist < 1.8 then
if not isNearElevator then
isNearElevator = true
currentBuilding = nearestBuilding
currentFloor = nearestFloor
-- Einmal anzeigen wenn Zone betreten, 5000ms
exports['hex_4_hud']:ShowHelpNotify("Aufzug benutzen", "E", 5000)
end
else
if isNearElevator then
isNearElevator = false
currentBuilding = nil
currentFloor = nil
exports['hex_4_hud']:HideHelpNotify()
end
end
Wait(500)
end
end)
-- Input-Loop
CreateThread(function()
while true do
if isNearElevator and not showui then
if IsControlJustReleased(0, 38) then
OpenElevatorUI(currentBuilding, currentFloor)
end
Wait(0)
else
Wait(500)
end
end
end)
function OpenElevatorUI(building, currentFloor)
exports['hex_4_hud']:HideHelpNotify()
SendNUIMessage({ action = "open", building = building, currentFloor = currentFloor })
SetNuiFocus(true, true)
showui = true
end
function CloseElevatorUI()
SetNuiFocus(false, false)
showui = false
end
RegisterNUICallback('close', function(data, cb)
CloseElevatorUI()
cb('OK')
end)
RegisterNUICallback('setNuiFocus', function(data, cb)
SetNuiFocus(data.focus, data.cursor)
cb('OK')
end)
RegisterNUICallback('floorSelected', function(data, cb)
local coords = data.coords
if coords then
local ped = PlayerPedId()
FreezeEntityPosition(ped, true)
SetNuiFocus(false, false)
exports['hex_4_hud']:Notify("Aufzug", "Der Aufzug wurde gerufen...", "info", 4000)
Wait(2000)
PlaySoundFrontend(-1, "CLOSED", "MP_PROPERTIES_ELEVATOR_DOORS", 1)
Wait(2500)
PlaySoundFrontend(-1, "Hack_Success", "DLC_HEIST_BIOLAB_PREP_HACKING_SOUNDS", 0)
Wait(500)
PlaySoundFrontend(-1, "OPENED", "MP_PROPERTIES_ELEVATOR_DOORS", 1)
SetEntityCoords(ped, coords.x, coords.y, coords.z - 1)
SetEntityHeading(ped, coords.w)
FreezeEntityPosition(ped, false)
exports['hex_4_hud']:Notify("Aufzug", "Etage erreicht.", "success", 3000)
showui = false
end
cb('OK')
end)