Jump to content
PNWParksFan

Detect if World.GetStreetName is actually nearest street?

Recommended Posts

World.GetStreetName returns the name of the nearest named street, but does not indicate how far away that is, or if a closer road exists which is unnamed. I'd like to be able to detect if a Vector3 location is on or near a road with a particular name - and ideally be able to tell how far away they are from the nearest point on the nearest named road. 

Using the native IS_POINT_ON_ROAD you can tell if the location is on a road, but that returns true if the point is on any road (or even dirt path). Using GetStreetName always returns a name even if you're in the middle of the desert far from any roads. Using GetNextPositionOnStreet and checking the distance from the point of interest to that point helps if the next position is on the named street, but if you're on an unnamed street then the next position is often also on the unnamed street and you're back to the same issue. 

So, does anybody have suggestions for a reliable way to detect the nearest named street, and how far away a given point is from the nearest named street?

Share this post


Link to post
Share on other sites

You lost me with what you're trying to achieve here. Especially the part about Vectors. If you know the Vector location why don't you just use Pythagoras theorem to calculate the distance between the player and that location?

As for the name of the street there is a native that gets the name of a street at given coordinates. 

void GET_STREET_NAME_AT_COORD(float x, float y, float z, Hash *streetName,
  Hash *crossingRoad) // 0x2EB41072B4C1E4C0 0xDEBEEFCF

 

Of course you need to enable the use of unsafe contexts because you're messing with pointers here. Check the natives database, http://www.dev-c.com/nativedb/
But by doing this and acquiring the string for that road name you could then just pass it to an if statement to determine if it was the one you were looking for.

Share this post


Link to post
Share on other sites

I see that my question wasn't entirely clear. Here's an image to illustrate what I'm talking about: 

map.png.58f84b3b71884786d1148e2bce1c67ca

The issue is that both the RPH World.GetStreetName and the native GET_STREET_NAME_AT_COORD return the name for the nearest street that has a name, but that street may actually be quite far from the point of interest (for example, the purple X in the image above). You can't just use GetStreetName because you may not even be on a street at all. You also can't just check for IS_POINT_ON_ROAD because many points are on roads which are unnamed, like the red/blue X shown in the image. If you try to get the name at the red X, you get Great Ocean Hwy. If you try to find the next position on street, you get a point basically right next to it on the same unnamed road, which will also tell you the name is Great Ocean Hwy, even though you aren't on the highway at all. 

What I'd like to be able to do is determine how far away the nearest named road is from a given point, and what the name is.

I can figure out how far away the nearest road is, and I can figure out the name of the nearest named road, but those two roads may not be the same because of how many unnamed roads there are. 

Share this post


Link to post
Share on other sites
58 minutes ago, PNWParksFan said:

What I'd like to be able to do is determine how far away the nearest named road is from a given point, and what the name is.

I can figure out how far away the nearest road is, and I can figure out the name of the nearest named road, but those two roads may not be the same because of how many unnamed roads there are. 

Well I'm not 100% sure still. If I have you interpreted right I don't know if it's possible.

Assuming all unnamed roads are alleyways or dirt racks you could always look for the closest vehicle node, specifying only asphalt option (or use the other native for major vehicle nodes)

BOOL GET_CLOSEST_VEHICLE_NODE(float x, float y, float z, Vector3 *outPosition,
  int nodeType, float p5, float p6)
// 0x240A18690AE96513 0x6F5F1E6C

 

This would give you a Vector location of the nearest main road if you gave the right nodetype. Combine this with the name of road at coords would give you the name and the distance could then be calculated as per usual using pythag.
Again though it's main roads. So it depends on how rockstar decided to name roads which I obviously have no idea.

Am I on the right lines here or am I still not understanding you?

Share this post


Link to post
Share on other sites
12 hours ago, LukeD said:

Well I'm not 100% sure still. If I have you interpreted right I don't know if it's possible.

Assuming all unnamed roads are alleyways or dirt racks you could always look for the closest vehicle node, specifying only asphalt option (or use the other native for major vehicle nodes)


BOOL GET_CLOSEST_VEHICLE_NODE(float x, float y, float z, Vector3 *outPosition,
  int nodeType, float p5, float p6)
// 0x240A18690AE96513 0x6F5F1E6C

 

This would give you a Vector location of the nearest main road if you gave the right nodetype. Combine this with the name of road at coords would give you the name and the distance could then be calculated as per usual using pythag.
Again though it's main roads. So it depends on how rockstar decided to name roads which I obviously have no idea.

Am I on the right lines here or am I still not understanding you?

You've got the right idea for what I'm looking for. I agree that it seems it may not be possible. Major vehicle nodes still seems to pick up points on unnamed roads, so that doesn't work. Using the asphalt filter is effective, although there are a handful of named dirt roads out in the Senora Desert and Raton Canyon areas (and possibly elsewhere too). I'll just have to make do with this combination of natives to do a best approximation. 

If anybody can figure out a reliable way to actually figure this out I'd be thrilled to hear!

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

×