Jump to content
vissarion1917

How to identify the terrain of a certain coordinate

Recommended Posts

Hi everyone!

I am a noob on scripting but I am trying really hard to understand and practice as much as I can so here is a doubt I have.

I am creating random coordinates on the maps, and what I am trying to do is to identify what is on that specific coordinate. Is it a road, is it flat, is it a building, is it a forest, is it a rock, is it a hill,  is it a concealment position...?

I am trying to do it with the "nearestLocation" command and the "nearestObject" command but it doesn't really work. I just want to identify if the given coordinates refers to a concealment position, to a city, to a flat...

 

Thank you a lot!

Share this post


Link to post
Share on other sites

It's an open-ended question so there is no single command that will answer it. Here are a few powerful commands you can play around with:

Keep the radius small, compare their outputs and you'll find your answer 😉

Share this post


Link to post
Share on other sites
22 hours ago, _foley said:

It's an open-ended question so there is no single command that will answer it. Here are a few powerful commands you can play around with:

Keep the radius small, compare their outputs and you'll find your answer 😉

Thank you! "SelectBEstPlaces" seems to be the command I was looking for.

And now I have a pair of doubts about it.

 

Doubt 1

In the bohemia interactive page where this command is explained, it gives an example of its use, and states the following command:

myPlaces = selectBestPlaces [position player, 50, "meadow + 2*hills", 1, 5];

I do not know why he puts that "meadow+2*hills". Why not just "meadow" or "hills" why that strange formula and what does it mean?

 

Doubt 2

I have checked the bohemia interactive page of that command and I do not get clear what does that command return. I have checked on game and i t returns a lot of numbers and coordinates that I do not have any idea what are they refering to.

Ideally, I would like to receive the coordinates of what I am looking for. As an example, lets imagine that with "selectBestPlaces" I am searching for a meadow in a 50m radius from the position A. I would type that in the code:

myplace=selectBestPlaces[positionA, 50, "meadow", 1, 5];

thex=myplace select 1;
they=myplace select 2;
positionBravo=[thex,they];
_marker88=createMarker ["_marker88", positionBravo];
"_marker88" setMarkerType "mil_warning";
"_marker88" setMarkerColor "ColorBlue";

But it doesn't work for me. Any ideas?

 

 

Thanks!

Share this post


Link to post
Share on other sites

I am not in a position to test it at the moment, but it looks like your call to selectBestPlaces is right.

myplace=selectBestPlaces[positionA, 50, "meadow", 1, 5];

Assuming positionA is an [x,y,z] position then this should work.  The problem I see is that the return value will be an array of positions.  Something like [[x_0, y_0, z_0], [x_1, y_1, z_1], [x_2, y_2, z_2], ...].

The problem is that the return value of selectBestPlaces is actually an array like [[[x_0, y_0], score_0], [[x_1, y_1], score_1], [[x_2, y_2], score_2]] ...

Thus in your code

thex=myplace select 1;
they=myplace select 2;
positionBravo=[thex,they];

thex gets assigned with [x_1, y_1, z_1] and they gets assigned [x_2, y_2, z_2].  Thus positionBravo is now a list of two positions, [[x_1, y_1, z_1], [x_2, y_2, z_2]].

 

Instead, just replace those three lines with:

EDIT: Sorry, I was mistaken.  In that above snippet, positionBravo would end up with a list of two position, score pairs  [[[x_1, y_1], score_1], [[x_2, y_2], score_2]].  You can isolate just the first position like so:

// positionBravo = myplace select 0; // This won't work, gets a [[x, y], score] pair.

positionBravo = (myplace select 0) select 0;

Note that we start array selection indexing with 0, not 1.  That should get positionBravo assigned to the best "meadow" position found by selectBestPlaces within 50m.

As for how those expressions work, think of it like this:

 

There are ten "keywords": forest, trees, meadow, hills, houses, sea, night, rain, windy and deadBody. selectBestPlaces randomly scatters some test positions throughout its search radius.  Then, for each position, it would assign each one a score from 0 to 1. Like

Position 1:
forest   0.0
trees    0.5
meadow   0.2
hills    0.4
houses   0.2
sea      0.0
night    0.0
rain     0.0
windy    0.1
deadBody 0.0

How you compose the expression determines which scores are evaluated, and how the scores are used.  So "3*hills + trees" would evaluate the hills and trees scores of each position, and then weight the hills score 3 times as much when sorting the results.  The wiki page has a lot more information, features, and examples.

Incidentally this kind of thing is also the purpose of the scripts I recently released here as "ANIMA - AI for advanced position analysis using genetic algorithms".  With ANIMA you can work "under the hood", so to speak, and rather than giving it a keyword expression to rank positions chosen at random, the algorithm directly takes a list of functions (of a single "game object") that evaluate to each score, and actively evolves them over a number of generations to improve the results. These functions can be written as anything, so you could for instance count LOS to specific units.  Unfortunately there's a performance cost for this, and customizing it is more difficult than with selectBestPlaces.  It also currently only works in single player.  Still if you're interested in such things you might check it out.

 

Share this post


Link to post
Share on other sites
9 hours ago, dwringer said:

thex gets assigned with [x_1, y_1, z_1] and they gets assigned [x_2, y_2, z_2].  Thus positionBravo is now a list of two positions, [[x_1, y_1, z_1], [x_2, y_2, z_2]].

 

Instead, just replace those three lines with:

positionBravo = myPlace select 0;

Note that we start array selection indexing with 0, not 1.  That should get positionBravo assigned to the best "meadow" position found by selectBestPlaces within 50m.

Thank you for the reply!

I did exactly that, and in the line of

_marker88=createMarker ["_marker88", positionBravo];

I get the following error:

Vector type error. Number expected

 

Share this post


Link to post
Share on other sites
10 hours ago, dwringer said:

How you compose the expression determines which scores are evaluated, and how the scores are used.  So "3*hills + trees" would evaluate the hills and trees scores of each position, and then weight the hills score 3 times as much when sorting the results.  The wiki page has a lot more information, features, and examples

Thank you a lot for the reply!

 

In my formula, I put:

myplace=selectBestPlaces[positionA, 50, "meadow", 1, 5];

And always, the marker_88 puts at the bottom of the map, in the sea. But that does not make any sense to me

 

What am I doing wrong with selectBestPlaces command?

Share this post


Link to post
Share on other sites
2 hours ago, vissarion1917 said:

Thank you a lot for the reply!

 

In my formula, I put:


myplace=selectBestPlaces[positionA, 50, "meadow", 1, 5];

And always, the marker_88 puts at the bottom of the map, in the sea. But that does not make any sense to me

 

What am I doing wrong with selectBestPlaces command?


Sorry! I checked it out today and it actually returns something different than I thought.

The results are an array like [[[x_0, y_0], score_0], [[x_1, y_1], score_1], [[x_2, y_2], score_2]] ...

 

So, to pull the coordinate you want for setMarkerPos, an [x, y] pair, get it like so:

myplaces = selectBestPlaces [positionA, 50, "meadow", 1, 5];

positionBravo = (myplaces select 0) select 0;

Sorry about the confusion.  Basically just drill down an extra "select 0" to get the position out of the place result.

EDIT: Something else occurred to me that you might find useful.  A quick way to figure out what the return value of something looks like is to put a brief bit of code in the in-game Extended Debug Console that appears from the pause menu, I tested selectBestPlaces with:

myPlaces = selectBestPlaces [position player, 50, "meadow", 1, 5];
hint format ["%1", myPlaces];

I do most of my debugging with hint statements either throughout the code or directly from the console like this.

 

Share this post


Link to post
Share on other sites
9 hours ago, dwringer said:


Sorry! I checked it out today and it actually returns something different than I thought.

The results are an array like [[[x_0, y_0], score_0], [[x_1, y_1], score_1], [[x_2, y_2], score_2]] ...

 

So, to pull the coordinate you want for setMarkerPos, an [x, y] pair, get it like so:


myplaces = selectBestPlaces [positionA, 50, "meadow", 1, 5];

positionBravo = (myplaces select 0) select 0;

Sorry about the confusion.  Basically just drill down an extra "select 0" to get the position out of the place result.

EDIT: Something else occurred to me that you might find useful.  A quick way to figure out what the return value of something looks like is to put a brief bit of code in the in-game Extended Debug Console that appears from the pause menu, I tested selectBestPlaces with:


myPlaces = selectBestPlaces [position player, 50, "meadow", 1, 5];
hint format ["%1", myPlaces];

I do most of my debugging with hint statements either throughout the code or directly from the console like this.

 

 

Yeah I know it, I tried it and after trying I finally realized what you just have said, that it is needed an extra "select" to obtain the coordinates and yes, I also validated it with a hint.

But thank you anyways for replying again!

 

No the doubt I have is this one.

11 hours ago, vissarion1917 said:

Thank you a lot for the reply!

 

In my formula, I put:


myplace=selectBestPlaces[positionA, 50, "meadow", 1, 5];

And always, the marker_88 puts at the bottom of the map, in the sea. But that does not make any sense to me

 

What am I doing wrong with selectBestPlaces command?

I have tried inizialiting the mission many many times and in everytime the _marker88 puts at the bottom of the map in the sea, every single time. It seems that I am using wrong the "selectBestPlaces" command

Share this post


Link to post
Share on other sites
24 minutes ago, vissarion1917 said:

What am I doing wrong

myplace=selectBestPlaces[positionA, 50, "meadow", 1, 5];

 

My first thought would be that there is no "meadow" location within 50 meters of your specified position.

Share this post


Link to post
Share on other sites
23 minutes ago, Harzach said:

myplace=selectBestPlaces[positionA, 50, "meadow", 1, 5];

 

My first thought would be that there is no "meadow" location within 50 meters of your specified position.

I have done it with 300m over and over again and the same result

 

Also I have tried several options such as:

(meadow)*(1-sea)

(1+meadow)

(meadow)*(trees)*(1-sea)

(meadow)*(1+trees)*(1-sea)

(trees)*(forest)*(1-sea)

(trees)*(1+forest)*(1-sea)

 

And always, the _marker88 appears in the exact same spot: at the bottom of the map in the sea. The same result

Share this post


Link to post
Share on other sites

As far as I'm aware, selectBestPlaces will ALWAYS return a list of places, even if the score for "meadow" is extremely low.  So I don't believe the problem is there.  Also, above, your createMarker code looks alright.  So, could you put a hint statement somewhere in the code right before you create the marker?  Something like:

hint format ["%1", [positionA, positionBravo]];

Then make sure both positionA and positionBravo are returning [<x>, <y>] pairs.
If they are then please paste the entire section of your marker creation code because we must be missing something.

Share this post


Link to post
Share on other sites

Dunno. Works fine here. Something is wrong, please show ALL of your code.

 

Test code:

_myPlaces = [];
for "_i" from 0 to 499 do {
	_myPlace = selectBestPlaces [positionA, 50, "meadow", 1, 5];
	_pos = (_myplace#0)#0;
	_myPlaces pushBackUnique _pos;
};

systemChat str count _myplaces;

{
	_name = "marker_" + str _x;
	_mkr = createMarker [_name, _x];
	_mkr setMarkerShape "ICON";
	_mkr setMarkerType "hd_dot";
} forEach _myPlaces

Returned 500 positions within 50 meters radius, note that it avoided the area near the large trees:

 

R4ZbBel.png

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

×