Jump to content
Sign in to follow this  
big_wilk

Grid Refrence to World Position

Recommended Posts

Hi,

I am trying to make a Grid Reference to World Position script. But have run into a dead end. Could anyone help me understand the maths needed to make this work for all map as I don't want to write a script for every map?

The World Positions are always numbers less than 10,000. If the number is greater than 10,000 then up to two decimal places seem to used. What would I need to do to scale something like the script pasted bellow to work for every map, and work with a minimum of a 1 figure grid reference up to at least 8 figures.

(There does not seem to be any BIS functions for this, though CBA does have one, the script is not using mods so unfortunately I cant use that and I cant get my head round what it does either).

This is as far as I have gotten by myself (it works but only for Altis):

_pos = [123,321] call BW_fnc_GridToPos;

private ["_x3","_y3"];
_x2 = _this select 0;
_y2 = _this select 1;

_condition = worldName;

switch (_condition) do { 

case "Altis": { 
if (_x2 < 1000000000) then {_x3 = _x2 / 10000;};
if (_y2 < 1000000000) then {_y3 = _y2 / 10000;};

if (_x2 < 100000000) then {_x3 = _x2 / 1000;};
if (_y2 < 100000000) then {_y3 = _y2 / 1000;};

if (_x2 < 10000000) then {_x3 = _x2 / 100;};
if (_y2 < 10000000) then {_y3 = _y2 / 100;};

if (_x2 < 1000000) then {_x3 = _x2 / 10;};
if (_y2 < 1000000) then {_y3 = _y2 / 10;};

if (_x2 < 100000) then {_x3 = _x2};
if (_y2 < 100000) then {_y3 = _y2};

if (_x2 < 10000) then {_x3 = 10 * _x2;};
if (_y2 < 10000) then {_y3 = 10 * _y2;};

if (_x2 < 1000) then {_x3 = 100 * _x2;};
if (_y2 < 1000) then {_y3 = 100 * _y2;};
};

[_x3,_y3];

Edited by Big_Wilk

Share this post


Link to post
Share on other sites
This should fit your needs (I hope):

https://community.bistudio.com/wiki/posScreenToWorld

The problem with using this command is that you need to know the mystical "map control" the game uses' date=' which nobody that has found it has shared such information on the internet

---------- Post added at 14:53 ---------- Previous post was at 14:33 ----------

Could anyone help me understand the maths needed to make this work for all map as I don't want to write a script for every map?

The problem with this is that I've found each map seems to have a different X/Y offset concerning their grid. Why this is, I have no idea. Copy this code and run it in the debug console on all 3 maps:

[] spawn
{
_brushes = ["Solid","Horizontal","Vertical","Grid","FDiagonal","BDiagonal","DiagGrid"];
for "_i" from 0 to 81 do
{
	for "_o" from 0 to 81 do
	{
		//if (!surfaceIsWater [(_o * 100) + 50, (_i * 100)]) then
		//{
			_marker = createMarker [format["%1_%2",_o,_i], [(_o * 100), (_i * 100),0]];
			_marker setMarkerText (format ["%1_%2 \ %3",_o,_i, getMarkerPos _marker]);
			_marker setMarkerShape "RECTANGLE";
			//_marker setMarkerType "MIL_DOT";
			_marker setMarkerSize [50,50];
			_marker setMarkerBrush (_brushes select (floor random (count _brushes)));
			_marker setMarkerColor "ColorRed";
		//};
	};
};
};

This code puts a map marker on on some 100x100m squares. You should see that they do not align correctly with the grids. I've found 2 of the offsets (Altis & VR).

Altis: x + 50, y + 50

VR: x + 0, y + 2

I haven't messed with Stratis.

Again, I have no idea why they did this. If you ask me, the map should start at (0,0), along with the grids.

work with a minimum of a 1 figure grid reference up to at least 8 figures.

I'm having trouble understanding what you mean, you do know that in Arma3 vanilla you can only have map coords of up to 6 figures, right? (XXXYYY)

Share this post


Link to post
Share on other sites

Thanks for the reply's,

@ Heeeere's Johnny! Thanks, I'll have a look for the map control to see if posScreenToWorld will work, but not sure how to go about detecting the map dialog to test it.

@DreadedEntity that makes a nice pattern :) I was trying to do a similar thing after seeing what the CBA function does to check the maps scale: Its here if you want to look at it: https://www.dropbox.com/s/pw79bi5p16k7ryc/fnc_mapGridToPos.sqf?dl=0 I cant figure that out. The CBA one has attualy figure out

Unless I completely misunderstand how internal positions work I think you could convert a grid reference of any size to a world position. For example the CBA one converts up to 10 figures. [12345,54321].

In my script above to get a 10 figure grid reference into an internal potion I do this (works on altis):

Put this into your debug consol on Altis in the editor to end up on a nice stretch of coast line :). GRID 12355,12505

[12355,12505] spawn {  
private ["_x3","_y3"];  
_x2 = _this select 0;  
_y2 = _this select 1;    

if (_x2 < 1000000000) then {_x3 = _x2 / 10000;};  
if (_y2 < 1000000000) then {_y3 = _y2 / 10000;};    
if (_x2 < 100000000) then {_x3 = _x2 / 1000;};  
if (_y2 < 100000000) then {_y3 = _y2 / 1000;};    
if (_x2 < 10000000) then {_x3 = _x2 / 100;};  
if (_y2 < 10000000) then {_y3 = _y2 / 100;};    
if (_x2 < 1000000) then {_x3 = _x2 / 10;}; 
if (_y2 < 1000000) then {_y3 = _y2 / 10;};    
if (_x2 < 100000) then {_x3 = _x2};  
if (_y2 < 100000) then {_y3 = _y2};    
if (_x2 < 10000) then {_x3 = 10 * _x2;};  
if (_y2 < 10000) then {_y3 = 10 * _y2;};   
if (_x2 < 1000) then {_x3 = 100 * _x2;};  
if (_y2 < 1000) then {_y3 = 100 * _y2;};     

player setpos [_x3,_y3];
};

Edited by Big_Wilk

Share this post


Link to post
Share on other sites

So I wrote a grid converter just now, but here's the thing. When you input 5 character grid coordinates, the grid coordinates actually are the world coordinates

DE_fnc_convertGridCoord =
{
//input:  _myVar = [GridX, GridY] call DE_fnc_convertGridCoord;
//return: ARRAY - (worldPos)

private ["_gridX","_gridY","_input","_result","_size","_number","_char"];

_gridX = [_this, 0, "0", [""]] call BIS_fnc_param;
_gridY = [_this, 1, "0", [""]] call BIS_fnc_param;
_input = [_gridX,_gridY];
_gridX = nil;
_gridY = nil;
_result = [];

{
	_size = 10000;
	_number = 0;
	for "_i" from 0 to ((count _x) - 1) do
	{
		_char = [_x, _i, _i] call BIS_fnc_trimString;
		_number = _number + ((parseNumber _char) * _size);
		_size = _size / 10;
	};
	_result pushBack _number;		
}forEach _input;

_result;
}; //Didn't realize I was writing a string to number decimal converter until it was already done

//example
_coord = ["18045234","16293234"] call DE_fnc_convertGridCoord;

_marker = createMarker ["test", _coord];
_marker setMarkerShape "ICON";
_marker setMarkerType "MIL_DOT";

Share this post


Link to post
Share on other sites
The problem with using this command is that you need to know the mystical "map control" the game uses, which nobody that has found it has shared such information on the internet

I've found it being used in P:\a3\ui_f\scripts\IGUI\RscSpectator.sqf

It's a big switch statement and at the beginning of the 'init' case it does this:

_ctrlMainMap = (finddisplay IDD_MAIN_MAP) displayctrl IDC_MAP;

_ehClick = _ctrlMainMap ctrladdeventhandler ["mousebuttonclick","with uinamespace do {['click',_this,''] call RscSpectator_script};"];

The 'click' case does the following:

	_button = _params select 1;
	if (_button == 0) then {
		_x = _params select 2;
		_y = _params select 3;
		_worldpos = (_params select 0) posscreentoworld [_x,_y];
		_camera = missionnamespace getvariable ["RscSpectator_camera",objnull];
		_camera setpos [_worldpos select 0,_worldpos select 1,getposatl _camera select 2];
	};

I have to go to sleep but I'll update the wiki tomorrow so people can see what kind of Control the wiki talks about.

Couldn't help but digging a little deeper, in this file: P:\a3\ui_f\hpp\defineResincl.inc at around line 496 is a big list of displays. I don't know if any of this is useful to the OP but it's great to finally see that the mystical display 46 is a constant called IDD_MISSION

Edited by BadLuckBurt
Broken tags make Burt sad

Share this post


Link to post
Share on other sites

DreadedEntity your my hero! Thanks for that I've been trying to figure that out for a while now. I'll trying and make it work with reversed axis tomorrow (haven't tested it on a reversed yet but I assume from looking it wont currently deal with that).

BadLuckBurt thanks for your help I'll look at that tmrrow also.

Edited by Big_Wilk

Share this post


Link to post
Share on other sites
DreadedEntity your my hero! Thanks for that I've been trying to figure that out for a while now. I'll trying and make it work with reversed axis tomorrow (haven't tested it on a reversed yet but I assume from looking it wont currently deal with that).

What you mean reversed axis? Just switch the numbers around, it'll work the same

Burt, extremely good find, man. I'll have a play with this later

Share this post


Link to post
Share on other sites

No need to do any complicated string conversion, just call compile the string and you have a number.

_grid = _this;
_gridRefSize = ( count _grid ) / 2;
_multi = 10^ ( 5 - _gridRefSize );
_gridX = ( call compile ( _grid select [ 0, _gridRefSize ] ) ) * _multi;
_gridY = ( call compile ( _grid select [ _gridRefSize, _gridRefSize ] ) ) * _multi;

[ _gridX, _gridY ]

Also not sure what you mean by reversed axis!

@DE getting the map ctrl is not a problem, from the discussion in the other thread what i ment by the 'mystical _map' is in reference to the control in the editor that is meant to hold references to placed entities. Whether this be the actual map control (does not seem to be) or another, it is always referenced in the BIKI as _map <type control>.

Share this post


Link to post
Share on other sites

Rather than compiling the grid string, you can simply use parseNumber, it's about 2.5x faster.

Also, please note your solution will work only on terrains which are using numeric notation with 3 digits. For example South Asia from Take On is using 4 digits, and older islands, unless reconfigured, may be using alphabet as well (good ol' Bc64). The grid is defined in CfgWorlds >> [WorldName] >> Grid

Share this post


Link to post
Share on other sites

@ (DE / Badluck) What I mean about the axis is some maps for example VR have strange X or Y coordinates. VR starts with the Y000 in the middle of the map (if you go south its the grid is 999, if you go north its 001 (as VR seems to be on the equator :confused:)). The X axis on VR is how you might expect with 0 on the far left of the map. So to take Badlucks or DE's examples entering this grid 010,020:

[] spawn {
_grid = "010020";

_gridRefSize = ( count _grid ) / 2;  _multi = 10^ ( 5 - _gridRefSize );  
_gridX = ( parseNumber ( _grid select [ 0, _gridRefSize ] ) ) * _multi;  
_gridY = ( parseNumber ( _grid select [ _gridRefSize, _gridRefSize ] ) ) * _multi;   

player setpos [_gridX,_gridY,0];
};

Will place you at 0100,9765. (some maps have one axis complete reserved for example I think Bystrica from the ACR Dlc in Arma2 had that for some reason).

@Moricky I had a look around in CFGworlds earlyer and cant find the "grid" entry has that changed in arma3,

_num = getNumber (configfile >> "CfgWorlds" >> worldName >> "grid");

Or is the above wrong?

Edited by Big_Wilk

Share this post


Link to post
Share on other sites

@Moricky I had a look around in CFGworlds earlyer and cant find the "grid" entry has that changed in arma3,

_num = getNumber (configfile >> "CfgWorlds" >> worldName >> "grid");

Or is the above wrong?

Grid is class

Share this post


Link to post
Share on other sites
Grid is class

gettext then? if so it returns ""

I had a look through the config veiwer at:

configfile >> "CfgWorlds" >> "altis/stratis"

Don't see it unfortunately. Will look again later when I get sometime.

Share this post


Link to post
Share on other sites
gettext then? if so it returns ""

I had a look through the config veiwer at:

configfile >> "CfgWorlds" >> "altis/stratis"

Don't see it unfortunately. Will look again later when I get sometime.

- edit

See Killzone_Kid's correction of my post here, apparently the one I found on Six Config browser wasn't the right one. Thanks for the heads up KK!

Edited by BadLuckBurt
Posted wrong info

Share this post


Link to post
Share on other sites
Rather than compiling the grid string, you can simply use parseNumber, it's about 2.5x faster.

Damit always forget about parseNumber, thats several script ive gotta go back and change :)

For example South Asia from Take On is using 4 digits, and older islands, unless reconfigured, may be using alphabet as well (good ol' Bc64).
Number of digits would just mean changing the hard coded base of 5 i have when needed i think.

Good to know about some coordinate systems using letters though. I have made plans for installations all over the world but only ever used UTM WGS84 and occasionally NAD, will be handy to keep in mind for some of my CAD scripts just in case a client ever needs us to work in some other system.

The grid is defined in CfgWorlds >> [WorldName] >> Grid
Is the offset incorrect then for VR?

worldOffsetX = getNumber ( configFile >> "CfgWorlds" >> worldName >> "Grid" >> "offsetx" );
worldOffsetY = getNumber ( configFile >> "CfgWorlds" >> worldName >> "Grid" >> "offsety" );
grid = [ worldOffsetX, worldOffsetY, 0 ];

Returns [0,3840,0], setting the players position using these coordinates leaves them 500 odd meters short of the zero line, as the vertical zero of VR is not central to the map.

Ok i see its based off of the top left corner but this still leaves problems as VR does not have a mapSize to reference. Although it is 8192, 8192 - 3840 does indeed leave the player on the zero line but there is no way to make a robust system out of this due to the grid nature ( smaller than zero in the vertical ) and that VR has no mapSize property. Leaves you having to hard code variables and fudge numbers rather than relying on config definitions.

Share this post


Link to post
Share on other sites
This is what it looks like:

class Grid: Grid {
offsetx = 0;
offsety = 8192;
class Zoom1 {
	format = "XY";
	formatx = 0;
	formaty = 0;
	stepx = 100;
	stepy = -100;
	zoommax = 0.2;
};
class Zoom2 {
	format = "XY";
	formatx = 0;
	formaty = 0;
	stepx = 1000;
	stepy = -1000;
	zoommax = 0.95;
};
class Zoom3 {
	format = "XY";
	formatx = 0;
	formaty = 0;
	stepx = 10000;
	stepy = -10000;
	zoommax = "1e+030";
};
};

Scroll down to line 2529:

http://browser.six-projects.net/cfg_worlds/Stratis/config?version=73

I think Karel is referring to either the format property or formatX / formatY. I couldn't find any info on the BIKI but the BISim version does have a config reference for it: https://resources.bisimulations.com/w/index.php?title=CfgWorlds_Config_Reference#format

That ^^^ config is incorrect, the correct one is:

class Grid: Grid
{
offsetX = 0;
offsetY = 8192;
class Zoom1
{
	zoomMax = 0.2;
	format = "XY";
	formatX = "000";
	formatY = "000";
	stepX = 100;
	stepY = -100;
};
class Zoom2
{
	zoomMax = 0.95;
	format = "XY";
	formatX = "00";
	formatY = "00";
	stepX = 1000;
	stepY = -1000;
};
class Zoom3
{
	zoomMax = 1e+030;
	format = "XY";
	formatX = "0";
	formatY = "0";
	stepX = 10000;
	stepY = -10000;
};
};

Share this post


Link to post
Share on other sites

Works for all vanilla maps (Altis, Stratis and VR). Everything else you are going to have to take case by case dependent on config properties available.

[] spawn {
_grid = "00";
_gridRefSize = ( count _grid ) / 2;
_mapSize = getArray ( configFile >> "CfgWorlds" >> worldName >> "mapsize" );
_multi = 10^ ( 5 - _gridRefSize );
_gridX = ( parseNumber ( _grid select [ 0, _gridRefSize ] ) ) * _multi;
_gridY = ( parseNumber ( _grid select [ _gridRefSize, _gridRefSize ] ) ) * _multi;

_worldOffsetX = getNumber ( configFile >> "CfgWorlds" >> worldName >> "Grid" >> "offsetx" );
_worldOffsetY = getNumber ( configFile >> "CfgWorlds" >> worldName >> "Grid" >> "offsety" );

_mapSize = getArray ( configFile >> "CfgWorlds" >> worldName >> "mapSize" );
if ( _mapSize isEqualTo [] ) then {
	_mapSize = [ 8192, 8192 ];
};  
_mapSizeX = _mapSize select 0;
_mapSizeY = _mapSize select 1;

switch ( worldName ) do {
	case "VR" : {
		_centerY = _mapSizeY - _worldOffsetY;
		if (  _gridY >= 90000 ) then {
			_gridY = _centerY - ( 100000 - _gridY );
		}else{
			_gridY = _gridY + _centerY;
		};
	};
};

grid = [ _gridX, _gridY, 0 ]
};

Share this post


Link to post
Share on other sites

Thanks a lot for your help everyone. I guess if this is ever used outside of the vanilla then I can tell people to load @cba as they'll probably be using that anyway.

Share this post


Link to post
Share on other sites

This was a nice coding exercise. BIS_fnc_gridToPos coming to your dev version soon ;)

It works with any possible grid configuration, including rectangular grids, various offsets, letter denotations or custom format.

/*
Author: Karel Moricky

Description:
Converts grid coordinates to world position.
Correct results outside of the map area are not guaranteed.

Parameter(s):
	0: STRING - grid returned by mapGridPosition command

Returns:
ARRAY in format [[gridX:Number,gridY:Number],[gridWidth:Number,gridHeight:Number]]
*/

private ["_posGrid","_cfgGrid","_offsetX","_offsetY","_zoomMax","_format","_formatX","_formatY","_stepX","_stepY"];
_posGrid = [_this,0,mapgridposition position cameraon,[""]] call bis_fnc_param;

//--- Extract grid values from world config
_cfgGrid = configfile >> "CfgWorlds" >> worldname >> "Grid";
_offsetX = getnumber (_cfgGrid >> "offsetX");
_offsetY = getnumber (_cfgGrid >> "offsetY");
_zoomMax = 1e99;
_format = "";
_formatX = "";
_formatY = "";
_stepX = 1e10;
_stepY = 1e10;
{
_zoom = getnumber (_x >> "zoomMax");
if (_zoom < _zoomMax) then {
	_zoomMax = _zoom;
	_format = gettext (_x >> "format");
	_formatX = gettext (_x >> "formatX");
	_formatY = gettext (_x >> "formatY");
	_stepX = getnumber (_x >> "stepX");
	_stepY = getnumber (_x >> "stepY");
};
} foreach configproperties [_cfgGrid,"isclass _x",false];

//--- Get grid format
private ["_iX","_iY","_formatXcount","_formatYcount"];
_iX = -1;
_iY = -1;
{if (_iX < 0) then {_iX = _format find _x;};} foreach ["X","x"];
{if (_iY < 0) then {_iY = _format find _x;};} foreach ["Y","y"];
_formatXcount = count _formatX;
_formatYcount = count _formatY;

//--- Convert letters to numbers
private ["_replaceBefore","_replaceAfter","_posGridX","_posGridY","_fnc_lettersToNumbers"];
_replaceBefore = toarray " 0123456789abcdefghijklmnopqrestuvwxyz";
_replaceAfter = [-1,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25];
_posGridX = _posGrid select [_iX,_formatXcount];
_posGridY = _posGrid select [_iY + _formatXcount - 1,_formatYcount];

_fnc_lettersToNumbers = {
_array = toarray tolower (_this select 0);
_count = _this select 1;
_step = _this select 2;
_result = 0;
{
	_result = _result + (_replaceAfter select ((_replaceBefore find _x) max 0)) * _step * 0.1 * 10^(_count - _foreachindex);
} foreach _array;
_result
};

_posGridX = [_posGridX,_formatXcount,_stepX] call _fnc_lettersToNumbers;
_posGridY = [_posGridY,_formatYcount,_stepY] call _fnc_lettersToNumbers;
_formatX = [_formatX,_formatXcount,_stepX] call _fnc_lettersToNumbers;
_formatY = [_formatY,_formatYcount,_stepY] call _fnc_lettersToNumbers;

_posGridX = _posGridX - _formatX;
_posGridY = _posGridY - _formatY;

//--- Get map size (ToDo: Universal detection by new scripting command)
private ["_ctrlMap","_mapPos1","_mapPos2","_mapSize"];
_ctrlMap = finddisplay 12 displayctrl 51;
_mapPos1 = _ctrlMap ctrlmapscreentoworld [0,0];
_mapPos2 = _ctrlMap ctrlmapscreentoworld [1,0];
_mapPos1 set [2,0];
_mapPos2 set [2,0];
_mapSize = round ((_mapPos1 vectordistance _mapPos2) / ctrlmapscale _ctrlMap);

//--- Correct vertical pos, which for legacy reasons starts in top left, not bottom left corner
if (_stepY > 0) then {_offsetY = _offsetY + _stepY;};

//--- Return the position
[[_offsetX + _posGridX,_mapSize - _offsetY - _posGridY],[abs _stepX,abs _stepY]]

Edited by Moricky
  • Like 1

Share this post


Link to post
Share on other sites

I'm going to leave this here too:

[color="#FF8040"]KK_fnc_gridToPos  [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]{[/b][/color]

[color="#1874CD"]_GRID[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#000000"]_this[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_cfgWorld[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]configFile[/b][/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"CfgWorlds"[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#191970"][b]worldName[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_mapSize[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getNumber[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_cfgWorld[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"mapSize"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_cfgGrid[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cfgWorld[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"Grid"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_offsetX[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getNumber[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_cfgGrid[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"offsetX"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_offsetY[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getNumber[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_cfgGrid[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"offsetY"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_gridInfo[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#7A7A7A"]"true"[/color] [color="#191970"][b]configClasses[/b][/color] [color="#1874CD"]_cfgGrid[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_format[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getText[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_gridInfo[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"format"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_formatX[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getText[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_gridInfo[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"formatX"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_formatY[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getText[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_gridInfo[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"formatY"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_stepX[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getNumber[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_gridInfo[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"stepX"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_stepY[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getNumber[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_gridInfo[/color] [color="#8B3E2F"][b]>[/b][/color][color="#8B3E2F"][b]>[/b][/color] [color="#7A7A7A"]"stepY"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_cntX[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]count[/b][/color] [color="#1874CD"]_formatX[/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]_dataX[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]""[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_cntY[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]count[/b][/color] [color="#1874CD"]_formatY[/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]_dataY[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]""[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_j[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]for[/b][/color] [color="#7A7A7A"]"_i"[/color] [color="#191970"][b]from[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]to[/b][/color] [color="#191970"][b]count[/b][/color] [color="#1874CD"]_format[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]1[/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
	[color="#1874CD"]_format[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_i[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
		[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]_this[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"X"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
			[color="#1874CD"]_dataX[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_GRID[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_j[/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_cntX[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#1874CD"]_j[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_j[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#1874CD"]_cntX[/color][color="#8B3E2F"][b];[/b][/color]
		[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
		[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]_this[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"Y"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
			[color="#1874CD"]_dataY[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_GRID[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_j[/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_cntY[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#1874CD"]_j[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_j[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#1874CD"]_cntY[/color][color="#8B3E2F"][b];[/b][/color]
		[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
		[color="#1874CD"]_j[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_j[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
	[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_j[/color] [color="#8B3E2F"][b]![/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]count[/b][/color] [color="#1874CD"]_GRID[/color] [color="#8B3E2F"][b]|[/b][/color][color="#8B3E2F"][b]|[/b][/color] [color="#191970"][b]count[/b][/color] [color="#1874CD"]_dataX[/color] [color="#8B3E2F"][b]![/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cntX[/color] [color="#8B3E2F"][b]|[/b][/color][color="#8B3E2F"][b]|[/b][/color] [color="#191970"][b]count[/b][/color] [color="#1874CD"]_dataY[/color] [color="#8B3E2F"][b]![/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cntY[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_dt[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"0123456789"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_c1[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"abcdefghij"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_c2[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"klmnopqrst"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_c3[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"uvwxyzabcd"[/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_getGrid[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
	[color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]""[/color][color="#8B3E2F"][b];[/b][/color]
	[color="#191970"][b]for[/b][/color] [color="#7A7A7A"]"_i"[/color] [color="#191970"][b]from[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]to[/b][/color] [color="#1874CD"]__cnt[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]1[/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
		[color="#191970"][b]toLower[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]__format[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_i[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]call[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
			[color="#1874CD"]_p[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_dt[/color] [color="#191970"][b]find[/b][/color] [color="#000000"]_this[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_p[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]-1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
				[color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#191970"][b]str[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#191970"][b]parseNumber[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]__data[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_i[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]-[/b][/color] [color="#1874CD"]_p[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]%[/b][/color] [color="#FF0000"]10[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#1874CD"]_p[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_c1[/color] [color="#191970"][b]find[/b][/color] [color="#000000"]_this[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_p[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]-1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
				[color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#191970"][b]str[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_c1[/color] [color="#191970"][b]find[/b][/color] [color="#191970"][b]toLower[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]__data[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_i[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]-[/b][/color] [color="#1874CD"]_p[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]%[/b][/color] [color="#FF0000"]10[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#1874CD"]_p[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_c2[/color] [color="#191970"][b]find[/b][/color] [color="#000000"]_this[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_p[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]-1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
				[color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#191970"][b]str[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_c2[/color] [color="#191970"][b]find[/b][/color] [color="#191970"][b]toLower[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]__data[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_i[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]-[/b][/color] [color="#1874CD"]_p[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]%[/b][/color] [color="#FF0000"]10[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#1874CD"]_p[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_c3[/color] [color="#191970"][b]find[/b][/color] [color="#000000"]_this[/color][color="#8B3E2F"][b];[/b][/color] [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_p[/color] [color="#8B3E2F"][b]>[/b][/color] [color="#FF0000"]-1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
				[color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_ret[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#191970"][b]str[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_c3[/color] [color="#191970"][b]find[/b][/color] [color="#191970"][b]toLower[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]__data[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_i[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]-[/b][/color] [color="#1874CD"]_p[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]%[/b][/color] [color="#FF0000"]10[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]
			[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
		[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
	[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
	[color="#1874CD"]_ret[/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]__cnt[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cntX[/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]__format[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_formatX[/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]__data[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_dataX[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_gridX[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]parseNumber[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]call[/b][/color] [color="#1874CD"]_getGrid[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]__cnt[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cntY[/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]__format[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_formatY[/color][color="#8B3E2F"][b];[/b][/color] [color="#1874CD"]__data[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_dataY[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_gridY[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]parseNumber[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]call[/b][/color] [color="#1874CD"]_getGrid[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_posX[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_stepX[/color] [color="#8B3E2F"][b]*[/b][/color] [color="#1874CD"]_gridX[/color] [color="#8B3E2F"][b]+[/b][/color] [color="#1874CD"]_offsetX[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_posY[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_mapSize[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#1874CD"]_offsetY[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#1874CD"]_stepY[/color] [color="#8B3E2F"][b]*[/b][/color] [color="#1874CD"]_gridY[/color][color="#8B3E2F"][b];[/b][/color]

[color="#8B3E2F"][b][[/b][/color][color="#1874CD"]_posX[/color][color="#8B3E2F"][b],[/b][/color] [color="#1874CD"]_posY[/color][color="#8B3E2F"][b],[/b][/color] [color="#191970"][b]abs[/b][/color] [color="#1874CD"]_stepX[/color][color="#8B3E2F"][b],[/b][/color] [color="#191970"][b]abs[/b][/color] [color="#1874CD"]_stepY[/color][color="#8B3E2F"][b]][/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

It is not perfect and while experimenting with different grid formats I found out it fails, but the reason seems to point to the way engine converts position to grid. If you stick with simple format this should work, try something more interesting and expect trouble.

PS also VR map has no mapSize param so function wont work with it until it does.

Edited by Killzone_Kid

Share this post


Link to post
Share on other sites

Wow, thanks Karel / Killzone. I appreciate the effort, I'll check them out tonight.

Share this post


Link to post
Share on other sites

hi guy, if you dont want to reinvent the wheels, there is already an sqf GRID object that is fully usable:

http://forums.bistudio.com/showthread.php?172296-OO-GRID-oriented-object-Strategic-GRID

it works with all the maps, and you can scales the grid to square, and other custom size/format on the map. (No letter output format, cause nobody ask for it, and it s not a good usable format for apps that require grid like chess or other ;) )

You can set constructor parameter with the config entry of kk below.

example with altis map , and grid that fit perfectly to map square

_grid = ["new", [31000,31000,100,100]] call OO_GRID;
_square = ["getSectorFromPos", position player] call _grid;

and reverse it

_position = ["getPosFromSector", _square] call _grid;

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  

×