From 1b2a90a4bdf80c939587e8067cf06e7236b5007d Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Sun, 20 Jul 2025 21:09:58 +0200 Subject: [PATCH] Update client.lua --- .../nordi_talk_to_npc/client/client.lua | 149 +++++++----------- 1 file changed, 61 insertions(+), 88 deletions(-) diff --git a/resources/[tools]/nordi_talk_to_npc/client/client.lua b/resources/[tools]/nordi_talk_to_npc/client/client.lua index d885efc01..edb6e2193 100644 --- a/resources/[tools]/nordi_talk_to_npc/client/client.lua +++ b/resources/[tools]/nordi_talk_to_npc/client/client.lua @@ -1,7 +1,7 @@ local QBCore = exports['qb-core']:GetCoreObject() local spawnedNPCs = {} --- NPC Spawn Function +-- NPC Spawn Function (gleich wie oben) local function SpawnNPC(npcId, npcData) local model = GetHashKey(npcData.model) @@ -41,13 +41,13 @@ CreateThread(function() end end) --- Dialog öffnen - Startet mit NPC-Text Pop-up +-- Dialog öffnen - Zeigt zuerst NPC-Text, dann Optionen RegisterNetEvent('npc-dialog:client:openDialog', function(data) local npcId = data.npcId local npcData = Config.NPCs[npcId] if not npcData then return end - -- NPC-Begrüßung als Pop-up + -- Zuerst NPC-Text als Alert anzeigen lib.alertDialog({ header = npcData.dialog.title, content = npcData.dialog.description, @@ -58,12 +58,13 @@ RegisterNetEvent('npc-dialog:client:openDialog', function(data) } }):next(function(confirmed) if confirmed then + -- Dann Dialog-Optionen anzeigen ShowDialogOptions(npcData, npcId) end end) end) --- Dialog-Optionen anzeigen (Context-Menü) +-- Dialog-Optionen anzeigen function ShowDialogOptions(npcData, npcId) local options = {} @@ -74,33 +75,17 @@ function ShowDialogOptions(npcData, npcId) icon = option.icon, onSelect = function() if option.info then - -- Direkte Info als Pop-up lib.alertDialog({ header = option.title, content = option.info, centered = true, cancel = true, labels = { - cancel = 'Zurück zum Gespräch' + cancel = 'Zurück' } - }):next(function() - ShowDialogOptions(npcData, npcId) - end) + }) elseif option.response then - -- NPC-Antwort als Pop-up, dann weiter - lib.alertDialog({ - header = option.response.title, - content = option.response.description, - centered = true, - cancel = false, - labels = { - confirm = 'Weiter reden' - } - }):next(function(confirmed) - if confirmed then - ShowResponseOptions(option.response, npcData, npcId) - end - end) + ShowResponse(option.response, npcData, npcId) end end }) @@ -114,80 +99,68 @@ function ShowDialogOptions(npcData, npcId) lib.registerContext({ id = 'npc_options_' .. npcId, - title = "Was möchtest du sagen?", + title = "Antworten:", options = options }) lib.showContext('npc_options_' .. npcId) end --- Response-Optionen anzeigen -function ShowResponseOptions(response, npcData, npcId) - if not response.options then return end - - local options = {} - - for i, option in ipairs(response.options) do - table.insert(options, { - title = option.title, - description = option.description, - icon = option.icon, - onSelect = function() - if option.info then - -- Info als Pop-up - lib.alertDialog({ - header = option.title, - content = option.info, - centered = true, - cancel = true, - labels = { - cancel = 'Gespräch beenden' - } - }) - elseif option.response then - -- Weitere NPC-Antwort als Pop-up - lib.alertDialog({ - header = option.response.title, - content = option.response.description, - centered = true, - cancel = false, - labels = { - confirm = 'Weiter' - } - }):next(function(confirmed) - if confirmed then - ShowResponseOptions(option.response, npcData, npcId) +-- Response anzeigen +function ShowResponse(response, npcData, npcId) + lib.alertDialog({ + header = response.title, + content = response.description, + centered = true, + cancel = false, + labels = { + confirm = 'Weiter' + } + }):next(function(confirmed) + if confirmed and response.options then + local options = {} + + for i, option in ipairs(response.options) do + table.insert(options, { + title = option.title, + description = option.description, + icon = option.icon, + onSelect = function() + if option.info then + lib.alertDialog({ + header = option.title, + content = option.info, + centered = true, + cancel = true, + labels = { + cancel = 'Schließen' + } + }) + elseif option.response then + ShowResponse(option.response, npcData, npcId) end - end) - end + end + }) end - }) - end - - -- Zurück zum Hauptgespräch - table.insert(options, { - title = "← Zurück", - description = "Zurück zu den Hauptoptionen", - icon = 'arrow-left', - onSelect = function() - ShowDialogOptions(npcData, npcId) + + table.insert(options, { + title = "← Zurück", + description = "Zurück zu den Hauptoptionen", + icon = 'arrow-left', + onSelect = function() + ShowDialogOptions(npcData, npcId) + end + }) + + lib.registerContext({ + id = 'npc_response_' .. npcId .. '_' .. math.random(1000, 9999), + title = "Antworten:", + options = options + }) + + lib.showContext('npc_response_' .. npcId .. '_' .. math.random(1000, 9999)) end - }) - - -- Verlassen - table.insert(options, { - title = "🚪 Verlassen", - description = "Dialog beenden", - icon = 'times' - }) - - lib.registerContext({ - id = 'npc_response_' .. npcId .. '_' .. math.random(1000, 9999), - title = "Was möchtest du antworten?", - options = options - }) - - lib.showContext('npc_response_' .. npcId .. '_' .. math.random(1000, 9999)) + end) end -- Cleanup