Jump to content
Sign in to follow this  
ashram 1-1

Converting getpos to map grid reference

Recommended Posts

hi,

I couldn't find anything in the comref to convert a unit's position to a six or eight figure grid reference and nothing to help here on the forums

so i did some testing, of course it's simple enough maths but it seems the Utes and Chernarus maps are "upside down"

considering 8 figure references, the four digit x component is always the x position divided by ten

e.g. _playermapx = (getpos player select 0) / 10;

2900 -> 0290

for the y component, Takistan and Zargabad are also easy:

_playermapy = (getpos player select 1) / 10;

670 -> 0067

but for utes it has to be:

_playermapy = 512 - (getpos player select 1) / 10;

4820 -> 0030

and chernarus:

_playermapy = 1536 - (getpos player select 1) / 10;

14760 -> 0060

Is there an existing BIS function to do this? seems plausible as reporting-in units say "I'm at grid:..."

Otherwise will i need to work out what map the player is on and calculate myself accordingly?

Would obviously rather avoid that if possible!

Thanks in advance, Sam

Share this post


Link to post
Share on other sites

thanks very much, i did search through the comref for "grid", found nothing in there

will save me quite some trouble, cheers :)

Share this post


Link to post
Share on other sites

Sometimes you want the other way; send in a grid value and obtain the position. Feel free to rewrite, this is just what I happen to use atm for my own purposes. Have not checked if it works with other islands even. Note that _res is supposed to return a positional array, if it contains a string, it contains information about what went wrong, so you can use that. Goes like:

_ToGrid8 = {
private ["_pos","_posx","_posy","_array","_tmp","_str"];
_pos = _this;
_str = format ["%1",mapGridPosition _pos];
_posx = toArray format ["%1", round (((_pos select 0) % 100) / 11)] select 0;
_posy = toArray format ["%1", round (((_pos select 1) % 100) / 11)] select 0;
_array = toArray _str;
_tmp = [];
{_tmp set [count _tmp, _x]} forEach [_array select 0, _array select 1, _array select 2, _posx, _array select 3, _array select 4, _array select 5, _posy];
_str = toString _tmp;
_tmp = nil;
_posx = nil;
_posy = nil;
_str
};

_GridStringToPosition = {
private ["_input","_res"];
_input = _this select 0;
_res = [];
if !(typeName _input in ["STRING"]) exitWith {if(d_debug_mode) then {hint "_StringToGrid: Not a string, code error!"}; _res = "Bad grid data due to code error!"; _res};
if (count toArray _input != 6 && count toArray _input != 8) exitWith {if(d_debug_mode) then {hint "_StringToGrid: String not of correct size"}; _res = "Bad grid data"; _res};
_exit = false;
for "_i" from 0 to (count toArray _input) - 1 do {
	_tocheck = (toArray _input) select _i;
	if !(_tocheck in [48,49,50,51,52,53,54,55,56,57]) exitWith {_exit = true};
};
if (_exit) exitWith {if (d_debug_mode) then {hint "_StringToGrid: String contained non numerals"}; _res = "Bad grid data"; _res};
if (count toArray _input == 6) then {
	_res = [
		10000 * (parseNumber toString [toArray _input select 0]) +
		1000 * (parseNumber toString [toArray _input select 1]) +
		100 * (parseNumber toString [toArray _input select 2]) + 50,
		10000 * (parseNumber toString [toArray _input select 3]) +
		1000 * (parseNumber toString [toArray _input select 4]) +
		100 * (parseNumber toString [toArray _input select 5]) + 50
	];
} else {
	_res = [
		10000 * (parseNumber toString [toArray _input select 0]) +
		1000 * (parseNumber toString [toArray _input select 1]) +
		100 * (parseNumber toString [toArray _input select 2]) +
		10 * (parseNumber toString [toArray _input select 3]) + 5,
		10000 * (parseNumber toString [toArray _input select 4]) +
		1000 * (parseNumber toString [toArray _input select 5]) +
		100 * (parseNumber toString [toArray _input select 6]) +
		10 * (parseNumber toString [toArray _input select 7]) + 5
	];
};
_res
};

Share this post


Link to post
Share on other sites

Is there a way to get an 8 to 10 digit grid, these 6 digit grids work but it would be better to have an 8? It would be cool to be playing the game and then having the Takistan map on your desk. :p

Share this post


Link to post
Share on other sites

cobra, the values coming from getpos have plenty enough precision for a ten digit grid reference

not sure why you would need it that detailed, unless you want the batallion surgeon to direct an appendectomy by radio? ;)

_mapx = "0"+str(round (getpos player select 0));

_mapy = "0"+str(round (getpos player select 1));

n.b. this only works for the OA maps.

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  

×