Jump to content

[Solved] Air Units Endlessly Spawning?


OJS

Recommended Posts

Hello folks, I almost finished my first callout plugin when all of a sudden, while testing it. I show up on scene and the largest frame drop ever in my entire history of playing the game happens. The game won't stop spawning backup units. I only told it to spawn two. Here is my code:

 

        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 one air unit and one local patrol unit to join 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);
                }
            }
        }

 

 

Edited by OfficerJohnnyShumway
Question has been solved
Link to comment
Share on other sites

You keep creating a new pursuit instance and requesting backup on every tick/frame while your on scene. Easiest solution is to use a boolean variable.

bool bSomeGenericBool = false;

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 (!bSomeGenericBool && Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)
	{
		bSomeGenericBool = true;
		
		//Create the pursuit.
		this.pursuit = Functions.CreatePursuit();

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

		//Request backup for one air unit and one local patrol unit to join 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);
	}
}

 

Link to comment
Share on other sites

1 hour ago, OJdoesIt said:

You keep creating a new pursuit instance and requesting backup on every tick/frame while your on scene. Easiest solution is to use a boolean variable.


bool bSomeGenericBool = false;

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 (!bSomeGenericBool && Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)
	{
		bSomeGenericBool = true;
		
		//Create the pursuit.
		this.pursuit = Functions.CreatePursuit();

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

		//Request backup for one air unit and one local patrol unit to join 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);
	}
}

 

Thanks m8, I will try it in a little bit.

Link to comment
Share on other sites

2 hours ago, OJdoesIt said:

You keep creating a new pursuit instance and requesting backup on every tick/frame while your on scene. Easiest solution is to use a boolean variable.


bool bSomeGenericBool = false;

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 (!bSomeGenericBool && Game.LocalPlayer.Character.Position.DistanceTo(SpawnPoint) <= 100f)
	{
		bSomeGenericBool = true;
		
		//Create the pursuit.
		this.pursuit = Functions.CreatePursuit();

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

		//Request backup for one air unit and one local patrol unit to join 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);
	}
}

 

It worked m8, thank you so much! 

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