Jump to content

MY Callout pack causes my game to crash


Recommended Posts

hi everyone 

I am currently developing a callout pack for my mod  Security+ REVAMPED 1.3.2 but I am getting the following after accepting the only callout which is a pursuit in progress 

my game spawns in a lot of backup and then crashes 

i have included RagePluginHook.logmy rage log  and have included the code from my callout 

Spoiler

 public override void Process()
        {
            base.Process();
            {
                //This states that if the player is less than or equal to 100 meters away from SpawnPoint, then it will do whatever is in the brackets.
                if (Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)
                {
                    //Create the pursuit.
                    this.pursuit = Functions.CreatePursuit();

                    //Add mySuspect to the pursuit.
                    Functions.AddPedToPursuit(this.pursuit, mySuspect);

                    //Request Backup for an air unit and one local unit to join into the pursuit.
                    Functions.RequestBackup(Game.LocalPlayer.Character.Position, LSPD_First_Response.EBackupResponseType.Pursuit, LSPD_First_Response.EBackupUnitType.AirUnit);
                    Functions.RequestBackup(Game.LocalPlayer.Character.Position, LSPD_First_Response.EBackupResponseType.Pursuit, LSPD_First_Response.EBackupUnitType.LocalUnit);
                }
            }
        }

 

O.BUTLER

Link to comment
Share on other sites

Hey @Owen.butler17,

Hoping I can lend some experience here!

 

First up, Process() is looping, so unlike OnCalloutAccepted() and End() which are only executed once, Process() keeps iterating over while your callout is running.

 

According to your logic, if the player is within 100f of the spawn point, you are continuously creating a pursuit & requesting backup. And that code keeps looping, and before you know it you've tried to request over a 100 backup units for your 100 pursuits & the game crashes!

 

What you can do here to fix this is add a simple boolean (true or false) to prevent this code from executing more than once.

 

At the top of your class, you can add: private bool IsPursuitRunning = false;

And when you create a pursuit, you can set IsPursuitRunning = true;

 

Then in your if statement, change it to include your boolean check:

if (!IsPursuitRunning && Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)

 

I hope this helps you! 😄 Best of luck.

 

Prefer support on Discord? Want your log automatically read? Join my server to receive live support!

https://discord.gg/gyw5rDHCfr

 

Developer of Callout Pack 686 Callouts & Discord Bot 686 Utilities.

 

Link to comment
Share on other sites

21 hours ago, Owen.butler17 said:

if (Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)

You say that the pursuit should be created if PLC < 100f form a vector-point
That will be true as long as PLC is that, and that will make your plugin create pursuit over and over.
Make a boolean short-circuit shouldCreatePursuit
 

if (Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f && shouldCreatePursuit) {

shouldCreatePursuit=false //only create pursuit once

:

:
}

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

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

Link to comment
Share on other sites

2 minutes ago, GTAbear said:
if (Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f && shouldCreatePursuit) {

I'm sidetracking a bit here 😅 but I would - as in my example - do the boolean check first.

 

Your if statement contains important order of operations, and your code will continue to check the distance even if a pursuit should not be created. If you check if a pursuit should be created first, that means you are only performing distance calculations if you actually need them.

 

Maybe that's not something you considered, but I would certainly recommend it nonetheless! 😄 

Prefer support on Discord? Want your log automatically read? Join my server to receive live support!

https://discord.gg/gyw5rDHCfr

 

Developer of Callout Pack 686 Callouts & Discord Bot 686 Utilities.

 

Link to comment
Share on other sites

8 hours ago, Charlie686 said:

Hey @Owen.butler17,

Hoping I can lend some experience here!

 

First up, Process() is looping, so unlike OnCalloutAccepted() and End() which are only executed once, Process() keeps iterating over while your callout is running.

 

According to your logic, if the player is within 100f of the spawn point, you are continuously creating a pursuit & requesting backup. And that code keeps looping, and before you know it you've tried to request over a 100 backup units for your 100 pursuits & the game crashes!

 

What you can do here to fix this is add a simple boolean (true or false) to prevent this code from executing more than once.

 

At the top of your class, you can add: private bool IsPursuitRunning = false;

And when you create a pursuit, you can set IsPursuitRunning = true;

 

Then in your if statement, change it to include your boolean check:

if (!IsPursuitRunning && Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)

 

I hope this helps you! 😄 Best of luck.

 

@Charlie686I just want to clarify when you say 

At the top of your class, you can add: private bool IsPursuitRunning = false;    where do put this as it caused errors in my code 

And when you create a pursuit, you can set IsPursuitRunning = true;

 

Then in your if statement, change it to include your boolean check:

if (!IsPursuitRunning && Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)

O.BUTLER

Link to comment
Share on other sites

14 minutes ago, Owen.butler17 said:

@Charlie686I just want to clarify when you say 

At the top of your class, you can add: private bool IsPursuitRunning = false;    where do put this as it caused errors in my code 

And when you create a pursuit, you can set IsPursuitRunning = true;

 

Then in your if statement, change it to include your boolean check:

if (!IsPursuitRunning && Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)

@Charlie686Never mind I figured it out hopefully it works 

O.BUTLER

Link to comment
Share on other sites

8 hours ago, Owen.butler17 said:

@Charlie686Never mind I figured it out hopefully it works 

Let me know! If you need me to clarify / explain anything else, I'd be happy to. 😄

Prefer support on Discord? Want your log automatically read? Join my server to receive live support!

https://discord.gg/gyw5rDHCfr

 

Developer of Callout Pack 686 Callouts & Discord Bot 686 Utilities.

 

Link to comment
Share on other sites

22 hours ago, Charlie686 said:

do the boolean check first.

Absolutely!

if (shouldCreatePursuit && Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f ) { shouldCreatePursuit=false //only create pursuit once
:
:

}



would be the correct way to do it
I btw did not see your post, i think we almost posted simultaneous though you were a tad faster 😛
 

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

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

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