Ped owner changes when being shot and breaks its behaviour

Hello,

I am having an issue where (what I think is the problem here) if I spawn ped or spawn ped via server where I am the owner, and if other player starts shooting that ped, owner changes and ped appears dead or ragdolls and then slides in that state. I tried every possible flag, disabled ragdol, disabled network id migration but still no progress. It seems that ped loses its flags and disabled states when changing owners or something.

Here is the code that can be used to reproduce this.

RegisterCommand("test_ped", function()
    local ped = PlayerPedId()
    local coords = GetEntityCoords(ped)

    local new_data = {
        model = `U_M_Y_Zombie_01`,
        zombie = 0,
        spawn_coords = vector4(coords.x, coords.y, coords.z, GetEntityHeading(ped)),
        times_killed = 1,
    }

    RequestModel(`U_M_Y_Zombie_01`)
    while not HasModelLoaded(`U_M_Y_Zombie_01`) do print("Waiting for model to load") Wait(0) end

    new_data.zombie = CreatePed(26, `U_M_Y_Zombie_01`, new_data.spawn_coords.x, new_data.spawn_coords.y, new_data.spawn_coords.z, new_data.spawn_coords.w, true, true)
    while not DoesEntityExist(new_data.zombie) do print("Waiting for ped to spawn") Wait(0) end

    new_data.network_id = PedToNet(new_data.zombie)
    while not NetworkDoesNetworkIdExist(new_data.network_id) do print("Waiting for network id to exist") Wait(0) end

    SetNetworkIdCanMigrate(new_data.network_id, false)
    SetEntityInvincible(new_data.zombie, false)
    SetEntityMaxHealth(new_data.zombie, 10000)
    SetPedMaxHealth(new_data.zombie, 10000)
    SetEntityHealth(new_data.zombie, 10000)
    SetPedArmour(new_data.zombie, 10000)
    SetPedSuffersCriticalHits(new_data.zombie, false)
    SetPedDiesWhenInjured(new_data.zombie, false)
    SetPedCanRagdoll(new_data.zombie, false)
    SetPedKeepTask(new_data.zombie, true)
    SetBlockingOfNonTemporaryEvents(new_data.zombie, true)
    SetPedCanRagdollFromPlayerImpact(new_data.zombie, false)
    SetRagdollBlockingFlags(new_data.zombie, 2)
    SetRagdollBlockingFlags(new_data.zombie, 1)
    SetRagdollBlockingFlags(new_data.zombie, 4)

    TaskCombatPed(new_data.zombie, ped, 0, 16)

    local last_owner = 0
    while DoesEntityExist(new_data.zombie) do
        local owner = GetPlayerServerId(NetworkGetEntityOwner(new_data.zombie))
        if owner ~= last_owner then
            last_owner = owner
            new_data.owner = owner

            print("Owner changed to: " .. owner, "Can ped ragdoll?", CanPedRagdoll(new_data.zombie))
        end
        Wait(0)
    end
end, false)

And here is the video

Is this intended? If yes how can I go around this?

Thanks!

Bump.

I also create github issue - Networked peds ragdoll and play injured animation when migrated from owner/owner changes when shot · Issue #2986 · citizenfx/fivem · GitHub

Anyone has any idea how to fix this? I don’t think this is expected behaviour