[Help] Disable shooting doesn't work?

Hello. My problem is that when I disable moving right/left, up/down it works and it blocks player movement but when I put the disables for shooting then it doesn’t work and player is still able to shoot.

-- Handcuff
Citizen.CreateThread(function()
  while true do
    Wait(0)
    if IsHandcuffed then
      DisableControlAction(0, 142, true) -- MeleeAttackAlternate
      --DisableControlAction(0, 30,  true) -- MoveLeftRight <- THIS WORKS IF UNCOMMENTED
      --DisableControlAction(0, 31,  true) -- MoveUpDown <- THIS WORKS IF UNCOMMENTED
      DisableControlAction(0, 24,  true) -- Shoot 
      DisableControlAction(0, 92,  true) -- Shoot in car
      DisableControlAction(0, 75,  true) -- Leave Vehicle
    end
  end
end)

This is some code from my AOP script.

if IsControlPressed(0, 106) then
    ShowInfo("~r~Peacetime is enabled. ~n~~s~You can not shoot.")
end
SetPlayerCanDoDriveBy(player, false)
DisablePlayerFiring(player, true)
DisableControlAction(0, 140) -- Melee R

Source: https://github.com/FAXES/Area-of-Patrol/blob/master/client.lua#L150

1 Like

Thanks, I’ll test that when I will have a chance :slight_smile:

There are more actions you must disable to disable shooting.

disablePlayerFiring = function()
	DisableControlAction(0,24) -- INPUT_ATTACK
	DisableControlAction(0,69) -- INPUT_VEH_ATTACK
	DisableControlAction(0,70) -- INPUT_VEH_ATTACK2
	DisableControlAction(0,92) -- INPUT_VEH_PASSENGER_ATTACK
	DisableControlAction(0,114) -- INPUT_VEH_FLY_ATTACK
	DisableControlAction(0,257) -- INPUT_ATTACK2
	DisableControlAction(0,331) -- INPUT_VEH_FLY_ATTACK2
end

Do you know if there is a way to disable it for npcs?
(Deleted my old post and created a topic for it)

use this native: https://runtime.fivem.net/doc/natives/?_0x8EEDA153AD141BA4

2 Likes

If you don’t know off the top of your head it’s fine I’ll do tests later, but is that function at all networked? Or does it only affect the AI of peds you own? Would you have to call that on every client for each player id?

Sorry I should’ve explained more. What I wanted to do was make it so the npcs (cops) don’t fire their weapons, but aim them at you and chase you still. However, this native may work along with SetPoliceIgnorePlayer(), but it is a little glitchy as the cops sometimes stop what they’re doing and continue walking like nothing is happening. They will sometimes even drive right past you in their cop cars when your wanted.

I have a video example of what is happening with the police:

I also set a 50/50 chance that the cops can have a pistol or a taser. I want the cops that have tasers to continue shooting at the player, but I try to do that with TaskShootAtEntity() in an if statement, and it doesn’t work because the SetPoliceIgnorePlayer() overrides it and the cops can’t shoot. It would be nice if I can set a specific ped to ignore the player, because it would work as I am using a foreach loop on World.GetAllPeds().
Using C# btw.

Hope everything is explained properly and thanks in advance :slightly_smiling_face:

since you have a “table” with police officers’ peds, you can create something related to Relationships, and manage it separately for each group.

Ok I see what you mean. But when I try to Create a new Relationship group with World.AddRelationshipGroup("COPS_WITH_PISTOLS") and use it in SetRelationshipBetweenGroups(), it says " cannot convert from ‘CitizenFX.Core.RelationshipGroup’ to ‘uint’ "
How would I convert that?

I don’t know C #, in Lua I never had this problem.
1st you need to create the group: https://runtime.fivem.net/doc/natives/?_0xF372BC22FCB88606

AddRelationshipGroup("COPS_WITH_PISTOLS")

2nd you define the type of relationship: https://runtime.fivem.net/doc/natives/?_0xBF25EB89375A37AD

SetRelationshipBetweenGroups(RELATIONTYPE, GetHashKey("COPS_WITH_PISTOLS"), GetHashKey("PLAYER"))

3rd You Add the Relationship to the Ped: https://runtime.fivem.net/doc/natives/?_0xC80A74AC829DDD92

SetPedRelationshipGroupHash(ped, GetHashKey("COPS_WITH_PISTOLS"))

Ok this does work when the cops first pull up, but the relationship seems to change and they start shooting after you bump them or provoke them. I even have it set to 0 (Companion).