Jump to content
Sign in to follow this  
HateDread

Finding Nearest Town + Case Switch

Recommended Posts

Howdy all,

I'm trying to figure out how to calculate the nearest town to the player, so I can spawn things I want them to see there (basically like what the Civilian Module does - spawning only in the nearest town to the player).

After this, I'm hoping to use the nearest town's name in a case-switch or similar comparison, or using it within a script, as a variable (like _NearestTown), so I can use the nearest town within a script, in future.

Any ideas how to get its name, then use it in a script?

Cheers,

- HateDread.

Share this post


Link to post
Share on other sites

Thanks :)

But how do I utilise this, exactly? I can't see how to compare it, or use it in a case-switch?

Share this post


Link to post
Share on other sites
fncGetClosestTown = {
 private ["_pos","_locations","_closest"];

 _pos = _this;
 if (typename _pos == typename objNull) then {_pos = getpos _pos};
 _locations = [["NameCityCapital","NameCity","NameVillage"],[_pos,100000]] call BIS_fnc_locations;
 _closest = objNull;

 if (count _locations > 0) then {
   _closest = _locations select 0;
   {
     if (_x distance _pos < _closest distance _pos) then {
       _closest = _x;
     };
   } foreach _locations;
 };
 _closest
};

loc = player call fncGetClosestTown;
hint (loc getvariable "name");

Share this post


Link to post
Share on other sites
_closesttown = (nearestLocations [player,["NameCityCapital","NameCity","NameVillage"],10000]) select 0;

_town_name = text _closesttown;
_town_pos = position _closesttown;

Edited by Bon
  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×