Jump to content
Sign in to follow this  
jakkob4682

Function to find the center of a town that a unit is in?

Recommended Posts

Perhaps one of these:

1. If "in town" means inside town location:

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

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

_townPos = [];
_nearestCity = locationNull;

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

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

	if (_pos in _nearestCity) then 
		{
		_townPos = position _nearestCity
		}
	};

_townPos
};

2. If "in town" means not further from center, than passed distance:

RYD_TownCenterB = 
{
private ["_pos","_nearCities","_nearestCity","_rds","_townPos","_tpos"];

_pos = _this select 0;
_rds = _this select 1;

_townPos = [];
_nearestCity = locationNull;

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

if ((count _nearCities) > 0) then
	{
	_nearestCity = _nearCities select 0;
	_tpos = position _nearestCity;
	_tpos = [_tpos select 0,_tpos select 1,0];

	if ((_pos distance _tpos) <= _rds) then 
		{
		_townPos = position _nearestCity;
		}
	};

_townPos
};

Note, that location position is on the sea level given in ATL, so height is usual a negative value.

Share this post


Link to post
Share on other sites

The first one is what I'm looking for, I could set _pos = position player and just run in it from the init.sqf right?

Share this post


Link to post
Share on other sites
I could set _pos = position player and just run in it from the init.sqf right?

Right. :)

Share this post


Link to post
Share on other sites

how do i get the actual center of the town though? I guess the actual question is how to get the area of the town from config files dynamically

Share this post


Link to post
Share on other sites

I believe this is what CityCenter is.

From the config:

Class CityCenter : Strategic

name="Center of the village/town/city";

logicClass="LocationLogicCityCenter";

Share this post


Link to post
Share on other sites

@Panther42

whats the command to find the name of a town?_name = getText(), but theres no citycenter in the config for any of the towns. They do how ever have an area defined in the configs for each town, so I guess that brings up a few more questions.

1. How do you get the name of the current map you're on

2. How do you get the name of a city

3. How do you get the area

(I'm not very experienced reading from the configs or getting info from the configs which all 3 of those relate too)

4. Find the center of a circle with the given area

Share this post


Link to post
Share on other sites

CityCenter is a logic created by the game. You can use it in your nearestLocation, or nearestLocations search.

I'm not at my home computer, but I'll try to answer what I can.

1. worldName

2. nearestLocation or nearestLocations should return the names.

For example, if you search using NameVillage near Kamenyy on Utes, the position is:

position[]={3334.68,4445.62}; area is 100x100

if you search using CityCenter near Kamenyy, the position is:

position[]={3381.94,4399.93}; area is 10x10, which should give you the center position. Both should return Kamenyy, but I can't test to verify the output

Share this post


Link to post
Share on other sites

while {true} do 
{
_westUnits = [];
{
	if (side _x==west) then 
	{
	_westUnits = _westUnits + [_x];
	_townCenter = nearestLocations [getPos _x,["CityCenter"],500];
	};
}forEach _westunits;

if (!isNull _townCenter) then {}
}forEach allUnits;

?

Edited by jakkob4682
formatting

Share this post


Link to post
Share on other sites

I wouldn't run the nearestLocations in a loop like that. It could be expensive for resources.

What exactly are you trying to do?

Share this post


Link to post
Share on other sites

find the nearest to any blufor unit within 500 yards, then spawn some ied's with them. when the trigger activates to create the explosion I want to spawn a group nearby to ambush the blufor unit if he is in a group, or spawn an enemy sniper if there's less than x amount of friendly units nearby

---------- Post added at 04:07 ---------- Previous post was at 04:05 ----------

The reason I want to use CityCenter is because I'm trying to make it as generic as I can so its just a plugin script that doesnt require a user defined position.

you said not to run it in a loop. so I would just eliminate the while-do loop and call it as a function to make it more efficient?

Edited by jakkob4682

Share this post


Link to post
Share on other sites

I decided just to run it in a loop using nearestLocations, works well(assuming mission isnt loaded w/ addons and/or scripts). Just trying to work out a solution to check nearestLocations for all west units now.

Share this post


Link to post
Share on other sites

I can find the city center, but the script only runs once and doesn't update. I'm trying to get it to run so that if you go to another town then it'll run the script again. i.e. I have a function made that populates the area of the city center with ied's and spawns a militia squad, but that function only runs once and when I move to another town it doesn't fire again.

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  

×