Update client.lua
This commit is contained in:
		
							parent
							
								
									4222d6cafd
								
							
						
					
					
						commit
						469dda5d47
					
				
					 1 changed files with 133 additions and 89 deletions
				
			
		| 
						 | 
				
			
			@ -17,7 +17,6 @@ local function SpawnNPC(npcId, npcData)
 | 
			
		|||
    SetEntityInvincible(npc, true)
 | 
			
		||||
    SetBlockingOfNonTemporaryEvents(npc, true)
 | 
			
		||||
    
 | 
			
		||||
    -- QB-Target hinzufügen
 | 
			
		||||
    exports['qb-target']:AddTargetEntity(npc, {
 | 
			
		||||
        options = {
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +31,6 @@ local function SpawnNPC(npcId, npcData)
 | 
			
		|||
    })
 | 
			
		||||
    
 | 
			
		||||
    spawnedNPCs[npcId] = npc
 | 
			
		||||
    
 | 
			
		||||
    SetModelAsNoLongerNeeded(model)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -43,110 +41,156 @@ CreateThread(function()
 | 
			
		|||
    end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Rekursive Funktion zum Erstellen der Dialog-Optionen
 | 
			
		||||
local function CreateDialogOptions(options, npcId, parentId)
 | 
			
		||||
    local contextOptions = {}
 | 
			
		||||
    
 | 
			
		||||
    for i, option in ipairs(options) do
 | 
			
		||||
        local optionData = {
 | 
			
		||||
            title = option.title,
 | 
			
		||||
            description = option.description,
 | 
			
		||||
            icon = option.icon,
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if option.info then
 | 
			
		||||
            -- Direkte Info anzeigen
 | 
			
		||||
            optionData.onSelect = function()
 | 
			
		||||
                lib.alertDialog({
 | 
			
		||||
                    header = option.title,
 | 
			
		||||
                    content = option.info,
 | 
			
		||||
                    centered = true,
 | 
			
		||||
                    cancel = true,
 | 
			
		||||
                    labels = {
 | 
			
		||||
                        cancel = 'Zurück'
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            end
 | 
			
		||||
        elseif option.response then
 | 
			
		||||
            -- Weiteres Dialog-Level
 | 
			
		||||
            optionData.onSelect = function()
 | 
			
		||||
                local contextId = 'npc_dialog_' .. npcId .. '_' .. i .. '_' .. (parentId or 'main')
 | 
			
		||||
                local responseOptions = CreateDialogOptions(option.response.options, npcId, contextId)
 | 
			
		||||
                
 | 
			
		||||
                -- Zurück-Option hinzufügen
 | 
			
		||||
                table.insert(responseOptions, {
 | 
			
		||||
                    title = "← Zurück",
 | 
			
		||||
                    description = "Zum vorherigen Dialog",
 | 
			
		||||
                    icon = 'arrow-left',
 | 
			
		||||
                    onSelect = function()
 | 
			
		||||
                        if parentId then
 | 
			
		||||
                            lib.showContext(parentId)
 | 
			
		||||
                        else
 | 
			
		||||
                            lib.showContext('npc_dialog_' .. npcId)
 | 
			
		||||
                        end
 | 
			
		||||
                    end
 | 
			
		||||
                })
 | 
			
		||||
                
 | 
			
		||||
                -- Erste Option ist immer die NPC-Antwort (nur Text)
 | 
			
		||||
                table.insert(responseOptions, 1, {
 | 
			
		||||
                    title = "💬 " .. option.response.title,
 | 
			
		||||
                    description = option.response.description,
 | 
			
		||||
                    icon = 'comment',
 | 
			
		||||
                    disabled = true -- Macht die Option nicht klickbar, zeigt aber den Text
 | 
			
		||||
                })
 | 
			
		||||
                
 | 
			
		||||
                lib.registerContext({
 | 
			
		||||
                    id = contextId,
 | 
			
		||||
                    title = option.response.title,
 | 
			
		||||
                    options = responseOptions
 | 
			
		||||
                })
 | 
			
		||||
                
 | 
			
		||||
                lib.showContext(contextId)
 | 
			
		||||
            end
 | 
			
		||||
        end
 | 
			
		||||
        
 | 
			
		||||
        table.insert(contextOptions, optionData)
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    return contextOptions
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Dialog öffnen
 | 
			
		||||
-- 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
 | 
			
		||||
    
 | 
			
		||||
    local options = CreateDialogOptions(npcData.dialog.options, npcId)
 | 
			
		||||
    -- NPC-Begrüßung als Pop-up
 | 
			
		||||
    lib.alertDialog({
 | 
			
		||||
        header = npcData.dialog.title,
 | 
			
		||||
        content = npcData.dialog.description,
 | 
			
		||||
        centered = true,
 | 
			
		||||
        cancel = false,
 | 
			
		||||
        labels = {
 | 
			
		||||
            confirm = 'Antworten'
 | 
			
		||||
        }
 | 
			
		||||
    }):next(function(confirmed)
 | 
			
		||||
        if confirmed then
 | 
			
		||||
            ShowDialogOptions(npcData, npcId)
 | 
			
		||||
        end
 | 
			
		||||
    end)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Dialog-Optionen anzeigen (Context-Menü)
 | 
			
		||||
function ShowDialogOptions(npcData, npcId)
 | 
			
		||||
    local options = {}
 | 
			
		||||
    
 | 
			
		||||
    -- Erste Option ist die NPC-Begrüßung (nur Text)
 | 
			
		||||
    table.insert(options, 1, {
 | 
			
		||||
        title = "💬 " .. npcData.dialog.title,
 | 
			
		||||
        description = npcData.dialog.description,
 | 
			
		||||
        icon = 'comment',
 | 
			
		||||
        disabled = true -- Zeigt nur den Text, nicht klickbar
 | 
			
		||||
    })
 | 
			
		||||
    for i, option in ipairs(npcData.dialog.options) do
 | 
			
		||||
        table.insert(options, {
 | 
			
		||||
            title = option.title,
 | 
			
		||||
            description = option.description,
 | 
			
		||||
            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'
 | 
			
		||||
                        }
 | 
			
		||||
                    }):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)
 | 
			
		||||
                end
 | 
			
		||||
            end
 | 
			
		||||
        })
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Verlassen Option hinzufügen
 | 
			
		||||
    table.insert(options, {
 | 
			
		||||
        title = "🚪 Verlassen",
 | 
			
		||||
        description = "Dialog beenden",
 | 
			
		||||
        icon = 'times',
 | 
			
		||||
        onSelect = function()
 | 
			
		||||
            -- Dialog schließt sich automatisch
 | 
			
		||||
        end
 | 
			
		||||
        icon = 'times'
 | 
			
		||||
    })
 | 
			
		||||
    
 | 
			
		||||
    lib.registerContext({
 | 
			
		||||
        id = 'npc_dialog_' .. npcId,
 | 
			
		||||
        title = npcData.name,
 | 
			
		||||
        id = 'npc_options_' .. npcId,
 | 
			
		||||
        title = "Was möchtest du sagen?",
 | 
			
		||||
        options = options
 | 
			
		||||
    })
 | 
			
		||||
    
 | 
			
		||||
    lib.showContext('npc_dialog_' .. npcId)
 | 
			
		||||
end)
 | 
			
		||||
    lib.showContext('npc_options_' .. npcId)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Cleanup beim Resource Stop
 | 
			
		||||
-- 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)
 | 
			
		||||
                        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)
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
-- Cleanup
 | 
			
		||||
AddEventHandler('onResourceStop', function(resourceName)
 | 
			
		||||
    if GetCurrentResourceName() ~= resourceName then return end
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue