[HELP] Disable NPC Weapon Firing

Hi, I was wondering, how would I disable an npc ped that I found with World.GetAllPeds() from firing their weapon? I want them to keep aiming but not fire.

Using C# btw.

I tried things like:

Ped[] AllPeds = World.GetAllPeds();

foreach (var p in AllPeds)
{
    if (GetPedType(p.Handle) == 6 || GetPedType(p.Handle) == 27 || IsPedModel(p.Handle, 0xD768B228))
    {
        SetPedShootRate(p.Handle, 0); //This doesn't work at all.
    }
}

But the native SetPedShootRate() doesn’t seem to work.

Setting the ammo to 0 doesn’t even work.

I’ve gotten as far a getting them to shoot every couple seconds with SetPedFiringPattern(p.Handle, 0xE2CA3A71);

Any ideas? Thanks in advance :slightly_smiling_face:

I found this here to see how GTA 5 did it, but it’s a little hard to make sense of.

Any help?

local relationshipTypes = {

    'GANG_1',

    'GANG_2',

    'GANG_9',

    'GANG_10',

    'AMBIENT_GANG_LOST',

    'AMBIENT_GANG_MEXICAN',

    'AMBIENT_GANG_FAMILY',

    'AMBIENT_GANG_BALLAS',

    'AMBIENT_GANG_MARABUNTE',

    'AMBIENT_GANG_CULT',

    'AMBIENT_GANG_SALVA',

    'AMBIENT_GANG_WEICHENG',

    'AMBIENT_GANG_HILLBILLY',

    'DEALER',

    'COP',

    'PRIVATE_SECURITY',

    'SECURITY_GUARD',

    'ARMY',

    'MEDIC',

    'FIREMAN',

    'HATES_PLAYER',

    'NO_RELATIONSHIP',

    'SPECIAL',

    'MISSION2',

    'MISSION3',

    'MISSION4',

    'MISSION5',

    'MISSION6',

    'MISSION7',

    'MISSION8'

}

Citizen.CreateThread(function()

    while true do

        Citizen.Wait(5000)

        for _, group in ipairs(relationshipTypes) do

            SetRelationshipBetweenGroups(1, GetHashKey('PLAYER'), GetHashKey(group)) 

            SetRelationshipBetweenGroups(1, GetHashKey(group), GetHashKey('PLAYER'))

        end

    end

end)

Will this keep the npcs aiming at me?

Yes it will aim but its bit of buggy aiming. But i think this is best solution for you.
And what i mean buggy is like aiming for 3s and then it doesnt aim for 1s and then aiming. Im not sure if its like that but thats what i have seen when used that. Its hard to explain so test it and say if its what u need.

1 Like

Ok, thank you, I’ll give it a try.

1 Like

They still shoot me and the bullets clip through me taking no damage.
The NPCs are cops so relationship groups are probably not gonna work as well on them.

Umm there is ped what it doesnt include so you need to add that ped in that code. But do you want also it doesnt drop ammo? If yes add this to code what i send u.

		RemoveAllPickupsOfType(GetHashKey('PICKUP_WEAPON_CARBINERIFLE'))
		RemoveAllPickupsOfType(GetHashKey('PICKUP_WEAPON_PISTOL'))
		RemoveAllPickupsOfType(GetHashKey('PICKUP_WEAPON_PUMPSHOTGUN'))

I just need them to not be able to fire their weapons, yet still aim at me as they are still aggressive.
And taking ammo away doesn’t seem to work.

Okay, that script doesnt take them ammo away. Just making them not shooting you, if some ped shoot you that mean that ped is not in list. But i believe you dont need that script because its not what u wanted maybe. But if you wanna add peds to that you can find peds from here: https://gist.github.com/ghermans/30b7e578fca2494b20616f8d4725d05c

Relationships don’t seem to effect the cops’ shooting at all. I got SetAmmoInClip() to work, but it needs to be called every frame. The only issue is that they keep reloading their weapon constantly when called every frame. And calling PedSkipNextReloading() will just make them keep shooting regardless of calling the SetAmmoInClip() native.

Still pretty lost. There’s gotta be some way we can disable npc weapon firing, as rockstar found a way to do so with the cops in story mode for being arrested:

UPDATE:
Got it working. The native I used to get it working was SetPoliceIgnorePlayer()
And the cops kept aiming at me and chasing me, but didn’t shoot. Took forever to figure this out lol. I feel stupid considering the fact that is was one simple native that I needed, as I was trying a combination of different ones with if statements and all.

EDIT: This native does not work very well. the cops will not persistently chase you and I cannot get the cops with tasers to shoot at me even with tasks.

2 Likes

Okay, nice to hear!

Works well, but I did notice that the police won’t persistently follow the player. When they can no longer see the player, they stop aiming and walk around like nothing is happening.

So do you want policeped follow you?

Pretty much. I want to make it so the police will keep following you if your wanted and on foot no matter what.

Maybe i can try to help you.
I dont know if this helps, but

ped = "s_m_y_cop_01"
x, y, z = table.unpack(GetEntityCoords(ped, true))
TaskGoToEntity(ped, GetPlayerPed(-1), -1, 1.0, 10.0, 1073741824.0, 0)

If you want you can use distance, i didnt mostly make the code, but there is easy base for you.

local distance = GetDistanceBetweenCoords() --Just need to put ped and playerped coordinates here.
    if distance <= 1 then

    elseif distance > 1 then

end

If you need any help just ask for it! I will help you :slight_smile: ! Hope this helps you.

EDIT: Forgot said that the first code makes cop npc move to you.
With distance code you can easily make that cop stop walking to you when it is close to you. :slight_smile:

What exactly would go in these if statements? Would I use something like ClearPedTasksImmediately()?

You can try like that. Mine dev server host is down atm so i cant make and test my own code but its should be fixed today. So i can help you in forums but cant be sure if the code works.

    if distance <= 3 then
       ClearPedTasks(ped)
    elseif distance > 3 then
       TaskGoToEntity(ped, GetPlayerPed(-1), -1, 1.0, 10.0, 1073741824.0, 0)
end