[FREE] [QBCore] AI Police

Would suggest to make a pull request if you have any improvements instead of just saying this or that is wrong and help to make this a great script.

Nah I don’t mind the suggestion, he’s free to write whatever :wink:

The apparent issues that people reported are now all sorted though.

I’ll go about further optimizing the cop check as Eden suggested above and look into why the AI police are sometimes complete idiots tomorrow :policeman:

1 Like

Can confirm all the issues reported are resolved. Only still issue with the cops driving past you first.

3 Likes

Been testing bit more still not solved the issue police just driving past you but found: GetPlayerWantedCentrePosition / SetPlayerWantedCentrePosition so might have a test with that.

Managed to build in surrender option where you will get send to jail, does work but still testing some stuff. Sorry MLO not loaded on test server so does look bit crap in video. Also we changed police vehicles in the video.

Yeah the surrender option is kind of cool :slight_smile:

As for the AI driving past the player, I’ve tested out some Natives and couldn’t get it fixed either. It seems to only really be a consistent issue on one star. 2 Stars and up seems to work fine 85% of the time. If you have the fix for it, feel free to share it with me/PR the repo!

No worries happy to share, and most likely could be optimized. No checks if in vehicle or anything.
Only tested few times but surrender option so far:

RegisterCommand('surrender', function()
    QBCore.Functions.TriggerCallback("phade-aipolice:server:GetCops", function(copCount) 
        if copCount == 0 then 
			FreezeEntityPosition(PlayerPedId(), true)
            TriggerEvent('animations:client:EmoteCommandStart', {"surrender"})
            SetPoliceIgnorePlayer(PlayerId(), true)
            ClearPlayerWantedLevel(PlayerId())
            SetPlayerWantedLevelNow(PlayerId(),false)
            Citizen.Wait(2500)
            TriggerEvent("police:client:SendToJailAI", (PlayerId()), 30)
            FreezeEntityPosition(PlayerPedId(), false)
        end                        
    end)
end)

Did try with Progressbar and other options but had issue if people cancel they can abuse it to reset their wanted level, didn’t find way to avoid that yet or find other Natives stop police shooting. Could of course counter that with setting wanted level on random number or something.

Might be nice to do something with hands up function to surrender.

Oke oke let me help this developer out lets give you some tips with code. i used InteractSound for this.
I think adding this would make your script better way much better.

Blockquote <-------remove this line)
RegisterCommand(‘surrender’, function()
QBCore.Functions.TriggerCallback(“phade-aipolice:server:GetCops”, function(copCount)
if copCount == 0 then
FreezeEntityPosition(PlayerPedId(), true)
TriggerEvent(‘animations:client:EmoteCommandStart’, {“surrender”})
SetPoliceIgnorePlayer(PlayerId(), true)
ClearPlayerWantedLevel(PlayerId())
SetPlayerWantedLevelNow(PlayerId(),false)
Citizen.Wait(2500)
– Add police audio cue here
TriggerServerEvent(‘InteractSound_SV:PlayWithinDistance’, 3.0, ‘stop_hands_up’, 0
TriggerEvent(“police:client:SendToJailAI”, (PlayerId()), 30)
FreezeEntityPosition(PlayerPedId(), false)
end
end)
end)

Blockquote <------- remove this line
Config = {}
Config.sounds = {
stop_hands_up = {
file = “path/to/stop_hands_up.ogg”,
volume = 0.5,
},
}

Actually did something similar to this on my little test server about a year ago, enabled wanted in QB and only cleared wanted stars if your job was police so you could be a cop and shoot crims alongside the AI police lol.

Can we have an ESX version?

Hello, this is a script I have been looking forward to for a while on my personal server for a few friends and myself. I am a novice when it comes to this type of programming but I am hoping someone could shed some light on an issue I keep receiving. I installed this AI police script on a fresh copy of a QB server. When I attempt to use a lockpick I get the notification “event lockpicks:UseLockpick was not safe for net”. Would someone be able to assist with why it is triggering this error instead of notifying AI police? Thank you so much in advance.

I’ll give support on my discord (linked on the repo) not over the forum post.

You can change the settings to add wanted system in es_extended config

This is sweet. I spent hours trying to do this on my own with not a whole lot of success outside of them spawning. It would be badass if you could get it setup so when a player is killed by one of the AI police they wake up in jail instead of at the hospital.

2 Likes

Can i get some help on this please, 1st time i added was working now for some reason it aint

where would i need to add this

Has this been added yet?

im assuming theres no way to make it the police vehicles for your own servers needs? would be really cool if the cruisers would be OPP or toronto police in our server

yes you can i have calgary cop cars on my server and RCMP as well just need to change the vanilla ones in your car folder to your livery for your city

1 Like

yea i am also having this issue. Seems like a great idea

Hella smart.