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

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\{\{ArgTitle *\| *([^\|]+) *\| *([1-6]) *\|" to "{{ArgTitle|$2|$1|")
m (Text replacement - "{{Feature|Informative|" to "{{Feature|informative|")
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
}}
}}


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




Line 13: Line 13:
}}
}}


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




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




Line 42: Line 44:
{{Feature | Informative | This is an [[SQS Syntax]] example.}}
{{Feature | Informative | This is an [[SQS Syntax]] example.}}


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




[[Category:Example Code]]
[[Category:Example Code]]

Latest revision as of 01:24, 2 February 2024

Arma 3

private _mapGridPosition = mapGridPosition player;


Arma 2


Armed Assault

private _gridSize = 200; // given grid squares are 200 × 200 private _yOffset = -280; // position [0,0,0] is somewhere in the middle of second big grid on Y axis private _xPos = floor ((_this select 0) / _gridSize); 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; // coordinate numbers start from top-left of the map private _mapGridPosition = format ["%1%2%3", _letter1, _letter2, _numbers];


Operation Flashpoint

This is an SQS Syntax example.

; given grid squares are 200 × 200 private _gridSize = 200 ; position [0,0,0] is somewhere in the middle of second big grid on Y axis private _yOffset = -280 private _xPos = (_this select 0) / _gridSize private _yPos = ((_this select 1) + _yOffset) / _gridSize _xPos = _xPos - (_xPos mod 1) _yPos = _yPos - (_yPos mod 1) private _letter1Index = _xPos / 10 private _letter2Index = _xPos % 10 _letter1Index = _letter1Index - (_letter1Index mod 1) _letter2Index = _letter2Index - (_letter2Index mod 1) 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 ; coordinate numbers start from top-left of the map private _numbers = 100 - _yPos private _mapGridPosition = format ["%1%2%3", _letter1, _letter2, _numbers]