Replies: 5 (Who?), Viewed: 211 times.
Instructor
Original Poster
#1 Old 7th Jun 2021 at 12:18 AM Last edited by echoweaver : 7th Jun 2021 at 2:09 AM.
Default Find nearest body of water?
Given an active sim, is it possible to find the nearest body of water?

ETA: I see a method GlobalFunctions.FindGoodLocationNearby, which seems promising, though I'm not clear how I might call it.

Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
Advertisement
Field Researcher
#2 Old 7th Jun 2021 at 4:27 PM Last edited by gamefreak130 : 7th Jun 2021 at 6:04 PM.
You could try World.GetNearestSwimmingPoint(). It takes a Vector3 position and returns a boolean representing whether the search succeeded, plus two "ref" variables: a Vector3 representing a point on the shoreline, and another Vector3 representing...some other point in the water, I'm not entirely sure. I don't think it would work for pools, but it should work for ponds and oceans both on and off lots.

Take a look at the Run method of FishHere for an example.

Code:
Vector3 shorePos = Vector3.Invalid;
Vector3 oceanPos = Vector3.Invalid;
if (!World.GetNearestSwimmingPoint(sim.Position, ref shorePos, ref oceanPos))
{
    return false;
}

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Field Researcher
#3 Old 7th Jun 2021 at 5:44 PM
gamefreak130's solution should work but i think only for water a sim can swin in.

if that is the case here is something you could also try (i did not test it)

Code:
		public static IPond GetNearestWater(Vector3 point)
		{
			IPond result = null;
			float num = float.MaxValue;
			IPond[] ponds = Sims3.Gameplay.Queries.GetObjects<IPond>();
			foreach (IPond DHMOLocation in ponds)
			{

				float num2 = (point - ((GameObject)DHMOLocation).Position).LengthSqr();
					if (num2 < num)
					{
						result = DHMOLocation;
						num = num2;
					}			
			}
			return result;
		}
Instructor
Original Poster
#4 Old 7th Jun 2021 at 7:41 PM
This is incredibly useful. Thank you!

I'm not sure if I can use GetNearestSwimmingPoint, though, because I have no idea where there might be a body of water. I have a sim's location, and I need to find if there IS a body of water nearby (for some definition of nearby) and then try to route to it. So I don't know how I'd get the Vectors.

I'm going to try Battery's query against the IPond interface. I basically follow the code example, but I'm beyond the edge of my knowledge here .

Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
Instructor
Original Poster
#5 Old 9th Jun 2021 at 4:55 PM
@Battery That pond locator worked as written! Thank you!

Echo Weaver's Simblr: http://echoweaver.tumblr.com/
A portrait in stubbornness - Playing the same legacy since 2009
Sample a Brave Legacy: http://sims3sample.illation.net
Test Subject
#6 Old 9th Jun 2021 at 8:03 PM
Thank you so much
Back to top