Jump to content
Spriterfight

Check contonously nearest locations around player thenput them in an array

Recommended Posts

So basicaly i want a script that checks contonously the locations around the player in a 700m radius and stores them in an array but if he moves along the older locations will be replaced by the new locations.Any advice?

I would start witha  while {true} do {

_locations = [ getPos player nearestLocations[ towns,cities etc];

 

 

Share this post


Link to post
Share on other sites

Can you please be more specific on what you are trying to accomplish here?

 

Share this post


Link to post
Share on other sites

It is basically a custom spawn ai script that spawns ai on the nearest locations from the player,It is very custom and mission specific.But if i use this 

_locations = nearestLocations [ position player, ["Airport", "NameLocal", "NameVillage", "NameCity", "NameCityCapital","NameMarine"],worldsize*10];

_markerdist = 350;

_locaiton = _locations select 0;

while {true} do {
{
		if (player distance getPos _x < player distance getPos _locaiton) then
		{
			_locaiton = _x;
		};
		sleep 0.01;
	}foreach _locaitons;

	if (player distance getPos _locaiton < _markerdist) then
	{

_locaiton call fnc_spawnai;

}
else {sleep 5;};
};

this script uses the first nearest location to player and spawns only one group of enemy unit.What i want is that if the player is close to several towns then in each settlement spawn an ai group.

But to achieve this  i need a change in the script to store the nearest locations from the player then call the spawn funciton on it.

Share this post


Link to post
Share on other sites

why not just:

 

 

_locations = nearestLocations [ position player, ["Airport", "NameLocal", "NameVillage", "NameCity", "NameCityCapital","NameMarine"],worldsize*10];

_markerdist = 350;

_locaiton = _locations select 0;

while {true} do 
{
 {
		if (player distance getPos _x < _markerdist) then
		{
            _locaiton = _x;
			_locaiton call fnc_spawnai;
		};
                                                    
		sleep 0.01;
                                                    
 } foreach _locaitons;
};

 

  • Thanks 1

Share this post


Link to post
Share on other sites
55 minutes ago, gc8 said:

why not just:

 

 


_locations = nearestLocations [ position player, ["Airport", "NameLocal", "NameVillage", "NameCity", "NameCityCapital","NameMarine"],worldsize*10];

_markerdist = 350;

_locaiton = _locations select 0;

while {true} do 
{
 {
		if (player distance getPos _x < _markerdist) then
		{
            _locaiton = _x;
			_locaiton call fnc_spawnai;
		};
                                                    
		sleep 0.01;
                                                    
 } foreach _locaitons;
};

 

Wow.Thank you!

Share this post


Link to post
Share on other sites

I hope it works for you. I would still put a sleep inside the while loop so that the loop doesn't run too fast, slowing rest of the scripts down. Also for nearestLocations you should probably put center of the map there and not just "position player"

Share this post


Link to post
Share on other sites
47 minutes ago, gc8 said:

I hope it works for you. I would still put a sleep inside the while loop so that the loop doesn't run too fast, slowing rest of the scripts down. Also for nearestLocations you should probably put center of the map there and not just "position player"

I will try it and give you a feedback.

Share this post


Link to post
Share on other sites
52 minutes ago, gc8 said:

I hope it works for you. I would still put a sleep inside the while loop so that the loop doesn't run too fast, slowing rest of the scripts down. Also for nearestLocations you should probably put center of the map there and not just "position player"

I have a question can i use foreach in a if statement or i have to use count?

Share this post


Link to post
Share on other sites
4 minutes ago, Spriterfight said:

I have a question can i use foreach in a if statement or i have to use count?

 

I would use count

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

×