Stop peds from fleing during gunshot and more

Hello excuse me ! I need help to make a script where during gunshots ped that are around don’t flee and the peds who are attacking with melee weapon doesn’t stop from attacking even if somebody has a gun, i found a lot of tasks to make that but I need help to make that work in a script ! Thank you very much !

I found an attribute that makes them attack no matter what and a script that stops them from fleeing when you pull a weapon out

attribute
  • PED::SET_PED_COMBAT_ATTRIBUTES(peds[i],5,TRUE);PED::SET_PED_COMBAT_ATTRIBUTES(peds[i],46,TRUE);AI::CLEAR_PED_TASKS_IMMEDIATELY(peds[i]);AI::TASK_COMBAT_PED(peds[i],PLAYER::PLAYER_PED_ID(),0,0);PED::SET_PED_KEEP_TASK(peds[i],TRUE);

I doesn’t understand what you really want but I think what you need is This Native TaskSetBlockingOfNonTemporaryEvents - FiveM Natives @ Cfx.re Docs

Oh yes that’s exactly what i need ty very much, any idea how can i apply this on all the peds in world that surrounds the player ?

local peds = GetAllPeds()
for i=1, #peds, 1 do
	local distance = #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(peds[i]))
	
	if distance < 50 and peds[i] ~= PlayerPedId() then
		TaskSetBlockingOfNonTemporaryEvents(peds[i], true)
	end
end

or something like that
what I did here is checking for all peds on server nearby player by 50 GTA units
and executed the native on them that should work try that!

1 Like

Alright thank you very much, gonna try that !

Mhh that doesn’t seems to work, it says that GetAllPeds is a nil value, did i do anything wrong ? Sorry if my questions are a bit dumb haha

late to the party but i think GetAllPeds() is a server side function

GetGamePool(CPed) does the same thing, FYI, and that’s definitely client-side :wink:

well idk, but GetGamePool worked for me in client side but GetAllPeds() didn’t, btw i got that IA thing to work thank you for your help!

1 Like