[Request] How to create Aggressive NPCs

Hello community,

I would like to know how to create NPC (gang type) that are aggressive and can attack the player who is close.

  • This idea occurred to me when trying to make the points of RP drugs more difficult.

Any way to create such Script?

// 0xF166E48407BAC484 0xCB0D8932
// TaskCombatPed
void TASK_COMBAT_PED(Ped ped, Ped targetPed, int p2, int p3);
Makes the specified ped attack the target ped.  
p2 should be 0  
p3 should be 16
6 Likes

Thanks @KrizFrost

I do not understand much about what to do.
I would need a Script that I can create:

  • NPC: Gang (Ballas)
  • Editable respawn zone
  • Armed and Attack in a range of vision to the Player.
2 Likes

I dont know what your asking here, Thats how you set the Ped to attack, as you requested if your asking for a entire script for you I mean every script is going to work just read it, I mean if you use the natives for FiveM they can help you… or you can make it yourself, If you don’t plan on making it yourself then should specify your looking for someone to make you the script instead of how to do it I highly recommend looking at the FiveM Natives and look up how lua code.
But to give you some pretext that will set whatever “Ped” is so
local Ped = (ThisisWhereYou'dSpecify)
then You’d specify the targetPed (The ped usually is the NPC targetPed would be the closest player)
TaskCombatPed(Ped, targetPed, 0, 16)

2 Likes

Excuse me. i try taskcombatped for a shark but it not work. it alway swim away. do you know how to fix that ?

-- 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
3 Likes

@hichay Thanks to some lines that I took from your codes, I managed to get the NPCs to attack me but they also do it among them, how would we do it so that they do not attack each other?

  • As for your problem, when you leave it Freeze off, it immediately goes away but it stays with me in only one place.

if i try to freeze in position. they will not swim or attack anyone.

for your problem you should try

SetRelationshipBetweenGroups

set SetRelationshipBetweenGroups(3,GetHashKey("0xC26D562A"),GetHashKey("0xC26D562A"))
i think it will work

1 Like

Hi Thank you hichay for your code, it is so useful!

1 Like

hey can you please share the script’s link :slight_smile:

3 Likes

It’s not a script. it just a code like above. copy and paste it to somewhere in your resource. edit it by yourself

2 Likes

hey was jsut wondering if you where able to make the shark attack

1 Like

How would I make the NPC spawn at the coordinates I want?