Example Code: Convert Position To Map Grid: Difference between revisions

From Bohemia Interactive Community
Category: Example Code
No edit summary
 
(Removed private usage in OFP/A1 examples)
 
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
= Problem =
__NOTOC__
{{ArgTitle|2|{{arma3}}|{{GVI|arma3|1.00}} {{GVI|arma2|1.04}}}}
{{Feature|informative|
* [[mapGridPosition]] has been introduced in {{GVI|arma2|1.04}}
}}


How to get map's grid from object's position. For example get "Fe 26" from [10987.8, 15092.8, 0.0017395].
<sqf>private _mapGridPosition = mapGridPosition player;</sqf>


= Solution =


nothing at this time.
{{ArgTitle|2|{{arma2}}|{{GVI|arma2|1.00}}}}
{{Feature|informative|
* [[BIS_fnc_posToGrid]] has been introduced in {{GVI|arma2|1.00}}
}}


= Implementations =
<sqf>local _mapGridPosition = player call BIS_fnc_posToGrid;</sqf>


* SQS Script


Arguments: [[Position]]
{{ArgTitle|2|{{arma1}}|{{GVI|arma1|1.00}}}}
{{Feature|informative|
* [[floor]] has been introduced in {{GVI|arma1|1.00}}
}}


<pre>_str = ""
<sqf>
private ["_gridSize", "_yOffset", "_xPos", "_yPos"]
private ["_letter1Index", "_letter2Index", "_letter1Choice", "_letter2Choice", "_letter1", "_letter2"]
private ["_numbers", "_mapGridPosition"]


;OX
_gridSize = 200; // given grid squares are 200 × 200
_x = floor ((_this select 0) / 200)
_yOffset = -280; // position [0,0,0] is somewhere in the middle of second big grid on Y axis
_t = floor (_x / 10)
?_t == 0: _str = _str + "A"
?_t == 1: _str = _str + "B"
?_t == 2: _str = _str + "C"
?_t == 3: _str = _str + "D"
?_t == 4: _str = _str + "E"
?_t == 5: _str = _str + "F"
?_t == 6: _str = _str + "G"
?_t == 7: _str = _str + "H"
?_t == 8: _str = _str + "I"
?_t == 9: _str = _str + "J"
_t = _x mod 10
?_t == 0: _str = _str + "a"
?_t == 1: _str = _str + "b"
?_t == 2: _str = _str + "c"
?_t == 3: _str = _str + "d"
?_t == 4: _str = _str + "e"
?_t == 5: _str = _str + "f"
?_t == 6: _str = _str + "g"
?_t == 7: _str = _str + "h"
?_t == 8: _str = _str + "i"
?_t == 9: _str = _str + "j"


_str = _str + " "
_xPos = floor ((_this select 0) / _gridSize);
_yPos = floor (((_this select 1) + _yOffset) / _gridSize);


;OY
_letter1Index = floor (_xPos / 10);
_str = _str + str (104 - floor (((_this select 1) + 520) / 200))
_letter2Index = floor (_xPos % 10);
_letter1Choice = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];
_letter2Choice = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];
_letter1 = _letter1Choice select _letter1Index;
_letter2 = _letter2Choice select _letter2Index;


Hint _str</pre>
_numbers = 100 - _yPos; // coordinate numbers start from top-left of the map


_mapGridPosition = format ["%1%2%3", _letter1, _letter2, _numbers];
</sqf>


[[Category:Scripting Templates]]
 
{{ArgTitle|2|{{ofp}}|{{GVI|ofp|1.00}}}}
 
<sqs>
private ["_gridSize", "_yOffset", "_xPos", "_yPos"]
private ["_letter1Index", "_letter2Index", "_letter1Choice", "_letter2Choice", "_letter1", "_letter2"]
private ["_numbers", "_mapGridPosition"]
 
; given grid squares are 200 × 200
_gridSize = 200
 
; position [0,0,0] is somewhere in the middle of second big grid on Y axis
_yOffset = -280
 
_xPos = (_this select 0) / _gridSize
_yPos = ((_this select 1) + _yOffset) / _gridSize
_xPos = _xPos - (_xPos mod 1)
_yPos = _yPos - (_yPos mod 1)
 
_letter1Index = _xPos / 10
_letter2Index = _xPos % 10
_letter1Index = _letter1Index - (_letter1Index mod 1)
_letter2Index = _letter2Index - (_letter2Index mod 1)
_letter1Choice = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
_letter2Choice = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
_letter1 = _letter1Choice select _letter1Index
_letter2 = _letter2Choice select _letter2Index
 
; coordinate numbers start from top-left of the map
_numbers = 100 - _yPos
 
_mapGridPosition = format ["%1%2%3", _letter1, _letter2, _numbers]
</sqs>
 
 
[[Category:Example Code]]

Latest revision as of 21:46, 28 February 2026

Arma 3

private _mapGridPosition = mapGridPosition player;


Arma 2

local _mapGridPosition = player call BIS_fnc_posToGrid;


Armed Assault

private ["_gridSize", "_yOffset", "_xPos", "_yPos"] private ["_letter1Index", "_letter2Index", "_letter1Choice", "_letter2Choice", "_letter1", "_letter2"] private ["_numbers", "_mapGridPosition"] _gridSize = 200; // given grid squares are 200 × 200 _yOffset = -280; // position [0,0,0] is somewhere in the middle of second big grid on Y axis _xPos = floor ((_this select 0) / _gridSize); _yPos = floor (((_this select 1) + _yOffset) / _gridSize); _letter1Index = floor (_xPos / 10); _letter2Index = floor (_xPos % 10); _letter1Choice = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]; _letter2Choice = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; _letter1 = _letter1Choice select _letter1Index; _letter2 = _letter2Choice select _letter2Index; _numbers = 100 - _yPos; // coordinate numbers start from top-left of the map _mapGridPosition = format ["%1%2%3", _letter1, _letter2, _numbers];


Operation Flashpoint

private ["_gridSize", "_yOffset", "_xPos", "_yPos"] private ["_letter1Index", "_letter2Index", "_letter1Choice", "_letter2Choice", "_letter1", "_letter2"] private ["_numbers", "_mapGridPosition"] ; given grid squares are 200 × 200 _gridSize = 200 ; position [0,0,0] is somewhere in the middle of second big grid on Y axis _yOffset = -280 _xPos = (_this select 0) / _gridSize _yPos = ((_this select 1) + _yOffset) / _gridSize _xPos = _xPos - (_xPos mod 1) _yPos = _yPos - (_yPos mod 1) _letter1Index = _xPos / 10 _letter2Index = _xPos % 10 _letter1Index = _letter1Index - (_letter1Index mod 1) _letter2Index = _letter2Index - (_letter2Index mod 1) _letter1Choice = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] _letter2Choice = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] _letter1 = _letter1Choice select _letter1Index _letter2 = _letter2Choice select _letter2Index ; coordinate numbers start from top-left of the map _numbers = 100 - _yPos _mapGridPosition = format ["%1%2%3", _letter1, _letter2, _numbers]