[HELP] Shark

I try to create a shark to attack player when they swim. i try with taskcombatped but it alway flee away but i use TaskPutPedDirectlyIntoMelee it chase player but not attack. i was looking around the fivem native but cant find any solution for this

-- Shark
Citizen.CreateThread(function()

    local model = 0x06C3F072
    RequestModel(model)
	
    while not HasModelLoaded(model) do
        Citizen.Wait(1)
    end
	
	if Config.Animal then
		for _, item in pairs(Config.Shark) do
			local npc = CreatePed(28, model, item.x, item.y, item.z, item.heading, true, false)
			
			FreezeEntityPosition(npc, false)	
			SetEntityInvincible(npc, false)
			SetEntityHeading(npc, item.heading)


			SetBlockingOfNonTemporaryEvents(npc, true)
            sharkCoords = GetEntityCoords(npc, false)
		    plyCoords = GetEntityCoords(GetPlayerPed(-1), false)
			SetPedCombatAttributes(npc,46,true)
			 SetEntityHealth(npc,1000)
			 AddRelationshipGroup(GetHashKey("0x06C3F072"))
			SetPedRelationshipGroupHash(npc, GetHashKey("0x06C3F072"))
		    SetRelationshipBetweenGroups(5,GetHashKey("PLAYER"),GetHashKey("0x06C3F072"))
			SetRelationshipBetweenGroups(5,GetHashKey("0x06C3F072"),GetHashKey("PLAYER"))
			NetworkRegisterEntityAsNetworked(npc)
			SetPedSeeingRange(npc, 100.0)
			SetPedHearingRange(npc, 80.0)
			SetCanAttackFriendly(npc, true, true)
			
            
            dist = Vdist(plyCoords.x, plyCoords.y, plyCoords.z, sharkCoords.x,  sharkCoords.y , sharkCoords.z)
            if dist <= 50.0 then
	        RegisterHatedTargetsAroundPed(npc,100.0)
			TaskCombatHatedTargetsAroundPed(npc,100.0,0)


			TaskPutPedDirectlyIntoMelee(npc, GetPlayerPed(-1), 0.0, -1.0, 0.0, 0)
			
			
			
			end
		end
	end
end)

help!!!

1 Like

any fix ?

Heyo! i found out how to play the gta online animation of a shark attacking you,

its not the shark attacking you, actually Shark peds cant attack at all thats a gta 5 thing…

instead its a synchronised animation i found from some decompiled files, but barely managed to get working,

my problem is that the animation and the camera work, but after 2-3 sec in the animation it just stops and the ped dies,

if you add a FadeOut Screen, it looks kinda nice tho,

and in the code i made him play the “strafe right animation” when going out, which kinda works? but still looks kinda wonky…

if anyone has further ideas be free to test them and write them here!

(the code is messy, this is because ive been testing at 3am please dont judge it)

code:

RegisterCommand('testan2', function(source, args, rawCommand)
    dict = "creatures@shark@move"
    anim = "attack"
    dict2 = "creatures@shark@melee@streamed_core@"
    anim2 = "attack_player"

    RequestAnimDict(dict)
    while not HasAnimDictLoaded(dict) do
        Wait(1)
    end

    RequestAnimDict(dict2)
    while not HasAnimDictLoaded(dict2) do
        Wait(1)
    end

    local ped = PlayerPedId()

    if DoesEntityExist(ped) then
        TaskPlayAnim(ped, dict2, anim2, 8.0, 1.0, -1, 1, 0, 0, 0, 0)

        local model = GetHashKey('a_c_sharktiger')
        RequestModel(model)
        while not HasModelLoaded(model) do
            Wait(1)
        end

        local coords2 = GetEntityCoords(ped)
        local shark = CreatePed(4, model, coords2.x, coords2.y, coords2.z, 0.0, true, true)

        if DoesEntityExist(shark) then
            -- Set the shark's health to a higher value to prevent it from dying
            SetEntityHealth(shark, 200) -- Adjust the value as needed

            local coords = GetEntityCoords(shark)
            local scene = NetworkCreateSynchronisedScene(coords.x, coords.y, coords.z, GetEntityRotation(PlayerPedId()),
                2, true, false,
                1.0, 0.0, 1.0, -1, -1)

            if scene ~= 0 then
                NetworkAddSynchronisedSceneCamera(scene, dict, "attack_cam")
                NetworkAddPedToSynchronisedScene(shark, scene, dict, anim, 8.0, 8.0,
                    0)
                NetworkAddPedToSynchronisedScene(PlayerPedId(), scene, dict, "attack_player", 8.0, 8.0, 0)
                NetworkStartSynchronisedScene(scene)
                TaskPlayAnim(shark, dict2, anim, 8.0, 1.0, -1, 1, 0, 0, 0, 0)
                Wait(0)
                local localScene = NetworkGetLocalSceneFromNetworkId(scene)
                repeat
                    Wait(0)
                    -- print(GetSynchronizedScenePhase(localScene))
                until GetSynchronizedScenePhase(localScene) >= 0.259
                ClearPedTasks(shark)
                TaskPlayAnim(shark, dict, "accelerate_turn_r", 8.0, 1.0, -1, 1, 0, 0, 0, 0)
            end
        end
    end
end)
2 Likes