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,30 +41,31 @@ 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()
header = npcData.dialog.title, local result = lib.alertDialog({
content = npcData.dialog.description, header = npcData.dialog.title,
centered = true, content = npcData.dialog.description,
cancel = false, centered = true,
labels = { cancel = false,
confirm = 'Antworten' labels = {
} 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
lib.alertDialog({ -- Direkte Info als Pop-up
header = option.title, CreateThread(function()
content = option.info, lib.alertDialog({
centered = true, header = option.title,
cancel = true, content = option.info,
labels = { centered = true,
cancel = 'Zurück' cancel = true,
} labels = {
}) 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,68 +120,85 @@ 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, local options = {}
centered = true,
cancel = false, for i, option in ipairs(response.options) do
labels = { table.insert(options, {
confirm = 'Weiter' title = option.title,
} description = option.description,
}):next(function(confirmed) icon = option.icon,
if confirmed and response.options then onSelect = function()
local options = {} if option.info then
-- Info als Pop-up
for i, option in ipairs(response.options) do CreateThread(function()
table.insert(options, { lib.alertDialog({
title = option.title, header = option.title,
description = option.description, content = option.info,
icon = option.icon, centered = true,
onSelect = function() cancel = true,
if option.info then labels = {
lib.alertDialog({ cancel = 'Gespräch beenden'
header = option.title, }
content = option.info, })
centered = true, end)
cancel = true, elseif option.response then
labels = { -- Weitere NPC-Antwort als Pop-up
cancel = 'Schließen' CreateThread(function()
} local result = lib.alertDialog({
}) header = option.response.title,
elseif option.response then content = option.response.description,
ShowResponse(option.response, npcData, npcId) centered = true,
cancel = false,
labels = {
confirm = 'Weiter'
}
})
if result == 'confirm' then
ShowResponseOptions(option.response, npcData, npcId)
end end
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
}) end
})
lib.registerContext({ end
id = 'npc_response_' .. npcId .. '_' .. math.random(1000, 9999),
title = "Antworten:", -- Zurück zum Hauptgespräch
options = options table.insert(options, {
}) title = "← Zurück",
description = "Zurück zu den Hauptoptionen",
lib.showContext('npc_response_' .. npcId .. '_' .. math.random(1000, 9999)) icon = 'arrow-left',
onSelect = function()
ShowDialogOptions(npcData, npcId)
end 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 end
-- Cleanup -- Cleanup