1
0
Fork 0
forked from Simnation/Main

Update client.lua

This commit is contained in:
Nordi98 2025-07-20 21:09:58 +02:00
parent 469dda5d47
commit 1b2a90a4bd

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 -- NPC Spawn Function (gleich wie oben)
local function SpawnNPC(npcId, npcData) local function SpawnNPC(npcId, npcData)
local model = GetHashKey(npcData.model) local model = GetHashKey(npcData.model)
@ -41,13 +41,13 @@ CreateThread(function()
end end
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) 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
-- NPC-Begrüßung als Pop-up -- Zuerst NPC-Text als Alert anzeigen
lib.alertDialog({ lib.alertDialog({
header = npcData.dialog.title, header = npcData.dialog.title,
content = npcData.dialog.description, content = npcData.dialog.description,
@ -58,12 +58,13 @@ RegisterNetEvent('npc-dialog:client:openDialog', function(data)
} }
}):next(function(confirmed) }):next(function(confirmed)
if confirmed then if confirmed then
-- Dann Dialog-Optionen anzeigen
ShowDialogOptions(npcData, npcId) ShowDialogOptions(npcData, npcId)
end end
end) end)
end) end)
-- Dialog-Optionen anzeigen (Context-Menü) -- Dialog-Optionen anzeigen
function ShowDialogOptions(npcData, npcId) function ShowDialogOptions(npcData, npcId)
local options = {} local options = {}
@ -74,33 +75,17 @@ 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
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 zum Gespräch' cancel = 'Zurück'
} }
}):next(function() })
ShowDialogOptions(npcData, npcId)
end)
elseif option.response then elseif option.response then
-- NPC-Antwort als Pop-up, dann weiter ShowResponse(option.response, npcData, npcId)
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)
end end
end end
}) })
@ -114,17 +99,25 @@ function ShowDialogOptions(npcData, npcId)
lib.registerContext({ lib.registerContext({
id = 'npc_options_' .. npcId, id = 'npc_options_' .. npcId,
title = "Was möchtest du sagen?", title = "Antworten:",
options = options options = options
}) })
lib.showContext('npc_options_' .. npcId) lib.showContext('npc_options_' .. npcId)
end end
-- Response-Optionen anzeigen -- Response anzeigen
function ShowResponseOptions(response, npcData, npcId) function ShowResponse(response, npcData, npcId)
if not response.options then return end 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 = {} local options = {}
for i, option in ipairs(response.options) do for i, option in ipairs(response.options) do
@ -134,37 +127,22 @@ function ShowResponseOptions(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
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 = 'Gespräch beenden' cancel = 'Schließen'
} }
}) })
elseif option.response then elseif option.response then
-- Weitere NPC-Antwort als Pop-up ShowResponse(option.response, npcData, npcId)
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)
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",
@ -174,21 +152,16 @@ function ShowResponseOptions(response, npcData, npcId)
end end
}) })
-- Verlassen
table.insert(options, {
title = "🚪 Verlassen",
description = "Dialog beenden",
icon = 'times'
})
lib.registerContext({ lib.registerContext({
id = 'npc_response_' .. npcId .. '_' .. math.random(1000, 9999), id = 'npc_response_' .. npcId .. '_' .. math.random(1000, 9999),
title = "Was möchtest du antworten?", title = "Antworten:",
options = options options = options
}) })
lib.showContext('npc_response_' .. npcId .. '_' .. math.random(1000, 9999)) lib.showContext('npc_response_' .. npcId .. '_' .. math.random(1000, 9999))
end end
end)
end
-- Cleanup -- Cleanup
AddEventHandler('onResourceStop', function(resourceName) AddEventHandler('onResourceStop', function(resourceName)