Jump to content
Sign in to follow this  
Luigi4518

Random closest spawn-point from coordinate list?

Recommended Posts

Currently I have a system for calling random spawn-points using a set of set coordinates using 'new random().next(x, x); Unfortunately this system gets buggy and can select points from any point on the map which often leads to either the suspect escaping instantly and/or lspdfr crashing.

I'm hoping somebody around here would be able to point me in the right directing as to setting up a list containing the preset coordinates that can be randomly selected from within a maximum distance restriction.

Share this post


Link to post
Share on other sites

You may want to try one of these approaches:

  • After randomly getting a point, check if the distance exceeds your maximum distance. If so, get a new random point. Do this until you have found a valid point (adding some kind of maximum number of attempts is a good idea btw).
  • From a maths point of view, you could apply the closest pair of points problem to this. Yours is slighty different in the regard that you allow multiple points within a range, but a little altered algorithm should work here. Note that bruting takes O(n²) here, so I'd go for a divide and conquer algorithm, which should take O(n log n).

Share this post


Link to post
Share on other sites

If you simply need a location that's on a valid street, I'd recommend using the following:

Vector3 SpawnPoint= World.GetNextPositionOnStreet(Game.LocalPlayer.Character.Position.Around(radius));

If you have a list of specific spawn points you want to select from, LMS has explained it above. If you need to check the distance, I recommend using this:

if (Vector3.Distance(Game.LocalPlayer.Character.Position, SpawnPoint)< radius){}

Hope it helps!

Share this post


Link to post
Share on other sites

Somethings not working (Usually my code) as now its throwing a fit. It doesn't limit it by distance but now spawns the callout in only one place using old code that isn't even in the callout now.

Would it help if I paste the callout or part of it here?

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×