Jump to content
Sign in to follow this  
hogmason

creating an array of all locations using nearestLocations

Recommended Posts

how would I create an array of all nearby locations using


_location = nearestLocations [getPosATL center_pos, ["NameVillage","NameCity","NameCityCapital"], 25000];

and then call for a one of the locations at random selection.

Then once I used that location remove it from the array so I can not use that location again.

also when I call for the location I want to give players a hint with the locations name like


_RandomTownPosition = whatever the town selection is
hint parseText format["<t color=""#80FF00"">New Task Assigned at %1",_RandomTownPosition];

I know its a lot to ask for but honestly I just spent 7 hrs trying to get it and failed.

Share this post


Link to post
Share on other sites

Wouldn't something like this work?

_location = //code to select town
_randomtownlocation = _location select 0;
_location = _location - _randomtownlocation;

Since the random location given by _location is always the first index.

Share this post


Link to post
Share on other sites

Almost :)

_locations = nearestLocations [getPosATL center_pos, ["NameVillage","NameCity","NameCityCapital"], 25000];
_location = _locations call BIS_fnc_selectRandom;
_locations = _locations - [_location];


_locationPos = (position _location);
_locationName = (text _location);
hint parseText format["<t color=""#80FF00"">New Task Assigned at %1</t>", _locationName];

Edited by sxp2high
</t>

Share this post


Link to post
Share on other sites

cheers guys I think I got it from your help ;) ill just check

in my defines.sqf I have

AO_locations = nearestLocations [getPosATL Map_center, ["NameVillage","NameCity","NameCityCapital"], 25000]; 

then my code


//tested and this first part works
_location = AO_locations call BIS_fnc_selectRandom;
_locationPos = (position _location);
_locationName = (text _location);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
                   BELOW IS
         NOT TESTED JUST ASKING 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

//now later on when I need to can I use the following to remove the used location from AO_locations
AO_locations = AO_locations - [_location];

// then say to end the game when no locations remain can I use

if (AO_locations =0) then
{

//code to end game

};

Share this post


Link to post
Share on other sites

SWEET cheers man

BUT does this look right to you

// then say to end the game when no locations remain can I use

if (AO_locations =0) then

{

//code to end game

};

or should it be

// then say to end the game when no locations remain can I use

if (AO_locations ==0) then

{

//code to end game

};

Share this post


Link to post
Share on other sites

In the first example you're defining AO, the second example looks alot better, and it should work if it removes everything properly.

Share this post


Link to post
Share on other sites

Oh right, I didn't notice, you will have to use ==

= is for defining.

== is for comparing.

a = b;
if (a == b) then {};

Share this post


Link to post
Share on other sites

DOESNT WORK

I tried

defines.sqf --- launched by in my init call compile preprocessfile "common\defines.sqf";


AO_locations = nearestLocations [getPosATL Map_center, ["NameVillage","NameCity","NameCityCapital"], 25000];   

task.sqf


if (AO_locations == 0) then
{

hint "GAME OVER";

} else
{

  // my task code in here

 };

I get this error

Error ==: Type Array, expected Number,String,Object,Side,Group,Text,Config entry,Display (dialog),Control,Team member,Task,Location

Share this post


Link to post
Share on other sites

Try:

if (count AO_locations == 0) then
{
  hint "GAME OVER MAN, GAME OVER";
} else
{
  // my task code in here
};

You need to check the amount of elements in your array. At the moment, you're asking Arma to check if an array is equal to zero. An empty array would be [], not numerical :)

Share this post


Link to post
Share on other sites

FUNNY lol I just signed in to say I just thought and tried that and guess what it WORKS :)

Thanks any way Das and thanks to all that helped ;)

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  

×