1
0
Fork 0
forked from Simnation/Main

Update client.lua

This commit is contained in:
Nordi98 2025-07-20 21:12:23 +02:00
parent 1b2a90a4bd
commit 802944e8f6

View file

@ -1,7 +1,7 @@
local QBCore = exports['qb-core']:GetCoreObject() local QBCore = exports['qb-core']:GetCoreObject()
local spawnedNPCs = {} local spawnedNPCs = {}
-- NPC Spawn Function (gleich wie oben) -- NPC Spawn Function
local function SpawnNPC(npcId, npcData) local function SpawnNPC(npcId, npcData)
local model = GetHashKey(npcData.model) local model = GetHashKey(npcData.model)
@ -41,14 +41,15 @@ CreateThread(function()
end end
end) end)
-- Dialog öffnen - Zeigt zuerst NPC-Text, dann Optionen -- Dialog öffnen - Startet mit NPC-Text Pop-up
RegisterNetEvent('npc-dialog:client:openDialog', function(data) RegisterNetEvent('npc-dialog:client:openDialog', function(data)
local npcId = data.npcId local npcId = data.npcId
local npcData = Config.NPCs[npcId] local npcData = Config.NPCs[npcId]
if not npcData then return end if not npcData then return end
-- Zuerst NPC-Text als Alert anzeigen -- NPC-Begrüßung als Pop-up (ohne :next())
lib.alertDialog({ CreateThread(function()
local result = lib.alertDialog({
header = npcData.dialog.title, header = npcData.dialog.title,
content = npcData.dialog.description, content = npcData.dialog.description,
centered = true, centered = true,
@ -56,15 +57,15 @@ RegisterNetEvent('npc-dialog:client:openDialog', function(data)
labels = { labels = {
confirm = 'Antworten' confirm = 'Antworten'
} }
}):next(function(confirmed) })
if confirmed then
-- Dann Dialog-Optionen anzeigen if result == 'confirm' then
ShowDialogOptions(npcData, npcId) ShowDialogOptions(npcData, npcId)
end end
end) end)
end) end)
-- Dialog-Optionen anzeigen -- Dialog-Optionen anzeigen (Context-Menü)
function ShowDialogOptions(npcData, npcId) function ShowDialogOptions(npcData, npcId)
local options = {} local options = {}
@ -75,17 +76,37 @@ function ShowDialogOptions(npcData, npcId)
icon = option.icon, icon = option.icon,
onSelect = function() onSelect = function()
if option.info then if option.info then
-- Direkte Info als Pop-up
CreateThread(function()
lib.alertDialog({ lib.alertDialog({
header = option.title, header = option.title,
content = option.info, content = option.info,
centered = true, centered = true,
cancel = true, cancel = true,
labels = { labels = {
cancel = 'Zurück' cancel = 'Zurück zum Gespräch'
} }
}) })
Wait(500) -- Kurz warten
ShowDialogOptions(npcData, npcId)
end)
elseif option.response then elseif option.response then
ShowResponse(option.response, npcData, npcId) -- NPC-Antwort als Pop-up, dann weiter
CreateThread(function()
local result = lib.alertDialog({
header = option.response.title,
content = option.response.description,
centered = true,
cancel = false,
labels = {
confirm = 'Weiter reden'
}
})
if result == 'confirm' then
ShowResponseOptions(option.response, npcData, npcId)
end
end)
end end
end end
}) })
@ -99,25 +120,17 @@ function ShowDialogOptions(npcData, npcId)
lib.registerContext({ lib.registerContext({
id = 'npc_options_' .. npcId, id = 'npc_options_' .. npcId,
title = "Antworten:", title = "Was möchtest du sagen?",
options = options options = options
}) })
lib.showContext('npc_options_' .. npcId) lib.showContext('npc_options_' .. npcId)
end end
-- Response anzeigen -- Response-Optionen anzeigen
function ShowResponse(response, npcData, npcId) function ShowResponseOptions(response, npcData, npcId)
lib.alertDialog({ if not response.options then return end
header = response.title,
content = response.description,
centered = true,
cancel = false,
labels = {
confirm = 'Weiter'
}
}):next(function(confirmed)
if confirmed and response.options then
local options = {} local options = {}
for i, option in ipairs(response.options) do for i, option in ipairs(response.options) do
@ -127,22 +140,41 @@ function ShowResponse(response, npcData, npcId)
icon = option.icon, icon = option.icon,
onSelect = function() onSelect = function()
if option.info then if option.info then
-- Info als Pop-up
CreateThread(function()
lib.alertDialog({ lib.alertDialog({
header = option.title, header = option.title,
content = option.info, content = option.info,
centered = true, centered = true,
cancel = true, cancel = true,
labels = { labels = {
cancel = 'Schließen' cancel = 'Gespräch beenden'
} }
}) })
end)
elseif option.response then elseif option.response then
ShowResponse(option.response, npcData, npcId) -- Weitere NPC-Antwort als Pop-up
CreateThread(function()
local result = lib.alertDialog({
header = option.response.title,
content = option.response.description,
centered = true,
cancel = false,
labels = {
confirm = 'Weiter'
}
})
if result == 'confirm' then
ShowResponseOptions(option.response, npcData, npcId)
end
end)
end end
end end
}) })
end end
-- Zurück zum Hauptgespräch
table.insert(options, { table.insert(options, {
title = "← Zurück", title = "← Zurück",
description = "Zurück zu den Hauptoptionen", description = "Zurück zu den Hauptoptionen",
@ -152,15 +184,21 @@ function ShowResponse(response, npcData, npcId)
end end
}) })
-- Verlassen
table.insert(options, {
title = "🚪 Verlassen",
description = "Dialog beenden",
icon = 'times'
})
local contextId = 'npc_response_' .. npcId .. '_' .. math.random(1000, 9999)
lib.registerContext({ lib.registerContext({
id = 'npc_response_' .. npcId .. '_' .. math.random(1000, 9999), id = contextId,
title = "Antworten:", title = "Was möchtest du antworten?",
options = options options = options
}) })
lib.showContext('npc_response_' .. npcId .. '_' .. math.random(1000, 9999)) lib.showContext(contextId)
end
end)
end end
-- Cleanup -- Cleanup