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

From Bohemia Interactive Community
Category: Example Code
m (Text replacement - "BIS_fnc_PosToGrid" to "BIS_fnc_posToGrid")
(Removed private usage in OFP/A1 examples)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{ArgTitle|{{arma3}}|2|{{GVI|arma3|1.00}} {{GVI|arma2|1.04}}}}
{{ArgTitle|2|{{arma3}}|{{GVI|arma3|1.00}} {{GVI|arma2|1.04}}}}
{{Informative |
{{Feature|informative|
* [[mapGridPosition]] has been introduced in {{GVI|arma2|1.04}}
* [[mapGridPosition]] has been introduced in {{GVI|arma2|1.04}}
}}
}}


[[private]] _mapGridPosition = [[mapGridPosition]] [[player]];
<sqf>private _mapGridPosition = mapGridPosition player;</sqf>




{{ArgTitle|{{arma2}}|2|{{GVI|arma2|1.00}}}}
{{ArgTitle|2|{{arma2}}|{{GVI|arma2|1.00}}}}
{{Informative |
{{Feature|informative|
* [[BIS_fnc_posToGrid]] has been introduced in {{GVI|arma2|1.00}}
* [[BIS_fnc_posToGrid]] has been introduced in {{GVI|arma2|1.00}}
}}
}}


[[private]] _mapGridPosition = [[player]] [[call]] [[BIS_fnc_posToGrid]];
<sqf>local _mapGridPosition = player call BIS_fnc_posToGrid;</sqf>




{{ArgTitle|{{arma}}|2|{{GVI|arma|1.00}}}}
{{ArgTitle|2|{{arma1}}|{{GVI|arma1|1.00}}}}
{{Informative|
{{Feature|informative|
* [[floor]] has been introduced in {{GVI|arma|1.00}}
* [[floor]] has been introduced in {{GVI|arma1|1.00}}
}}
}}


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


_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


{{ArgTitle|{{ofp}}|2|{{GVI|ofp|1.00}}}}
_xPos = floor ((_this select 0) / _gridSize);
{{Informative | This is an [[SQS syntax]] example.}}
_yPos = floor (((_this select 1) + _yOffset) / _gridSize);


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