I want to make a spawned npc attack players

here is the code i used to make a spawn npc…

	ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
				if skin.sex == 0 then
					TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_male)

local hash = GetHashKey( "mp_m_shopkeep_01" )
  while not HasModelLoaded( hash ) do
    RequestModel( hash )
    Wait(20)
  end
  local pos =  GetEntityCoords(GetPlayerPed(-1))
  local ped =  CreatePed(4, hash, 568.147, -2326.42, 5.91035, 0.0, true, true)
  SetBlockingOfNonTemporaryEvents(ped, true)
  SetPedCombatAttributes(ped, 46, true)
  SetPedFleeAttributes(ped, 0, 0)

i want to give it a gun and make him attack players to make him an enemy…
is there some guide to know what the number means like:

SetPedCombatAttributes(ped, 46, true) what 46 means?

https://runtime.fivem.net/doc/natives/#_0x9F7794730795E019

1 Like

tks for that link its helping me a lot but here is what i use to make the npc attack always…

SetPedCombatAttributes(ped, 46, true)
SetPedFleeAttributes(ped, 0, 0)
SetPedAsEnemy(ped,true)

the ped attacks me only if i push him and make him fall…
i must piss him off… how can i having him attack all the time… agressive ped?

https://runtime.fivem.net/doc/natives/#_0xBF25EB89375A37AD

oh i see thanks a lot ill test those lines

1 Like

i used those line… but doesnt work…

SetPedCombatAttributes(ped, 46, true)
SetPedFleeAttributes(ped, 0, 0)
SetPedAsEnemy(ped,true)
SetPedMoney(ped, 50)
SetPedMaxHealth(ped, 900)
SetPedAlertness(ped, 3)
SetPedCombatRange(ped, 0)
SetPedConfigFlag(ped, 224, true)
SetPedCombatMovement(ped, 2)

the npc attack me when i use a weapon…
but how to make him attack me when he see me?

You are not using my linked native.

Setpedrelationship.

yes i am using it… i tried it too…

here i wrote:

SetRelationshipBetweenGroups(5, Hash group1, Hash group2)

what do i put for hashgroup1 and 2 ?

1 Like

Found some examples in this forum. You should try the search bar tho.

this is what i tried… but the npc attacxk me only when i provoke him…

local hash = GetHashKey( "mp_m_shopkeep_01" )
  while not HasModelLoaded( hash ) do
    RequestModel( hash )
    Wait(20)
  end
  local pos =  GetEntityCoords(GetPlayerPed(-1))
  local ped =  CreatePed(4, hash, 568.147, -2326.42, 5.91035, 0.0, true, true)
  SetPedCombatAttributes(ped, 46, true)
  SetPedFleeAttributes(ped, 0, 0)
  SetPedAsEnemy(ped,true)
  SetPedMoney(ped, 50)
  SetPedMaxHealth(ped, 900)
  SetPedAlertness(ped, 3)
  SetPedCombatRange(ped, 0)
  SetPedConfigFlag(ped, 224, true)
  SetPedCombatMovement(ped, 2)
SetRelationshipBetweenGroups(5, GetHashKey("mp_m_shopkeep_01"), GetHashKey("PLAYER")) 

Some people found how to manage this, I can’t remember the name. I was a little team, they did a little mission where policeman were attacking you, and you need to protect the transport vehicle. Maybe someone here is able to help us find out what was it?

is it that complicated to spawn an npc with agressive behaviour?
and when he see the player… he attacks…

i tried the chnage behaviour settings but stilli not attacking me…

add this
SetPedRelationshipGroupHash(ped, GetHashKey(“HATES_PLAYER”))