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)