Jump to content

[SA] Cleo. Help with creating cops & CCarAI::AddPoliceCarOccupants


vladvo

Recommended Posts

I give up. Tried for several days and still no luck. The problem is that I can't create two cops that behave like game cops. The only difference I need - they should shoot gang members. No matter what I do - at some point their behavior gets messed up.

I start with creating a cop car and then:

0129: 11@ = create_actor_pedtype 6 model 280 in_car 10@ driverseat

No matter what decision maker types I assign to them, no matter what ped acquaintances I set - at some point they start shooting each other and regular (game spawned) cops as well.  Yes, they shoot gang members if I set the right acquaintances, but it's not enough. 
The best I got is spawning a cop with this: (20@ is struct of vehicle)

0AA5: call_function 0x41C070 num_params 2 pop 2 1 20@

I say 'cop' because for some reason it only spawns one cop in the passenger seat. No driver. Tried to change 1 to anything from 1 to 6 - no luck. Still only one.

Maybe someone can give me a good cop script or tell how to use AddPoliceCarOccupants ?

Link to comment
Share on other sites

@vladvo you should use pedtypes 4 (or 5) for your scripts because others (especially 6) are massively manipulated by the game code or a main.scm. 
In most cases pedtypes 4 and 5 (male and female) are just avoided. If you create cops with pedtype 4 and put them inside vehicles they will only have one task and that's car drive. If you do that with pedtype 6 they will have all kinds of tasks and most of them will be focused on the player. At wanted level 0 pedtypes 6 on foot are focused on searching threats of any kind and if they don't find any they simply provoke one. Those inside the vehicles are relatively peaceful but also waiting for a car collision so they can do their cop stuff like beating the suspect or shooting. I don't know why R* made them to be so aggressive because in most cases who ever even slightly confront them - ends up dead on the street.
Bottom line - use pedtype 4 for the cops:

0129: 1@ = create_actor_pedtype 4 model #LAPDM1 in_car 0@ driverseat
01C8: 2@ = create_actor_pedtype 4 model #LAPDM1 in_car 0@ passenger_seat 0

so your peds can be under your controll only.

As for the func:

CCarAI::AddPoliceCarOccupants(CVehicle*, bool);

It looks like the game uses it for the game created vehicles only. That means if the vehicle is made by the script it's most likely that the func will ignore it. However it will probably work if you use it under the:

01C3: remove_references_to_car 0@

Because after that the car is no longer considered to be controlled by a script and becoms game created. Also the cops made by this func will be pedtype 6 which is a problem. Another thing you should know about this function is that it's limited to police vehicle models only. Other vehicle models will be empty.
 

Edited by Jack
Link to comment
Share on other sites

Well, I managed to spawn two cops in cop car with remove_references. Almost nice, but they refuse to accept any acquaintances I set.

Ok, let's forget about them for a while.

Tried pedtype 4 with this setup. Nothing. They do attack gang members but 0709 doesn't work.

Spoiler
060A: create_decision_maker_type 3 store_to 21@ // decision\allowed\m_.ped files
07E5: copy_decision_maker 3 to 21@
0708: reset_decision_maker 21@ event 9
0708: reset_decision_maker 21@ event 15
0708: reset_decision_maker 21@ event 31
0708: reset_decision_maker 21@ event 36
0708: reset_decision_maker 21@ event 43
0708: reset_decision_maker 21@ event 49
0708: reset_decision_maker 21@ event 50
0708: reset_decision_maker 21@ event 51
0708: reset_decision_maker 21@ event 69
0709: set_decision_maker 21@ on_event 9 task 1000 respect 0.0 hate 100.0 like 0.0 dislike 100.0 in_car 1 on_foot 1 //EVENT_DAMAGE
0709: set_decision_maker 21@ on_event 15 task 1000 respect 0.0 hate 100.0 like 0.0 dislike 100.0 in_car 1 on_foot 1 //EVENT_SHOT_FIRED
0709: set_decision_maker 21@ on_event 31 task 1000 respect 0.0 hate 100.0 like 0.0 dislike 0.0 in_car 1 on_foot 1 //EVENT_GUN_AIMED_AT
0709: set_decision_maker 21@ on_event 36 task 1000 respect 0.0 hate 100.0 like 0.0 dislike 0.0 in_car 1 on_foot 1 //EVENT_ACQUAINTANCE_PED_HATE
0709: set_decision_maker 21@ on_event 43 task 1000 respect 0.0 hate 100.0 like 0.0 dislike 100.0 in_car 1 on_foot 1 //EVENT_GOT_KNOCKED_OVER_BY_CAR
0709: set_decision_maker 21@ on_event 49 task 1000 respect 0.0 hate 100.0 like 0.0 dislike 100.0 in_car 1 on_foot 1 //EVENT_SHOT_FIRED_WHIZZED_BY
0709: set_decision_maker 21@ on_event 50 task 1000 respect 100.0 hate 100.0 like 100.0 dislike 100.0 in_car 1 on_foot 1 //EVENT_LOW_ANGER_AT_PLAYER
0709: set_decision_maker 21@ on_event 51 task 1000 respect 100.0 hate 100.0 like 100.0 dislike 100.0 in_car 1 on_foot 1 //EVENT_HIGH_ANGER_AT_PLAYER
0709: set_decision_maker 21@ on_event 69 task 1000 respect 100.0 hate 100.0 like 100.0 dislike 100.0 in_car 1 on_foot 1 //EVENT_PLAYER_WANTED_LEVEL
//0709: set_decision_maker 21@ on_event 72 task 200 respect 100.0 hate 0.0 like 0.0 dislike 0.0 in_car 1 on_foot 1 //EVENT_SEEN_COP
077C: clear_actor 11@ acquaintance 1 to_all_pedtypes // see ped.dat
077C: clear_actor 11@ acquaintance 2 to_all_pedtypes // see ped.dat
077C: clear_actor 11@ acquaintance 3 to_all_pedtypes // see ped.dat
077C: clear_actor 11@ acquaintance 4 to_all_pedtypes // see ped.dat
077C: clear_actor 12@ acquaintance 1 to_all_pedtypes // see ped.dat
077C: clear_actor 12@ acquaintance 2 to_all_pedtypes // see ped.dat
077C: clear_actor 12@ acquaintance 3 to_all_pedtypes // see ped.dat
077C: clear_actor 12@ acquaintance 4 to_all_pedtypes // see ped.dat
077A: set_actor 11@ acquaintance 3 to_actors_pedtype 0 // Player
077A: set_actor 12@ acquaintance 3 to_actors_pedtype 0
077A: set_actor 11@ acquaintance 2 to_actors_pedtype 4 // CivMale
077A: set_actor 12@ acquaintance 2 to_actors_pedtype 4
077A: set_actor 11@ acquaintance 1 to_actors_pedtype 0 // CivFemale
077A: set_actor 12@ acquaintance 1 to_actors_pedtype 0 
077A: set_actor 11@ acquaintance 1 to_actors_pedtype 6 // Cop
077A: set_actor 12@ acquaintance 1 to_actors_pedtype 6
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 7 // Ballas
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 7
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 8 // Grove Street Families
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 8
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 9 // Los Santos Vagos
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 9
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 10 // San Fierro Rifa
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 10
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 11 // Da Nang Boys
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 11
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 12 // Mafia
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 12
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 13 // Mountain Cloud Triad
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 13
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 14 // Varrio Los Aztecas
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 14
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 15 // Gang9
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 15
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 16 // Gagng10
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 16
077A: set_actor 11@ acquaintance 4 to_actors_pedtype 17 // Dealer
077A: set_actor 12@ acquaintance 4 to_actors_pedtype 17
077A: set_actor 11@ acquaintance 1 to_actors_pedtype 18 // Medic
077A: set_actor 12@ acquaintance 1 to_actors_pedtype 18
077A: set_actor 11@ acquaintance 1 to_actors_pedtype 19 // Fireman
077A: set_actor 12@ acquaintance 1 to_actors_pedtype 19
077A: set_actor 11@ acquaintance 3 to_actors_pedtype 20 // Criminal
077A: set_actor 12@ acquaintance 3 to_actors_pedtype 20
077A: set_actor 11@ acquaintance 3 to_actors_pedtype 21 // Bum
077A: set_actor 12@ acquaintance 3 to_actors_pedtype 21
077A: set_actor 11@ acquaintance 3 to_actors_pedtype 22 // Prostitute
077A: set_actor 12@ acquaintance 3 to_actors_pedtype 22

07DD: set_actor 11@ attack_rate 80 // previously known as temper_to
07DD: set_actor 12@ attack_rate 80 // previously known as temper_to
060B: set_actor 11@ decision_maker_to 21@
060B: set_actor 12@ decision_maker_to 21@

048F: actor 11@ remove_weapons
048F: actor 12@ remove_weapons
01B2: give_actor 11@ weapon 3 ammo 0
01B2: give_actor 11@ weapon 22 ammo 20
01B2: give_actor 12@ weapon 3 ammo 0
01B2: give_actor 12@ weapon 22 ammo 20
02E2: set_actor 11@ weapon_accuracy_to 80
02E2: set_actor 12@ weapon_accuracy_to 80
0209: 0@ = random_int_in_ranges 4 9
if 0@ == 8
then 
0@ = 15
end
07FE: set_actor 11@ fighting_style_to 0@ moves 6
0209: 0@ = random_int_in_ranges 4 9
if 0@ == 8
then 
0@ = 15
end
07FE: set_actor 12@ fighting_style_to 0@ moves 6

 

Apart from that I made a small script that checks char's DM type.

:MAIN
wait 0
0AD2: 1@ = player $PLAYER_CHAR targeted_actor // IF and SET
if 
1@ > 0
then
0A96: 21@ = ped 1@ struct
0D4E: 22@ = struct 21@ offset 0x47C size 4
0D4E: 26@ = struct 22@ offset 0xB4 size 4
0AD1: show_formatted_text_highpriority "DMT:%d" time 20 26@
end
jump @MAIN

CPed -> m_pIntelligence -> m_dwDecisionMakerType
It returns 11. Why ?
Still no luck. 

Link to comment
Share on other sites

You might wanna try these as well:

0687: clear_actor 0@ tasks
0433: set_actor 0@ criminal_flag 0
074E: unknown_set_actor_threat_scanner_flags 0@ radius 750.0 peds_to_scan 0
0770: set_actor 0@ target_priority 1
09B6: set_actor 0@ wanted_by_police 0
0961: set_actor 0@ keep_tasks_after_cleanup 1   //  for the mission pedtype probably

Also there's this:

0x5DDE80     ; CCopPed_SetPartner(CCopPed *this, CEntity *ent);

Btw using:

CCarAI::AddPoliceCarOccupants(CVehicle*, bool);

is basicly the same as this:

0129: 1@ = create_actor_pedtype 6 model #LAPD1 in_car 0@ driverseat
01C8: 2@ = create_actor_pedtype 6 model #LAPD1 in_car 0@ passenger_seat 0
01C2: remove_references_to_actor 1@
01C2: remove_references_to_actor 2@

And remember - after using 01C2 the ped is no longer under a script controll. 
 

Link to comment
Share on other sites

10 hours ago, Jack said:

is basicly the same as this:

I have a bit of doubt. When I had a cop that was spawned by AddPoliceCarOccupants - he was a real in-game cop, with all default cop behavior. The ones that were spawned by opcode were just standing like dummies.

Link to comment
Share on other sites

48 minutes ago, Strs said:

still need help for cops car and cops behave like game cops ?

Yep. Not tested Jack's recommendations yet.
What I want from them is to react to all the stuff game cops react to. Accept custom acquaintances. And most important - do not attack game cops.

 

Link to comment
Share on other sites

{$CLEO}
wait  500
while true
wait  0
if    0ADC: test_cheat "wnt2" //for test or you just shoot this car or cop 
then  010D: set_player 0 wanted_level_to 2 //for test if cops work no need more than that you can do anything 
0ace: "wanted 2"
end
if    0ADC: test_cheat "wcop" //
jf    continue
0247: load_model #COLT45
0247: load_model 280
0247: load_model #COPCARLA
0247: load_model #NITESTICK
038B: load_requested_models
if    and
0248: model #COLT45 available
0248: model 280 available
0248: model #COPCARLA available
0248: model #NITESTICK available
jf    continue
wait  100
04C4: store_coords_to 0@ 1@ 2@ from_actor $PLAYER_ACTOR with_offset 0.0 20.0 -1.0
02C1: store_to 0@ 1@ 2@ car_path_coords_closest_to 0@ 1@ 2@
00A5: 0@ = create_car #COPCARLA at 0@ 1@ 2@
0186: 20@ = create_marker_above_car 0@
0129: 1@ = create_actor_pedtype 6 model 280 in_car 0@ driverseat
01B2: give_actor 1@ weapon 3 ammo 1 // Load the weapon model before using this
01B2: give_actor 1@ weapon 22 ammo 600 // Load the weapon model before using this
0A96: 4@ = 1@ actor_struct
0A8E: 5@ = 4@ + 0x484 //Set as game spawn
0A8C: 5@ size 2 value 1 vp 0
0746: set_acquaintance 0 of_actors_pedtype 6 to_actors_pedtype 6 // just to make sure that cops dont shoot other cops 
07DD: set_actor 1@ temper_to 80 // see pedstats.dat  
02E2: set_actor 1@ weapon_accuracy_to 65 
060B: set_actor 1@ decision_maker_to 2 
00AE: set_car 0@ traffic_behaviour_to 0 //2 cop Behavior
00AF: set_car 0@ driver_behaviour_to 1 //1 Normal 6 or 44 Copcar chase CJ idk why
0A97: 5@ = car 0@ struct
0A8E: 6@ = 5@ + 0x428 //    
0A8C: 6@ size 2 value 8401 vp 0 //value 209 is cop car go to player and stop cops get down and attack cj 144 is go faster chase someone and 
0ace: "Cops Car and cops Spawned"
01C3: remove_references_to_car 0@
end

Link to comment
Share on other sites

On 8/2/2023 at 1:53 AM, vladvo said:

...at some point they start shooting each other and regular (game spawned) cops as well...

If nothing helps you might wanna check cop ped target entity (scm):

0E44: get_char_kill_target_char 0@ store_to 1@

c++:

if (var0->m_pIntelligence) {
    if (var0->m_pIntelligence->GetTaskUseGun()) {
        if (var0->m_pIntelligence->GetTaskUseGun()->m_pTarget == var1) {
            //  then clear and reset var0 tasks
        }
    }
}

where var0 and var1 are instances of the CPed class - police peds.

Edited by Jack
Link to comment
Share on other sites

Hey @Jack sir i try  0E44: get_char_kill_target_char 0@ store_to 1@ and see they function is active only game event if you remember some driveby happens and cops chase that 16 abd 36 and 24 it shows in  0x41C byte 1 // mTarget cant set it just giving info 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.