Jump to content

[Tutorial] How to make a search area and refresh it when suspect leaves it.


Faya

Recommended Posts

I'm assuming you already have created a search area, but if you haven't yet, click the spoiler.

Spoiler
SearchArea = new Blip(SpawnPoint.Position, 60f);
SearchArea.Alpha = 0.5f;
SearchArea.Color = Color.FromArgb(240, 200, 80);
SearchArea.EnableRoute(Color.FromArgb(240, 200, 80));

The first line instantiates a new blip, the first parameter requires a location(Vector3), the second parameter requires a radius, to set the size of the SearchArea.

Alpha means transparancy, default is 1f. So I've set it to half as that.

240, 200, 80 is RGB; And the color is yellow.

EnableRoute means that it sets a waypoint to the blip(the blip is SearchArea).

 

Please check out this for the proper coloring of things:

Standardization of API Plugin Colors.

 

Okay, so first you want to create a private bool to check if it needs any refreshing, I will explain why later. Don't forget to set it to true.

private bool needsRefreshing = true;

 

Second, we're making an if-statement, we don't need to add "== true" since we already set true by default, normally it's always false.

if (Suspect.Position.DistanceTo(SpawnPoint) > 60f && needsRefreshing)

It checks if the suspect's position is further then the search area size, and if it still needs to be refreshed(which it does).

 

Now for the rest of the if-statement: the red parts describe what that line executes.

if (Suspect.Position.DistanceTo(SpawnPoint) > 60f && needsRefreshing)
{
   if (SearchArea.Exists()) { SearchArea.Delete(); } // Checks if SearchArea is still there, then it deletes it.
   SceneLocation = Suspect.Position.Around(10f, 30f); //Sets the SpawnPoint to a random position between 10 and 30, since the SpawnPoint is of no more use.
   SearchArea = new Blip(SpawnPoint, 60f);
   SearchArea.Alpha = 0.5f; // Sets the transparancy to half of the standard size.
   SearchArea.Color = Color.FromArgb(240, 200, 80); // Sets the color to yellow.
}

 

We're not done yet, We still have to make a second if-statement to check where the player is.

if (Game.LocalPlayer.Character.Position.DistanceTo(Suspect.Position) < 10f && needsRefreshing) // Executes when the player is close to the suspect and if it needs refreshing.
{
    while (true) // keeps executing while true
    {
        needsRefreshing = false; // Since the player found the Suspect, we don't need to refresh the SearchArea anymore, because that would be weird.
        if (SearchArea.Exists()) { SearchArea.Delete(); } // This is the old SearchArea, since the suspect is not in it anymore, it needs to be deleted.
        Game.LogTrivial("TutorialPlugin: Search Area doesn't need to be refreshed anymore."); // This is optional, but i do recommend you log things alot.
        break; // This stops the while loop from executing anymore, otherwise it is going to do this 1000x per second.
    }
}

 

If you need any support with coding, head over to "VincentsGM Modifications" Discord server, he helped me alot and there is alot of things you can learn in his #coding-help channel.

Server:

https://discord.gg/A7pJNY3HM5

Make sure to get the Developer role for you to see #coding-help.

Edited by Faya
Typo

🇳🇱

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