Ped

Can someone help me with the cutscene and explain why the first player isn’t visible?

local spawnedProp = nil
local npc = nil
local npcCoords = vector4(1773.1241, 3654.7354, 34.3807, 347.4246)
local npcModel = "s_m_m_migrant_01"
local cutsceneCoords = vector4(1773.1241, 3654.7354, 34.3807, 347.4246)

-- Prop spawn Event
RegisterNetEvent('koffer:clientSpawn')
AddEventHandler('koffer:clientSpawn', function()
    local playerPed = PlayerPedId()
    local coords = GetEntityCoords(playerPed)
    local forward = GetEntityForwardVector(playerPed)

    local propHash = GetHashKey("hei_prop_hei_drug_case")
    RequestModel(propHash)
    local waitCounter = 0
    while not HasModelLoaded(propHash) do
        Wait(100)
        waitCounter = waitCounter + 1
        if waitCounter > 100 then return end
    end

    local spawnCoords = coords + forward * 1.0
    spawnedProp = CreateObject(propHash, spawnCoords.x, spawnCoords.y, spawnCoords.z, true, true, true)
    PlaceObjectOnGroundProperly(spawnedProp)
    FreezeEntityPosition(spawnedProp, true)
    SetEntityHeading(spawnedProp, (GetEntityHeading(playerPed) + 360.0) % 360)

    exports.ox_target:addLocalEntity(spawnedProp, {{
        name = 'koffer_interact',
        icon = 'fas fa-box',
        label = 'Koffer durchsuchen',
        onSelect = function(entity)
            searchKoffer()
        end
    }})
end)

-- Animation + Prop löschen
function searchKoffer()
    local playerPed = PlayerPedId()
    local animDict = "amb@prop_human_bum_bin@base"
    local animName = "base"

    RequestAnimDict(animDict)
    local waitCounter = 0
    while not HasAnimDictLoaded(animDict) do
        Wait(100)
        waitCounter = waitCounter + 1
        if waitCounter > 100 then return end
    end

    TaskPlayAnim(playerPed, animDict, animName, 8.0, -8.0, 5000, 1, 0, false, false, false)
    Wait(5000)
    ClearPedTasks(playerPed)
    TriggerServerEvent('koffer:giveCoke')

    if spawnedProp then
        DeleteObject(spawnedProp)
        spawnedProp = nil
    end
end

-- NPC Setup
CreateThread(function()
    RequestModel(GetHashKey(npcModel))
    local waitCounter = 0
    while not HasModelLoaded(GetHashKey(npcModel)) do
        Wait(100)
        waitCounter = waitCounter + 1
        if waitCounter > 100 then return end
    end

    npc = CreatePed(4, GetHashKey(npcModel), npcCoords.x, npcCoords.y, npcCoords.z, npcCoords.w, false, true)
    SetEntityInvincible(npc, true)
    SetBlockingOfNonTemporaryEvents(npc, true)
    FreezeEntityPosition(npc, true)

    exports.ox_target:addLocalEntity(npc, {{
        name = 'sell_coke',
        icon = 'fas fa-hand-holding',
        label = 'Ware abgeben',
        onSelect = function(entity)
            TriggerEvent('koffer:playCutsceneWithClones', true) -- true = optional change
        end
    }})
end)

-- Cutscene mit Dummy-Klone und Spieler
RegisterNetEvent('koffer:playCutsceneWithClones')
AddEventHandler('koffer:playCutsceneWithClones', function(change)
    local playerPed = PlayerPedId()
    local pedModel = GetEntityModel(playerPed)

    -- Cutscene laden
    local cutsceneName = "hs3f_all_drp2"
    RequestCutscene(cutsceneName, 8)
    while not HasCutsceneLoaded(cutsceneName) do Wait(0) end

    -- Spieler unsichtbar machen
--SetEntityVisible(playerPed, false, false)
    SetEntityCollision(playerPed, true, true)
    NetworkSetEntityInvisibleToNetwork(playerPed, false)

    -- Dummy-Klone erstellen
    local clones = {}
    for i = 1,5 do
        local clone = ClonePedEx(playerPed, 0.0, true, true, 1)
        SetBlockingOfNonTemporaryEvents(clone, true)
        SetEntityVisible(clone, true, true)
        SetEntityInvincible(clone, true)
        SetEntityCollision(clone, false, false)
        FreezeEntityPosition(clone, true)
        SetPedHelmet(clone, false)
        RemovePedHelmet(clone, true)
        table.insert(clones, clone)
    end

    -- Spieler und Klone für Cutscene registrieren
    if change then
        SetCutsceneEntityStreamingFlags('MP_2', 0, 1)
        RegisterEntityForCutscene(playerPed, 'MP_2', 0, pedModel, 64)

        SetCutsceneEntityStreamingFlags('MP_1', 0, 1)
        RegisterEntityForCutscene(clones[2], 'MP_1', 0, pedModel, 64)
    else
        SetCutsceneEntityStreamingFlags('MP_1', 0, 1)
        RegisterEntityForCutscene(playerPed, 'MP_1', 0, pedModel, 64)

        SetCutsceneEntityStreamingFlags('MP_2', 0, 1)
        RegisterEntityForCutscene(clones[2], 'MP_2', 0, pedModel, 64)
    end

    -- restliche Klone registrieren
    for i = 3,5 do
        local name = 'MP_'..i
        SetCutsceneEntityStreamingFlags(name, 0, 1)
        RegisterEntityForCutscene(clones[i], name, 0, pedModel, 64)
    end

    -- Kleidung und Props des Spielers übernehmen
    for i = 0, 7 do
        local drawable = GetPedDrawableVariation(playerPed, i)
        local texture = GetPedTextureVariation(playerPed, i)
        SetCutscenePedComponentVariation('MP_2', i, drawable, texture, 0)
    end
    for i = 0, 7 do
        local propIndex = GetPedPropIndex(playerPed, i)
        local propTexture = GetPedPropTextureIndex(playerPed, i)
        if propIndex ~= -1 then
            SetCutscenePedPropVariation('MP_2', i, propIndex, propTexture, 0)
        end
    end

    -- Cutscene an festen Koordinaten starten
    StartCutsceneAtCoords(vector3(cutsceneCoords.x, cutsceneCoords.y, cutsceneCoords.z), cutsceneCoords.w)

    Wait(10)
    -- Optional: erster Klon auf Spieler synchronisieren
    ClonePedToTarget(clones[1], playerPed)
    Wait(10)

    -- Klone löschen
    for _, clone in ipairs(clones) do
        DeleteEntity(clone)
    end

    Wait(50)
    DoScreenFadeIn(250)

    -- Spieler wieder sichtbar machen
    SetEntityVisible(playerPed, true, false)
    SetEntityCollision(playerPed, true, true)
    NetworkSetEntityInvisibleToNetwork(playerPed, false)
end)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.