Jump to content

[SOLVED] Overuse IsCopBusy()


ziipzaaapM16A4

Recommended Posts

Hello ,

 

so i tried this day to find out when a cop is busy by lspdfr so i can better decide on which cops i use.

i wrote so far this code here

Spoiler



GameFiber.StartNew(delegate 
{ 
    try {
        Game.LogTrivial("[lspdfrTesterPlugin] Main: Started");
        Ped[] allPeds = Game.LocalPlayer.Character.GetNearbyPeds(1);
        var pedRegisterRed = new List<Ped>();
        var pedRegisterYellow = new List<Ped>();
        var pedRegisterGreen = new List<Ped>();

        GameFiber.StartNew(delegate
        {
            while (OnDuty)
            {
                GameFiber.Sleep(4000);
                Game.LogTrivial("[lspdfrTesterPlugin] Detect: cleaning now the Lists");
                allPeds = Game.LocalPlayer.Character.GetNearbyPeds(16);
                pedRegisterRed = new List<Ped>();
                pedRegisterYellow = new List<Ped>();
                pedRegisterGreen = new List<Ped>();

                Game.LogTrivial("[lspdfrTesterPlugin] [Detect]: detecting now peds");
                foreach (var ped in allPeds)
                {
                    try
                    {
                        GameFiber.Sleep(500);
                        Game.LogTrivial("[lspdfrTesterPlugin] [Detect]: IsPedACop?");
                        if (Functions.IsPedACop(ped))
                        {
                            Game.LogTrivial("[lspdfrTesterPlugin] [Detect]: IsPedACop? YES");
                            GameFiber.Sleep(500);
                            Game.LogTrivial("[lspdfrTesterPlugin] [Detect]: IsCopBusy(ped, false)");
                            if (Functions.IsCopBusy(ped, false))
                            {
                                pedRegisterRed.Add(ped);
                                goto goOn;
                            }
                                                    
                            GameFiber.Sleep(500);
                            Game.LogTrivial("[lspdfrTesterPlugin] [Detect]: IsCopBusy(ped, true)");
                            if (Functions.IsCopBusy(ped, true))
                            {
                                pedRegisterYellow.Add(ped);
                                goto goOn;
                            }

                            GameFiber.Sleep(500);
                            Game.LogTrivial("[lspdfrTesterPlugin] [Detect]: !IsCopBusy(ped, true)");
                            pedRegisterGreen.Add(ped);

                            goOn:
                            GameFiber.Yield();
                        } else
                        {
                            Game.LogTrivial("[lspdfrTesterPlugin] [Detect]: IsPedACop? NO");
                        } 
                    } 
                    catch { }
                }
                Game.LogTrivial("[lspdfrTesterPlugin] [Detect]: Assigned the last Ped in List to a group. Sleeping now");
            }
        });

        Game.LogTrivial("[lspdfrTesterPlugin] [Display]: New Round");
        while (OnDuty)
        {
            try
            {
                foreach (var ped in pedRegisterRed)
                {
                    try { Debug.DrawSphere(ped.AbovePosition, 0.20f, System.Drawing.Color.Red); } catch { }
                }

                foreach (var ped in pedRegisterYellow)
                {
                    try { Debug.DrawSphere(ped.AbovePosition, 0.20f, System.Drawing.Color.Yellow); } catch { }
                }

                foreach (var ped in pedRegisterGreen)
                {
                    try { Debug.DrawSphere(ped.AbovePosition, 0.20f, System.Drawing.Color.Green); } catch { }
                }
                GameFiber.Yield();
            }
            catch { }
        }
    } catch (Exception e) { Game.LogTrivial("[LSPDFR TESTER]: " + e); }
});

 

 

to analyze when a ped is a cop and when they are busy or just ambient-busy.

 

this looks like here (in the Picture):

Spoiler

Bild1.thumb.jpg.8cd9088939d4efed97fa2177035f9409.jpg

 

By trying this code i often get an lspdfr crash 

Quote

Exception message: Processing cache while it's still in use - one or more subcalls may have caused the thread to yield

 

here is the full error message:

Spoiler

[10/22/2020 3:40:07 AM.942] LSPD First Response: ==============================
[10/22/2020 3:40:07 AM.942] LSPD First Response: UNHANDLED EXCEPTION DURING GAME FIBER TICK
[10/22/2020 3:40:07 AM.943] LSPD First Response: ------------------------------
[10/22/2020 3:40:07 AM.943] LSPD First Response: Origin: Game fiber "<UNNAMED THREAD>".
[10/22/2020 3:40:07 AM.944] LSPD First Response: ------------------------------
[10/22/2020 3:40:07 AM.944] LSPD First Response: Exception type: System.Exception
[10/22/2020 3:40:07 AM.946] LSPD First Response: Exception message: Processing cache while it's still in use - one or more subcalls may have caused the thread to yield
[10/22/2020 3:40:07 AM.946] LSPD First Response: ------------------------------
[10/22/2020 3:40:07 AM.947] LSPD First Response: Inner exceptions:
[10/22/2020 3:40:07 AM.947] LSPD First Response: ------------------------------
[10/22/2020 3:40:07 AM.948] LSPD First Response: Stack trace:
[10/22/2020 3:40:07 AM.949] LSPD First Response: at puKdGLPlzrKbIXGLcNCARcAOsBxt.rEjgHcfcQhkMKoukSNHcAepFBxJLB() in E:\GTA V\LSPD First Response\LSPD First Response\Engine\Scripting\Entities\CPedCache.cs:line 45
[10/22/2020 3:40:07 AM.949] at vxdgPkPcSgnhjDPQYfrMLZNJPsLW.rEjgHcfcQhkMKoukSNHcAepFBxJLB() in E:\GTA V\LSPD First Response\LSPD First Response\Engine\Main.cs:line 54
[10/22/2020 3:40:07 AM.951] at wlaMNAwUqzSeZxSmegYMTFkgvJeS.GUnnckBWEiqJWvXtSPtDHJsxWnvM() in E:\GTA V\LSPD First Response\LSPD First Response\Mod\LSPDFR.cs:line 797
[10/22/2020 3:40:07 AM.952] at Rage.GameFiber.Main()
[10/22/2020 3:40:07 AM.952] LSPD First Response: ==============================
[10/22/2020 3:40:07 AM.953] LSPD First Response: 
[10/22/2020 3:40:07 AM.957] LSPD First Response: [FATAL] Forced termination
[10/22/2020 3:40:07 AM.960] LSPD First Response: [TRACE] Released 0 entities from DefaultContentManager
[10/22/2020 3:40:08 AM.020] LSPD First Response: [INFO] LSPDFR has shut down
[10/22/2020 3:40:10 AM.243] LSPD First Response: [LSPDFR TESTER]: System.Threading.ThreadAbortException: Der Thread wurde abgebrochen.
[10/22/2020 3:40:10 AM.245] at lspdfrTesterPlugin.Main.<>c__DisplayClass4_0.<OnOnDutyStateChangedHandler>b__1() in D:\#UserData\Dokumente 2 - TB\Development\Visual Studio\Projects\lspdfrTesterPlugin\lspdfrTesterPlugin\Main.cs:line 163

 

 

so i extended the sleeps to give lspdfr more time. 

Now it does work for a few rounds but still lspdfr reports back with this exception.

Which is an actual problem for me because the way i wanted to use those functions is pretty similar to the one in the code.

For AmbientAICallouts i will need to check all surrounding peds (for now just in copcars) if they are busy.

If im doing that not something like this could happen: lspdfr suspect transport gets an AiCallout.

 

 

Questions:

- How would i use this function without destablizing lspdfr?

- @LMSWhy is even backup just an AmbientScenario 

( yellow = includeAmbientScenarios) (red = busy but not from AmbientScenarios) (green = not busy)

 

Thanks.

Edited by ziipzaaapM16A4

Take a look at my Plugins:

AmbientAICallouts: Ai get calls too. Callouts can turn into a backup request for the player [YouTube Link]

Search Vehicle Plugin: Simple and more Immersive Vehicle Search Plugin [YouTube Link]

What Was You Name Again?: Get the name of a Suspect even when arrested and placed in your Vehicle [YouTube Link]
Corpse Inspection:  Investigate the corpse. Interact and search for details in a more Cinematic way  [YouTube Link]
[WIP] EnvoirementalCallouts: A couple of Callouts and WorldEvents that are likely to happen to you while you're on duty [Youtube Link]

[OnHold] EMS Support: Be the First Responder of Medical Emergency's and do CPR on Patients [YouTube Link]

 

spacer.png

Checkout my Patreon for Early Access to my mods                                       checkout my Discord Server

Link to comment
Share on other sites

  • Management Team

You are most likely passing invalid handles to the API functions that will crash LSPDFR, which is then swallowed instead of being handled and/or logged so you won't notice that something went wrong, and thus corrupting the cache. The issue is you are getting 16 nearby peds, then sleeping and then using them without verifying they still exist (and sleeping again and using them again later, same issue).


We consider cops ambient if they are not specifically assigned to a chase, callout or suspect transport (there might be a few more I cannot think of right now). Backup units can be pulled away at any time and have a lower internal task priority.

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

Link to comment
Share on other sites

🤦‍♂️ yeah that fixed it. hmm i wonder why i let them sleep in the first place.

Edited by ziipzaaapM16A4

Take a look at my Plugins:

AmbientAICallouts: Ai get calls too. Callouts can turn into a backup request for the player [YouTube Link]

Search Vehicle Plugin: Simple and more Immersive Vehicle Search Plugin [YouTube Link]

What Was You Name Again?: Get the name of a Suspect even when arrested and placed in your Vehicle [YouTube Link]
Corpse Inspection:  Investigate the corpse. Interact and search for details in a more Cinematic way  [YouTube Link]
[WIP] EnvoirementalCallouts: A couple of Callouts and WorldEvents that are likely to happen to you while you're on duty [Youtube Link]

[OnHold] EMS Support: Be the First Responder of Medical Emergency's and do CPR on Patients [YouTube Link]

 

spacer.png

Checkout my Patreon for Early Access to my mods                                       checkout my Discord Server

Link to comment
Share on other sites

  • Management Team
1 hour ago, ziipzaaapM16A4 said:

yeah that fixed it. hmm i wonder why i let them sleep in the first place.

Glad to hear! Sleeping is not necessarily bad, as long as you check that the entity still exists afterwards 🙂 In fact, we do yield in some expensive loops in LSPDFR to make sure they do not run on just one game tick to prevent lagspikes and it definitely helps.

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

Link to comment
Share on other sites

  • The title was changed to [SOLVED] Overuse IsCopBusy()

thanks m8.  It looks really good rn.

Take a look at my Plugins:

AmbientAICallouts: Ai get calls too. Callouts can turn into a backup request for the player [YouTube Link]

Search Vehicle Plugin: Simple and more Immersive Vehicle Search Plugin [YouTube Link]

What Was You Name Again?: Get the name of a Suspect even when arrested and placed in your Vehicle [YouTube Link]
Corpse Inspection:  Investigate the corpse. Interact and search for details in a more Cinematic way  [YouTube Link]
[WIP] EnvoirementalCallouts: A couple of Callouts and WorldEvents that are likely to happen to you while you're on duty [Youtube Link]

[OnHold] EMS Support: Be the First Responder of Medical Emergency's and do CPR on Patients [YouTube Link]

 

spacer.png

Checkout my Patreon for Early Access to my mods                                       checkout my Discord Server

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...