Spriterfight 10 Posted October 1, 2020 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
gc8 977 Posted October 1, 2020 Can you please be more specific on what you are trying to accomplish here? Share this post Link to post Share on other sites
Spriterfight 10 Posted October 1, 2020 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
gc8 977 Posted October 1, 2020 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; }; 1 Share this post Link to post Share on other sites
Spriterfight 10 Posted October 1, 2020 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
gc8 977 Posted October 1, 2020 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
Spriterfight 10 Posted October 1, 2020 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
Spriterfight 10 Posted October 1, 2020 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
gc8 977 Posted October 1, 2020 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