Jump to content
Sign in to follow this  
f2k sel

Is there a way to find a marker

Recommended Posts

I was just wondering it there a way to find the nearest marker.

I haven't been able to find an example so I'm thinking there isn't.

Share this post


Link to post
Share on other sites

My script: (old one so dunno if theres a better way to do this)

// get_nearestmarker.sqf
/*
- returns nearest marker of an array
- returns empty string if nothing found
*/

private ["_nearest","_break","_array","_pos","_i","_marker"];

_nearest = "";
_pos = _this select 0;
_array = _this select 1;

_i = count _array - 1;

//if array isnt empty use last array marker as nearest for a start (if he exists):
if (_i > -1) then {_nearest = _array select _i;};
if ((getmarkerpos _nearest) select 0 == 0) then {_nearest = "";}; 

//search through rest of array for nearer markers than _nearest:
//(dont do if _array has only 1 marker)
while {_i > 0} do
{
_i = _i - 1;
_marker = _array select _i;
//compare distances
if ( ((getmarkerpos _marker) distance _pos) < ((getmarkerpos _nearest) distance _pos) ) then
{
	_nearest = _marker;
//		player sidechat format["%1 is nearest now",_nearest]
};
};

//RETURN:
_nearest

call like [my position, array_with_markers] or [ [x,y,z],[marker1,marker2,marker3, ... ] ]

Hope this works for you

Share this post


Link to post
Share on other sites

OT:

There is no command called allMarkers afaik in Arma2, so only way is to track markers created.

to get nearest marker from a global array named All_My_Markers:

_unit = _this;
_dist = 999999999;
_marker = "";
{
_range = ((getMarkerPos _x) distance (vehicle _unit));
if (_range < _dist) then {_dist = _range; _marker = _x};
} foreach All_My_Markers;
hint format["nearest marker is %1",_marker];

this was a crasy and a little fun experiment,

for finding markers that have not been "tracked" by mission creator:

the actual use of this is pretty much non existing.

i placed 2 markers named "here" and "no45", limiting my "code cracker" to max 4 letters only using letters and numbers, no underscores or anything extra.

it took 94 seconds to return an array with ["here","no45"]

that was done over 1.926223e 006 variations.

so the usability is pretty much non existing, but it will find any unknown "marker" within the conditions, can be modified to support _ and bigger size name, but i asume the time will increase immensly with any new addition.

script used was this in a radio triggers on act:

_null = [] spawn {

_not = true;
_all = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","0"];
_marker = "";
_markers = [];
_cnt = 0;

while {_not} do {
{
	_marker = format["%1",_x];
	if ((getMarkerType _marker) != "") then {_markers = _markers + [_marker]};
	_cnt = _cnt + 1; sleep 0.00001;
	{
		_marker1 = format["%1%2",_marker,_x];
		if ((getMarkerType _marker1) != "") then {_markers = _markers + [_marker1]};
		_cnt = _cnt + 1; sleep 0.00001;
		{
			_marker2 = format["%1%2",_marker1,_x];
			if ((getMarkerType _marker2) != "") then {_markers = _markers + [_marker2]};
			_cnt = _cnt + 1; sleep 0.00001;
			{
				_marker3 = format["%1%2",_marker2,_x];
				if ((getMarkerType _marker3) != "") then {_markers = _markers + [_marker3]};
				_cnt = _cnt + 1; sleep 0.00001;
			} foreach _all;
		} foreach _all;
	} foreach _all;
} foreach _all;
_not = false;
hintc format["%1 and time to complete is %2 and amount of variations is %3",_markers,time,_cnt];
};

};

Note: i added the sleep so the script would not stall, but it works without, and then the time is roughly 83 seconds, using for loops instead resulted in ca 95 seconds without sleep, so foreach is the quickest i know of to this point.

adding a 5th letter increased the time past my patience, also it appeared that for every 15000 ca there was a short sleep..

this did not happen with 4 letters.

Edited by Demonized
modified text, added note on for loops and sleep.

Share this post


Link to post
Share on other sites

Also, you can simply use BIS_fnc_nearestPosition

(in viewer in Functions > misc > BIS_fnc_nearestPosition)

Parameter(s):

  • _this select 0: Array of Objects, Locations, Groups, markers (String) and / or positions (Array)
  • _this select 1: Comparator Object, Location, Group, marker (String) or position (Array)

Returns:

  • Object / Location / Group / marker (String) or position (Array) which is nearest to the comparator

Share this post


Link to post
Share on other sites

edit: this still asumes that you need to have the list/array of markers available yes?

you cannot find "untracked" markers with this function?

edit:

Description:

Function to find the nearest Object or position from a list,

when compared to a given Object or position.

Edited by Demonized

Share this post


Link to post
Share on other sites

Thanks, I haven't had chance to try anything yet. I was hoping there was a simple way but didn't expect it really.

Share this post


Link to post
Share on other sites

First I tried ])rStrangeloves script but I'm not getting anything returned apart from the location of my documents.

Demonized script gives an error in this line.

 _range = ((getMarkerPos _x) distance (vehicle _unit));

vehicle _unit seems to be the problem .

Share this post


Link to post
Share on other sites

Demonized script gives an error in this line.

 _range = ((getMarkerPos _x) distance (vehicle _unit));

vehicle _unit seems to be the problem .

i get no errors on my end, notice that _unit is _this, so you would need to run script with:

_null = unitname execVM "script.sqf";

and the markers to check you ofc need to fill into the global array called All_My_Markers before running the check.

All_My_Markers = ["markername1","markername2","etc"];

edit: you ofc does not need to run it as a script, i myself ran it in a trigger inside a spawn to test, but make sure _unit is set to the unit correctly.

my test unit is named test1, my markers are mark1-3.

_null = test1 spawn {

All_My_Markers = ["mark1","mark2","mark3"];
_unit = _this;
_dist = 999999999;
_marker = "";
{
_range = ((getMarkerPos _x) distance (vehicle _unit));
if (_range < _dist) then {_dist = _range; _marker = _x};
} foreach All_My_Markers;
hint format["nearest marker is %1",_marker];

};

it returns the closest marker to my position wich was mark2.

Edited by Demonized

Share this post


Link to post
Share on other sites

Thanks it was because I never call code that way, I always use the longer version with [].

Share this post


Link to post
Share on other sites

np m8te, i see how it could be confusing, i used _this instead of _unit, when i wrote it, but then added _unit = _this so it was clear to whomever that looked at the post what was the unit and how was it checked.

just ended up being confusing instead :)

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  

×