[Help] with LUA script - have NPCs "ignore you" (not panic/flee) when you aim with a radar gun

Hello everyone,
I need some help with a LUA script. I have been trying to make a few changes to a radargun script by TerbSEC, since I found that it had two issues:

  1. passengers were able to shoot bullets with the radargun
  2. NPCs were reacting afraid/paniced if you aimed at their cars to take a reading

The first issue I managed to fix using “SetPlayerCanDoDriveBy(PlayerId(), false)” and “SetPlayerCanDoDriveBy(PlayerId(), true)” - which disables the use of the radargun in cars for driver and passengers alike (this might not be very elegant but it sure does the trick).

The second issue is another matter, as I seem to be unable to make NPCs ignore you, when you aim the radargun (i.e. not to react with fear and trying to flee in haste) at them. Is there any way to put that in somehow? Any help is appreciated!

-- ////////////////////////////////////////////////////////////////
		-- DISABLE Attack/Weapon firing and MeleeAttackAlternate
		if getSelectedWeapon then
			DisableControlAction( 0, 24, true ) -- Attack
			DisablePlayerFiring(isPed, true ) -- Disable weapon firing
			DisableControlAction( 0, 142, true ) -- MeleeAttackAlternate
			SetPlayerCanDoDriveBy(PlayerId(), false)
                    else
			SetPlayerCanDoDriveBy(PlayerId(), true)
		end

		-- ////////////////////////////////////////////////////////////////

Try these natives:

@itsBrayden - Thank you very much for your swift reply!

So if I understand this right I can put those code lines in like I did with the “SetPlayerCanDoDriveBy(PlayerId(), false)” toggle above?

TaskSetBlockingOfNonTemporaryEvents(ped, true)
SetBlockingOfNonTemporaryEvents(ped, true)
SetEveryoneIgnorePlayer(PlayerId(), true)

And then toggle it back off

TaskSetBlockingOfNonTemporaryEvents(ped, false)
SetBlockingOfNonTemporaryEvents(ped, false)
SetEveryoneIgnorePlayer(PlayerId(), false)

Resulting in:

-- ////////////////////////////////////////////////////////////////
		-- DISABLE Attack/Weapon firing and MeleeAttackAlternate
		if getSelectedWeapon then
			DisableControlAction( 0, 24, true ) -- Attack
			DisablePlayerFiring(isPed, true ) -- Disable weapon firing
			DisableControlAction( 0, 142, true ) -- MeleeAttackAlternate
			SetPlayerCanDoDriveBy(PlayerId(), false)
			SetBlockingOfNonTemporaryEvents(ped, true)
			TaskSetBlockingOfNonTemporaryEvents(ped, true)
			SetEveryoneIgnorePlayer(PlayerId(), true)
                    else
			SetPlayerCanDoDriveBy(PlayerId(), true)
			SetBlockingOfNonTemporaryEvents(ped, false)
			TaskSetBlockingOfNonTemporaryEvents(ped, false)
			SetEveryoneIgnorePlayer(PlayerId(), false)
		end

		-- ////////////////////////////////////////////////////////////////

OK the above edit did not do the trick, the NPCs still react with fear and panic if one aimes at them with the radar gun… - …pretty sure I used the scripts wrong somehow and/or forgot to define something?

Here is the entire LUA script with the edits (only the “drive by shooting” toggle works).

local shown = false
local isPed = false
local isFreeAiming = false
local getSelectedWeapon = false
Citizen.CreateThread(function()
	while(true) do
		isPed = PlayerPedId()
		isFreeAiming = IsPlayerFreeAiming(PlayerId())
		getSelectedWeapon = GetSelectedPedWeapon(isPed) == GetHashKey(cfg.radargun)

		if shown then
			if getSelectedWeapon then
				if isFreeAiming then
					player = isPed
					coordA = GetOffsetFromEntityInWorldCoords(player, 0.0, 1.0, 1.0)
					coordB = GetOffsetFromEntityInWorldCoords(player, 0.0, 105.0, 0.0)
					frontcar = StartShapeTestCapsule(coordA, coordB, 3.0, 10, player, 7)
					a, b, c, d, e = GetShapeTestResult(frontcar)
					playerId = PlayerId()
					pos = GetEntityCoords(e)
				end
			end
		end
		Citizen.Wait(500)
	end
end)

Citizen.CreateThread( function()
	while true do
		Citizen.Wait(1)

-- ////////////////////////////////////////////////////////////////
		-- DISABLE Attack/Weapon firing and MeleeAttackAlternate
		if getSelectedWeapon then
			DisableControlAction( 0, 24, true ) -- Attack
			DisablePlayerFiring(isPed, true ) -- Disable weapon firing
			DisableControlAction( 0, 142, true ) -- MeleeAttackAlternate
			SetPlayerCanDoDriveBy(PlayerId(), false)
			SetBlockingOfNonTemporaryEvents(ped, true)
			TaskSetBlockingOfNonTemporaryEvents(ped, true)
			SetEveryoneIgnorePlayer(PlayerId(), true)
                    else
			SetPlayerCanDoDriveBy(PlayerId(), true)
			SetBlockingOfNonTemporaryEvents(ped, false)
			TaskSetBlockingOfNonTemporaryEvents(ped, false)
			SetEveryoneIgnorePlayer(PlayerId(), false)
		end

		-- ////////////////////////////////////////////////////////////////

		if IsControlJustPressed(1, cfg.menuopen) then --246 = Y

			if getSelectedWeapon then
				if shown == true then
					shown = false
					SendNUIMessage({
						action = "close",
					})
				else
					SendNUIMessage({
						action = "open",
					})
					shown = true
				end
			else
				if shown == true then
					SendNUIMessage({
						action = "close",
					})
					shown = false
				end
			end
		end

		if shown then
			if getSelectedWeapon then
				if IsControlJustPressed(1, cfg.bottomfreeze) then --38 = E
					if IsEntityAVehicle(e) then
						if isFreeAiming then
							PlaySoundFrontend(-1, "5_Second_Timer", "DLC_HEISTS_GENERAL_FRONTEND_SOUNDS", false)
							if cfg.metric == true then
								local fvspeed = GetEntitySpeed(e)*3.6  -- m/s to kmh
								SendNUIMessage({
									speed = math.ceil(fvspeed),
                                    range = GetDistanceBetweenCoords(GetEntityCoords(isPed),GetEntityCoords(e), true)
								})
							else
								local fvspeed = GetEntitySpeed(e)*2.23694 -- m/s to mph
								SendNUIMessage({
									speed = math.ceil(fvspeed),
                                    range = GetDistanceBetweenCoords(GetEntityCoords(isPed),GetEntityCoords(e), true)
								})
							end
						end
					end
				end
			end
		end
	end
end)

Been trying various versions like:

TaskSetBlockingOfNonTemporaryEvents(ped/npc/pedNPC, false/true)
SetBlockingOfNonTemporaryEvents(ped/npc/pedNPC, false/true)
SetEveryoneIgnorePlayer(PlayerId(), false/true)

but there is no noticable change in the NPCs behaviours, no matter if they are on foot or drive a vehicle: they still react with panic if I aim the radar gun at them. I am starting to think that this is not so easily done after all and might be well above my noob knowledge.

What is “ped” defined as?

@RailedFromBehind - Oh I thought “ped” is something that is automatically defined - I guess from your question that this is not the case. What do I need to put in to define it and make it work exactly? I really suck at programming.

No worries! we all start somewhere. im still learning :slight_smile:
This is what i did when i made a ped. you want to put the ped/peds that should be effected by the event.
I’ve only ever done this to 1 or a group of peds. not all peds. but i guess you could try something
using this native?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.