Jump to content
Sign in to follow this  
jakkob4682

how to get the nearestLocation of a unit no matter where he is at on the map?

Recommended Posts

i.e. I want to be able to check nearestLocations no matter where I'm at and if I move to another position I want it to update, so that if I get within distance of the location then I can perform another action.

Share this post


Link to post
Share on other sites

Description of desired effect is still a bit unclear to me, but according to our previous conversation, code, that will look for closest town location for every western group currently on map (to make it cheaper for CPU, for all units only minor changes needed, but will be heavier then) and perform any needed action for found that way location position, refreshed every 30 seconds, may look eg like here (not tested):

RYD_TownCenter = 
{
private ["_pos","_nearCities","_nearestCity","_townPos","_locPos"];

_pos = _this select 0;//unit's position

_nearestCity = locationNull;
_locPos = [];

_nearCities = nearestLocations [_pos, ["NameCityCapital","NameCity","NameVillage"],5000];

if ((count _nearCities) > 0) then
	{
	_nearestCity = _nearCities select 0;
	_locPos = position _nearestCity
	};

_locPos
}; 
//if should be refreshed, then loop is needed, unless should be refreshed manually, only on demand in game
while {true} do
{
sleep 30;	

	{
	if ((side _x) == west) then
		{
		_locPos = [getPosATL (leader _x)] call RYD_TownCenter;

		if ((count _locPos) > 0) then
			{
			//any other stuff for that locPos here
			}
		}
	}
foreach AllGroups
};

Perhaps 5000 meters radius is too big, and can be refreshed with bigger interval - if so, better, as would be less heavy for CPU then.

Share this post


Link to post
Share on other sites

nearestLocation is supposedly sorted, so RYD_TownCenter could probably be simplified into something like this:

RYD_TownCenter = {
getPos (((nearestLocations [_this select 0, ["NameCityCapital","NameCity","NameVillage"],5000]) + [objNull]) select 0)
}

Share this post


Link to post
Share on other sites

all right so I have another question then.. I have a function that auto populates an area around the town center(CityCenter) of a city when a west unit gets within certain range, basically what it does is gets the number of units and then creates _x amount of ieds in random position within a given radius, and then adds triggers to each ied position to trigger the explosions. However, I've tried using an if-loop, waitUntil{!isNull}, while loops, etc but it either only fires once or it fires indefinitely til the game crashes(stopped using the while loop because of this). So how would I use

_CC = locationNull;
_nCC = [_x,["CityCenter"],500];
- what kind of loop to do a continous check? and then only fire the ied function only once?

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  

×