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 spawnedNPCs = {}
-- NPC Spawn Function (gleich wie oben)
-- NPC Spawn Function
local function SpawnNPC(npcId, npcData)
local model = GetHashKey(npcData.model)
@ -41,30 +41,31 @@ CreateThread(function()
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)
local npcId = data.npcId
local npcData = Config.NPCs[npcId]
if not npcData then return end
-- Zuerst NPC-Text als Alert anzeigen
lib.alertDialog({
header = npcData.dialog.title,
content = npcData.dialog.description,
centered = true,
cancel = false,
labels = {
confirm = 'Antworten'
}
}):next(function(confirmed)
if confirmed then
-- Dann Dialog-Optionen anzeigen
-- NPC-Begrüßung als Pop-up (ohne :next())
CreateThread(function()
local result = lib.alertDialog({
header = npcData.dialog.title,
content = npcData.dialog.description,
centered = true,
cancel = false,
labels = {
confirm = 'Antworten'
}
})
if result == 'confirm' then
ShowDialogOptions(npcData, npcId)
end
end)
end)
-- Dialog-Optionen anzeigen
-- Dialog-Optionen anzeigen (Context-Menü)
function ShowDialogOptions(npcData, npcId)
local options = {}
@ -75,17 +76,37 @@ function ShowDialogOptions(npcData, npcId)
icon = option.icon,
onSelect = function()
if option.info then
lib.alertDialog({
header = option.title,
content = option.info,
centered = true,
cancel = true,
labels = {
cancel = 'Zurück'
}
})
-- Direkte Info als Pop-up
CreateThread(function()
lib.alertDialog({
header = option.title,
content = option.info,
centered = true,
cancel = true,
labels = {
cancel = 'Zurück zum Gespräch'
}
})
Wait(500) -- Kurz warten
ShowDialogOptions(npcData, npcId)
end)
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
})
@ -99,68 +120,85 @@ function ShowDialogOptions(npcData, npcId)
lib.registerContext({
id = 'npc_options_' .. npcId,
title = "Antworten:",
title = "Was möchtest du sagen?",
options = options
})
lib.showContext('npc_options_' .. npcId)
end
-- 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)
-- 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
CreateThread(function()
lib.alertDialog({
header = option.title,
content = option.info,
centered = true,
cancel = true,
labels = {
cancel = 'Gespräch beenden'
}
})
end)
elseif option.response then
-- 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
table.insert(options, {
title = "← Zurück",
description = "Zurück zu den Hauptoptionen",
icon = 'arrow-left',
onSelect = function()
ShowDialogOptions(npcData, npcId)
end)
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
})
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)
end
end)
})
-- Verlassen
table.insert(options, {
title = "🚪 Verlassen",
description = "Dialog beenden",
icon = 'times'
})
local contextId = 'npc_response_' .. npcId .. '_' .. math.random(1000, 9999)
lib.registerContext({
id = contextId,
title = "Was möchtest du antworten?",
options = options
})
lib.showContext(contextId)
end
-- Cleanup