[SOLVED] Adding AI wanted level to ESX

Sin título Hello, I am trying to complement the AI ​​police with the police players. I am trying to create the following resources:

  • Deactivate wanted level for those who have the job “police”

  • Add wanted level when a robbery to store or bank is finished

  • If a player has a wanted level, an alert will be sent to the real police players

(in the picture is the code that turns off the wanted level for all players, in es_extended)

SOLUTION:

1 Like

the wanted level is a function used to spawn in npc police.

if you just want police to be notified then use P_notify which will alert police to criminal activity.
then just add in the different alerts you want.

I want to increase the 5 starts wanted level on the player, with the NPC police that I have activated from es_extended

im in the same boat but wanting to cap the start level t o 2 or 3, gets to crazy for 4+stars

news ?

What news were you expecting? Whether he added the lines of code or not?

Yes ! because to tell you I’m looking for a script exactly like that and I don’t know anything about coding

This is what I wrote for our policejob to have ai cops supplement the players if wanted. You can see that it checks for a config setting for disabling wanted level or not, then a configurable number of cops to be online whether it should be enabled for a person stealing cars and finally whether they are a police officer. That’s exactly the type of thing that the OP discusses. Create your config settings, use that for your policejob wanted loop and this will do exactly what was being discussed.

Config file:

Config.DisableWantedLevel		  = false
Config.EnoughCopsOnline		      = 3

client/main.lua wanted loop:

-- Disable wanted level
firstLoop = 'yes'
Citizen.CreateThread(function()
	while true do
		if firstLoop then
			Citizen.Wait(10000)
		else
			Citizen.Wait(0)
		end
		if ((Config.DisableWantedLevel or copCount >= Config.EnoughCopsOnline) and carThief == false and wantedToggle ~= 'on') or (wantedToggle == 'off' and carThief == false) or PlayerData.job.name == 'police' then
			local playerId = PlayerId()
			if GetPlayerWantedLevel(playerId) ~= 0 then
				SetPlayerWantedLevel(playerId, 0, false)
				SetPlayerWantedLevelNow(playerId, false)
			end
		end
		firstLoop = nil
	end
end)
1 Like

I thank you forever it seems to work however I have a mistake

I wouldn’t have a solution as you didn’t share any of the problem code in that resource.

have you seen the image i posted above ?

Yes. Have you looked esx_wantedpolice/client/main.lua line 11 to see what’s triggering the error?

Let’s say I copy paste your script, but have a car steal script because I have a CarThief variant?

I don’t know what you’re asking or how it pertains to the error.

1 Like

I copy and paste the line of code you put and an error appears, I have nothing else in the client / main.lua

Then it’s of course going to throw an error as you’re not defining ESX/xplayer, etc. That loop was to be placed in the policejob where the original loop sits. You can’t just throw that into it’s own resource without making that resource ESX-compliant.

ok thanks I will try

config.lua (8.5 KB) main.lua (52.2 KB)

Like that ?

Yes but you’ll likely want to remove the carthief checks as I doubt you happen to have the same type of stolen car gameplay as the one I wrote.

actually I don’t have the CarThief but the simple value is “player”?