Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Get the ped targetted by my suspect's task

Featured Replies

Hi, I don't know how to get the ped targetted by my suspect's task. For exemple if I execute suspect.FightAgainst(human); how can I in an other area of the code get the human my ped is fighting with ? And if my suspect is fighting against multiple humans, can I get all of them ?

by Mytical.

  • Replies 20
  • Views 1.2k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • GTAbear
    GTAbear

    I did, and so it is, but its possible to fiddle a bit. It has no real functionality so no reason to do it. It will most likely also be crash-prone   Yes, you can do anything, it could be a

Posted Images

  • Author
9 hours ago, LMS said:

Check the CombatTarget property.

Thanks, didn't saw it. But for exemple if my task is EnterVehicle(); how can I get the vehicle ? Is there a universal way to get the target of a task ?

by Mytical.

1 hour ago, Mytical49 said:

Thanks, didn't saw it. But for exemple if my task is EnterVehicle(); how can I get the vehicle ? Is there a universal way to get the target of a task ?

Maybe I'm not understanding the question correctly:

 

All tasks have the Target as requirement anyway. So EnterVehicle(TargetVehicle), LeaveVehicle(TargetVehicle) etc. Scriptwise you would always know what TargetVehicle is. You can't call those functions and let the game decide who to target

  • Author
15 minutes ago, RicyVasco said:

Maybe I'm not understanding the question correctly:

 

All tasks have the Target as requirement anyway. So EnterVehicle(TargetVehicle), LeaveVehicle(TargetVehicle) etc. Scriptwise you would always know what TargetVehicle is. You can't call those functions and let the game decide who to target

I'm going to explain my situation a bit more, I have a ped who needs to attack his closest enemy (FightAgainstClosestHatedTarget(); ), which means he will attack a closest enemy, but the problem is that his enemies change dynamically in another part of the code with a gamefiber. Following this the ped acts in the wrong way (after FightAgainstClosestHatedTarget(); is executed, he will move towards an enemy who is far away or will spontaneously stop its task), to be able to better debug the problem it would be a lot easier to be able to identify which ped he targets, and also because it would be very practical to integrate later in my code. I hope I was clear enough

by Mytical.

  • Management Team
32 minutes ago, Mytical49 said:

I'm going to explain my situation a bit more, I have a ped who needs to attack his closest enemy (FightAgainstClosestHatedTarget(); ), which means he will attack a closest enemy, but the problem is that his enemies change dynamically in another part of the code with a gamefiber. Following this the ped acts in the wrong way (after FightAgainstClosestHatedTarget(); is executed, he will move towards an enemy who is far away or will spontaneously stop its task), to be able to better debug the problem it would be a lot easier to be able to identify which ped he targets, and also because it would be very practical to integrate later in my code. I hope I was clear enough

 

It might make sense to store its current target, as modified by your code, as metadata. For instance: ped.Metadata.CombatTaskTarget. That way you can manually set it whenever you change it and can rely on it.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

  • Author
2 hours ago, LMS said:

 

It might make sense to store its current target, as modified by your code, as metadata. For instance: ped.Metadata.CombatTaskTarget. That way you can manually set it whenever you change it and can rely on it.

I don't understand the difference and the purpose of using metadata (I'am new to this), because if I can set ped.Metadata.CombatTaskTarget, wouldn't it be simpler to just make a variable that I can change when I want and who store the target . For exemple : Ped dynamiqueTarget = suspect.CombatTarget; and I put this in a new GameFiber with a loop so dynamiqueTarget is everytime equal to the ped my suspect is fighting with.

by Mytical.

  • Management Team
21 hours ago, Mytical49 said:

I don't understand the difference and the purpose of using metadata (I'am new to this), because if I can set ped.Metadata.CombatTaskTarget, wouldn't it be simpler to just make a variable that I can change when I want and who store the target . For exemple : Ped dynamiqueTarget = suspect.CombatTarget; and I put this in a new GameFiber with a loop so dynamiqueTarget is everytime equal to the ped my suspect is fighting with.

 

Metadata makes it easy to associate data with a specific ped, whereas using a variable only works well if you only have one ped. You can, of course, create your own class or dictionary etc. to store variables for peds, but metadata does that for you already.

 

20 hours ago, Mytical49 said:

I just figured out that the CombatTarget property won't work because the task of my susepct is in "InProgress" status

 

What do you mean by that? If the task is currently running, then it should return the correct ped.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

  • Author
6 hours ago, LMS said:

 

Metadata makes it easy to associate data with a specific ped, whereas using a variable only works well if you only have one ped. You can, of course, create your own class or dictionary etc. to store variables for peds, but metadata does that for you already.

 

 

What do you mean by that? If the task is currently running, then it should return the correct ped.

Okay I understand better.

 

I have this code in my process

if (mySuspect.IsInCombat)
                        {
                            Game.Console.Print("TARGET SET");
                        target = mySuspect.CombatTarget;
                        }
                        
                        if (target.Exists()) 
                        {
                            Game.Console.Print("TARGET EXIST");
                            if (!target.GetAttachedBlip().Exists())
                            {
                                Game.Console.Print("ATTACH BLIPP");
                                target.AttachBlip();
                                targetBlip.Color = Color.Blue;
                            }
                        }
                        else
                        {
                            Game.Console.Print("TARGET NOT EXIST");
                        }
                        Game.Console.Print(Convert.ToString(mySuspect.Tasks.CurrentTaskStatus));

which return this in game : 

image.png.7771228ebc5664c7d0bd677d63c8c350.png

So, maybe my suspect is never in combat (never seen "TARGET SET" in the console), but then why the task is in progress ?

 

extra infomation : here is the code the is in the progess() who define the ped he must attack

victim = (Ped)World.GetClosestEntity(mySuspect.Position, 30f, GetEntitiesFlags.ConsiderHumanPeds);

and here is the task who is executed only one time after victim is set (keeptask is set to true) :

if (done == false) { mySuspect.Tasks.FightAgainst(victim); done = true; }

I don't know what to think about it, maybe you can help me

 

by Mytical.

16 hours ago, Mytical49 said:

maybe my suspect is never in combat

Yes it is not.
-You do not see any debug-text for your code except for the else block, that has
Game.Console.Print("TARGET NOT EXIST");
(you should use LogTrivial instead of .Console.Print, that is easier to compare to code, because you have all in a file)
But what is it you want to achieve ?
Do you want to return the Ped your suspect is aiming at? (in a holdup i guess..)

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

  • Management Team

I see, that is certainly odd. We use CombatTarget quite extensively in LSPDFR so I am sure it works. What does your combat look like? Melee, guns? How long has it been running when you check the target?

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

  • Author
10 hours ago, GTAbear said:

Yes it is not.
-You do not see any debug-text for your code except for the else block, that has
Game.Console.Print("TARGET NOT EXIST");
(you should use LogTrivial instead of .Console.Print, that is easier to compare to code, because you have all in a file)
But what is it you want to achieve ?
Do you want to return the Ped your suspect is aiming at? (in a holdup i guess..)

Hi, thanks for your reply, I don't know the difference between them, both of them show in-game in the console and both are in the RagePluginHook.log.

In fact I'am still learning to do a callout, what I want to do is having a suspect that shoot at everyone and focus on the police and the player when they arrive, I tried multiple things to achieve it but either, they don't work or didn't do exactly what I want. What I actually want to try is having a ped which is defined by :

(Ped)World.GetClosestEntity(mySuspect.Position, 30f, GetEntitiesFlags.ConsiderHumanPeds);

every time in the process, and then who got the task :

if (done == false) { mySuspect.Tasks.FightAgainst(victim); done = true; }

which is executed one time. But it don't work (I will post a video to show what happend). So what I want now is trying to debug it by getting the ped my suspect want to attack (victim), and then attach a blip to him to see where he is (but I guess if I debug it, it won't be necessary), the main problem is that when the I run the callout my suspect is running somewhere indefinitely.

 

9 hours ago, LMS said:

I see, that is certainly odd. We use CombatTarget quite extensively in LSPDFR so I am sure it works. What does your combat look like? Melee, guns? How long has it been running when you check the target?

My combat is not even happening (that's why I don't understand why the task is "InProgress")(you will see in the video), but yeah my suspect a a gun, here is the part where my suspect is defined :

		mySuspect = new Ped(SpawnPoint);
                mySuspect.BlockPermanentEvents = true;
                mySuspect.IsPersistent = true;
                mySuspect.Inventory.GiveNewWeapon("weapon_pistol_mk2", -1, true);
                mySuspect.Accuracy = 30;
                mySuspect.Armor = 75;
                mySuspect.FiringPattern = FiringPattern.BurstFireInCover;
                mySuspect.KeepTasks = true;
                mySuspect.RelationshipGroup = RelationshipGroup.Gang1;
                mySuspect.RelationshipGroup.SetRelationshipWith(RelationshipGroup.Player, Relationship.Hate);
                mySuspect.RelationshipGroup.SetRelationshipWith(RelationshipGroup.Cop, Relationship.Hate);
                mySuspect.RelationshipGroup.SetRelationshipWith(RelationshipGroup.Medic, Relationship.Neutral);

I'am not sure to understand your last question, can you develop ? 

Forgot to ask something, is the .NET framework version important and may cause that, because I saw something like that in an other topic, I'am using 4.8 .NET ?

 

 

HERE IS THE VIDEO : https://youtu.be/zQxaC-f0fP8       (it is even weirder because at 01:45 you can see him changing direction suddently after blocking him)

Edited by Mytical49
another detail

by Mytical.

  • Management Team

Fleeing is/can be part of the combat task if I remember correctly, so that might be why you are seeing the task as in progress. I am not sure why your ped would run away, though. Who are you tasking them to fight against? To make your life easier, why don't you move the code to spawn the ped and target to a console command so you do not always have to start the callout?

 

And no, .NET version does not affect this.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

On 5/3/2023 at 10:52 PM, Mytical49 said:

both of them show in-game in the console and both are in the RagePluginHook.log.

I diddent know that, so your fine.
Some of your code puzzles me. It is very different from mine. Yours may be excellent LMS will know, but

 

On 5/3/2023 at 10:52 PM, Mytical49 said:
(Ped)World.GetClosestEntity(mySuspect.Position, 30f, GetEntitiesFlags.ConsiderHumanPeds);


Why do you want to do a check on every entity for being human Peds?
Why not use a Ped[] and only check on Peds, and make those inside your distance (30f)? into targets?
I would use Game.gametime to setup the check frequency
I am also puzzled by the way you use relationship
When i declare a relation i do it like
assestee.RelationshipGroup = "COP";
Where "COP" is one of the default relationshioGroups
But it is also fine to say
chauf.RelationshipGroup = "SERVICEIMPLOYED";
Here i define a new group "SERVICEIMPLOYED" and i can use that as a filter for action
Setting relation i do like
 Game.SetRelationshipBetweenRelationshipGroups("even", "uneven", Relationship.Hate);//Mutual relations!
 Game.SetRelationshipBetweenRelationshipGroups("uneven", "even", Relationship.Hate);

Here i have a populated Ped[] and transverse it, then set everybody up against eachother and make them shoot at eachother, only depending on weather they were in an even or uneven position in the array :p.
-It was mostly a test of methods; And that works. Everybody do shoots at eachother.
I also wonder if this
 

On 5/3/2023 at 10:52 PM, Mytical49 said:
if (done == false) { mySuspect.Tasks.FightAgainst(victim); done = true; }

works like you expect?
Place a debug-check inside brackets, and follow output on console

 

Your video is very interesting! I have to ask you how you have AI-cars reacting to You in a non-police-car, because it IS a non-police-car, ???
It is YOU who have changed the lighting and given it a siren???
I have done exactly the same, any car can emulate a policecar, but it is only show-off. I cant make any other vehicle yield to the faked-policecar. It looks like Yours does, How have you achieved that???

On 5/4/2023 at 2:47 PM, LMS said:

why don't you move the code to spawn the ped and target to a console command so you do not always have to start the callout?

Woooo I had NO idea that could be done!
Could you point us to an example of how to do that?
Perhaps something like changing the Health-parameter for a specific entity through console input?
I have attempted to make a coroner-feature, but it is impossible to get a handle to a corpse, they are of a type i cant figure out, and seams to be impossible to address -They are not Peds after they are declared dead by an Ambulance crew
'Brute force'
World.CleanWorld(false, true, false, false, true, true);
handles them

Edited by GTAbear
bad format

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

  • Management Team
7 hours ago, GTAbear said:

Woooo I had NO idea that could be done!
Could you point us to an example of how to do that?

 

To test simple functionality, it is very helpful. An example to spawn a ped could be:

 

[ConsoleCommand(Name = "SpawnCopTest")]
private static void Command_SpawnCopTest()
{
  Ped p = new Ped("s_f_y_cop_01", Game.LocalPlayer.Character.GetOffsetPositionFront(2f), 0f);
  p.Dismiss();
  p.Tasks.StandStill(-1);
}

// You probably have to call this at the start of your plugin somewhere:
Game.AddConsoleCommands(new Type[] { typeof(ClassWithYourConsoleCommand) });

 

Every console command automatically runs in a new fiber so you can sleep and loop there for more advanced functionality.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

  • Author
On 5/4/2023 at 2:47 PM, LMS said:

Fleeing is/can be part of the combat task if I remember correctly, so that might be why you are seeing the task as in progress. I am not sure why your ped would run away, though. Who are you tasking them to fight against? To make your life easier, why don't you move the code to spawn the ped and target to a console command so you do not always have to start the callout?

 

And no, .NET version does not affect this.

So I tried to use a custom command and it works but then on the code I still have the same problem but it is easier to try things, thanks. My ped is fighting agains't victim who is defined by

(Ped)World.GetClosestEntity(mySuspect.Position, 30f, GetEntitiesFlags.ConsiderHumanPeds);

I believe the main problem is that when I execute FightAgainst(victim); the victim must be set in the memory and even when victim will change of value it will do nothing because it is the victim of the memory who is the target. To make it possible i would have need the function to take dynamique variable. I have a question, how does the time affect the function ? if I put 5000 what will happend at the end ? If I put -1, will the ped be chasing the victim indefinitely ?

 

11 hours ago, GTAbear said:

Some of your code puzzles me. It is very different from mine.

Why do you want to do a check on every entity for being human Peds?
Why not use a Ped[] and only check on Peds, and make those inside your distance (30f)? into targets?

How does mine is so different of yours ? Because I want my victim to be a Human Ped, so i have the ConsiderHumanPeds, it will return to me the closest human ped within 30f of my suspect position. How would you do ?

 

11 hours ago, GTAbear said:

I would use Game.gametime to setup the check frequency

What do you mean by check frequency and how ?

 

11 hours ago, GTAbear said:

I am also puzzled by the way you use relationship
When i declare a relation i do it like
assestee.RelationshipGroup = "COP";
Where "COP" is one of the default relationshioGroups
But it is also fine to say
chauf.RelationshipGroup = "SERVICEIMPLOYED";
Here i define a new group "SERVICEIMPLOYED" and i can use that as a filter for action
Setting relation i do like
 Game.SetRelationshipBetweenRelationshipGroups("even", "uneven", Relationship.Hate);//Mutual relations!
 Game.SetRelationshipBetweenRelationshipGroups("uneven", "even", Relationship.Hate);

Here i have a populated Ped[] and transverse it, then set everybody up against eachother and make them shoot at eachother, only depending on weather they were in an even or uneven position in the array :p.

I tried to use relationship at the first try with the FightAgainstClosestHated(); and it didn't work, I had a part where I wanted ped who are not a certain area to be set back to a normal relationship because when the shooting will start peds are going to run, and I don't want my suspect to chase them, I want my suspect to stay where he is, wait for the cops and shoot them.

 

11 hours ago, GTAbear said:

works like you expect?

It does

 

11 hours ago, GTAbear said:

Your video is very interesting! I have to ask you how you have AI-cars reacting to You in a non-police-car, because it IS a non-police-car, ???
It is YOU who have changed the lighting and given it a siren???
I have done exactly the same, any car can emulate a policecar, but it is only show-off. I cant make any other vehicle yield to the faked-policecar. It looks like Yours does, How have you achieved that???

I have totally no idea I didn't modified anythings, here is the link if I remember well.

by Mytical.

On 5/5/2023 at 8:49 PM, LMS said:

An example to spawn a ped

Thank You LMS! This will be very useful indeed!

 

 

On 5/6/2023 at 12:50 AM, Mytical49 said:

I want my victim to be a Human Ped

..Eh Human-Ped!?
In LSPD all Ped(s) are AI-Humans. Ped stands for Pedestrian
Ped is a subclass of Entity**
Using Entity will make the engine go through everything that exists as objects in the world, so things like boxes and road-furniture would be in the collection
If you use a Ped[] and populate it like
Ped[] pedGrp = mySuspect.GetNearbyPeds(9);
You would have an array with  10 Ped closest to your suspect
I believe they will be in order of near-to so Ped[0] is closest.
That could be your suspect' 1. target

Quote

What do you mean by check frequency and how ?

frequency : how often you would like to update f.i. target-selection
How:
If you in game-loop have something like

Spoiler
if(doThis) //is true
{
uint timerCounter = Game.GameTime +10000; //10 secd
                                 doThis = false;//block multiple calls                                   
                                }

                                if (Game.GameTime >= timerCounter)                            
                                {
                                    timerCounter = 0;                                  
                                   <make something take place>

}

 

where you then <make something take place> you also set doThis == true
with a frequency of 10. secd the event <make something take place> will happen
<make something take place> could f.i be that your suspect selects a new target from Ped[], or a change of behaviour

On 5/6/2023 at 12:50 AM, Mytical49 said:

FightAgainstClosestHated(); and it didn't work

True not always, but if FightAgainst(ped[n]) is used it works
 

 

On 5/6/2023 at 12:50 AM, Mytical49 said:

I have totally no idea I didn't modified anythings, here is the link if I remember well.

Ohhh you use a DLC car that IS a police car. I diddent realize that 🙂
 

** its actually possible to make some shenanigans and use animals as Peds, then you can do something like this:
image.png?width=1020&height=550

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

  • Author
7 hours ago, GTAbear said:

In LSPD all Ped(s) are AI-Humans. Ped stands for Pedestrian

thanks, I didn't knew that.

 

7 hours ago, GTAbear said:

f.i. target-selection

Sorry I don't understand what this is, english is not my native language

7 hours ago, GTAbear said:

If you in game-loop have something like

If I understand well, the purpose of this, is changing the behaviour of my ped ?

 

7 hours ago, GTAbear said:

its actually possible to make some shenanigans and use animals as Peds, then you can do something like this:

Didn't you said Ped are only pedestrian ?
I didn't know we could use bike with Rage, but how do you assign a task to a pig ?

by Mytical.

17 hours ago, Mytical49 said:

Didn't you said Ped are only pedestrian ?

I did, and so it is, but its possible to fiddle a bit. It has no real functionality so no reason to do it. It will most likely also be crash-prone

 

17 hours ago, Mytical49 said:

If I understand well, the purpose of this, is changing the behaviour of my ped ?

Yes, you can do anything, it could be a shift from moving towards a position with a check of something, and the shift to attacking the Peds in that position. That could be a state-machine


Does it work if you use FightAgainst(<Ped>);

See my plugin here:
https://www.youtube.com/watch?v=peqSXuTfIyY

Let me know if you find it interesting.
Best Regards.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.