forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
469dda5d47
commit
1b2a90a4bd
1 changed files with 61 additions and 88 deletions
|
@ -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,17 +99,25 @@ 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
|
||||
|
||||
-- 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
|
||||
|
@ -134,37 +127,22 @@ function ShowResponseOptions(response, npcData, npcId)
|
|||
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'
|
||||
cancel = 'Schließen'
|
||||
}
|
||||
})
|
||||
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)
|
||||
end
|
||||
end)
|
||||
ShowResponse(option.response, npcData, npcId)
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
-- Zurück zum Hauptgespräch
|
||||
table.insert(options, {
|
||||
title = "← Zurück",
|
||||
description = "Zurück zu den Hauptoptionen",
|
||||
|
@ -174,21 +152,16 @@ function ShowResponseOptions(response, npcData, npcId)
|
|||
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?",
|
||||
title = "Antworten:",
|
||||
options = options
|
||||
})
|
||||
|
||||
lib.showContext('npc_response_' .. npcId .. '_' .. math.random(1000, 9999))
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Cleanup
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue