[Help] Peds

-- Shark
Citizen.CreateThread(function()
    RequestModel(GetHashKey("a_c_sharktiger"))
	
    while not HasModelLoaded(GetHashKey("a_c_sharktiger")) do
        Wait(1)
    end
	
	if Config.EnableNightclubs then
		for _, item in pairs(Config.Shark) do
			local npc = CreatePed(28, 0x06C3F072, item.x, item.y, item.z, item.heading, false, false)
			
			FreezeEntityPosition(npc, false)	
			SetEntityInvincible(npc, false)
				
	
		end
	end
end)

i try to create a shark. it working for spawn a shark. but i got a problem when try to make them attack player. i try with TaskWanderStandard but it only swim around. even with TaskCombatHatedTargetsAroundPed still not working. any help?

any solution ?

just a quick search of the Native gave me this which I think could work for what you want. TaskCombatPed

Hopefully this helps you get it sorted out.

i dont know how to set the target ped it player. and when i use this task. ped not swim working or do anything. just stand at the spawn location

Once a PED is spawned it will stand there and do nothing until you give it orders. If you want to make it attack the person that is swimming near it… in the client script you would need to use the function i mentioned something like

TaskCombatPed(npc, GetPlayerPed(-1), 0, 16)

This should make the shark attack the client… but you will need to but some checks in there as well… as in how far away in the client from the shark so its not trying to attack every client that gets in render distance of the shark.

So something like

sharkCoords = GetEntityCoords(npc, false)
plyCoords = GetEntityCoords(GetPlayerPed(-1), false)
dist = Vdist(plyCoords.x, plyCoords.y, plyCoords.z, npc.x,  npc.y , npc.z)
if dist <= 2.0 then
     TaskCombatPed(npc, GetPlayerPed(-1), 0, 16)
end

That should make the shark attack any clients that get within 2.0m but without the entire code im just going from memory this should point you in the right direction.

SpikE

1 Like

thank for help. let me check the code

excuse me can i ask a question about TaskCombatHatedTargetsAroundPed
is this work ?

Excuse me. i try to use taskcombatped but it not work. it alway swim away

That would have been my best guess - hopefully someone else on here will have a bit more knowledge and be able to help you out.

SpikE

it really hard. i try many task but it alway swim away.

-- Shark
Citizen.CreateThread(function()

    local model = 0x06C3F072
    RequestModel(model)
	
    while not HasModelLoaded(model) do
        Citizen.Wait(10)
    end
	
	if Config.EnableNightclubs then
		for _, item in pairs(Config.Shark) do
			local npc = CreatePed(4, model, item.x, item.y, item.z, item.heading, false, false)
			FreezeEntityPosition(npc, false)	
			SetEntityInvincible(npc, false)
            sharkCoords = GetEntityCoords(npc, false)
            plyCoords = GetEntityCoords(GetPlayerPed(-1), false)
            dist = Vdist(plyCoords.x, plyCoords.y, plyCoords.z, sharkCoords.x,  sharkCoords.y , sharkCoords.z)
            if dist <= 20.0 then
			SetPedSeeingRange(npc, 100.0)
			SetPedHearingRange(npc, 80.0)
			SetPedCombatAttributes(npc, 46, 1)
			SetPedFleeAttributes(npc, 0, 0)
			SetPedCombatRange(npc,2)
			SetPedRelationshipGroupHash(npc, GetHashKey(0x06C3F072))
			SetPedDiesInWater(npc, false)
			SetRelationshipBetweenGroups(5,GetHashKey("PLAYER"),GetHashKey("0x06C3F072"))
			SetRelationshipBetweenGroups(5,GetHashKey("0x06C3F072"),GetHashKey("PLAYER"))
            TaskCombatPed(npc, GetPlayerPed(-1), 0, 16)
			
			
			end
		end
	end
end)

i try to create a shark to attack player. but it not work. do you know how to fix it ?

Anyone have solution for this?