Difference between revisions of "onMapSingleClick"

From Bohemia Interactive Community
Jump to navigation Jump to search
(26 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[[Category:Scripting Commands|ONMAPSINGLECLICK]]
+
{{Command|Comments=
[[Category:Scripting Commands OFP 1.96|ONMAPSINGLECLICK]]
 
[[Category:Scripting Commands ArmA|ONMAPSINGLECLICK]]
 
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
 
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
 
{{Command|= Comments
 
 
____________________________________________________________________________________________
 
____________________________________________________________________________________________
  
| ofpr |= Game name
+
| ofpr |Game name=
  
|1.85|= Game version
+
|1.85|Game version=
 
____________________________________________________________________________________________
 
____________________________________________________________________________________________
  
| Define action performed when user clicks in map by executing command string.
+
| Define action performed when user clicks in map by executing command string. The code is executed on every click, until the '''command''' is
 
+
* removed via '''onMapSingleClick''' "", or
the string receives 3 (localised in scope) variables:
+
* replaced by '''onMapSingleClick''' "SomeOtherCommand(s)"
  
 +
the string receives 5 (localised in scope) variables:
 +
* _this: [[Anything]] - Params passed to onMapSingleClick
 
* _pos: [[Array]] - Clicked position
 
* _pos: [[Array]] - Clicked position
 
* _units: [[Array]] - Units which were selected (via function keys) '''before''' opening the map (''may be non-functional in Arma'')
 
* _units: [[Array]] - Units which were selected (via function keys) '''before''' opening the map (''may be non-functional in Arma'')
* _shift, _alt [[Boolean]] - Whether <Shift> or <Alt> were pressed when clicking on the map
+
* _shift: [[Boolean]] - Whether <Shift> was pressed when clicking on the map
 +
* _alt: [[Boolean]] - Whether <Alt> was pressed when clicking on the map
  
When click is processed, code should ultimately return [[true]] back to the engine. If [[false]] is returned, default processing by the game engine is done. Return value of any other type (including [[Nothing]]) is an error. In such case default processing by the game engine is done, and error message may be displayed.
+
In Arma 3 the code should return [[true]] only if you wish to override default engine handling of the mouse click on map (see example #4)<br> For older games, when click is processed, code should ultimately return [[true]] back to the engine. If [[false]] is returned, default processing by the game engine is done. Return value of any other type (including [[Nothing]]) is an error. In such case default processing by the game engine is done, and error message may be displayed.
  
The code is executed on every click, until the '''Command''' is  
+
<br><br>
*removed via '''onMapSingleClick''' "", or
+
{{Feature arma3 | Since '''{{arma3}}''' v1.57 a stackable MissionEventHandler is available and should be used instead: [[Arma_3:_Event_Handlers/addMissionEventHandler#MapSingleClick|MapSingleClick]].<br>
*replaced by '''onMapSingleClick''' "SomeOtherCommand(s)"|=  
+
Before that, the functions [[BIS_fnc_addStackedEventHandler]] and [[BIS_fnc_removeStackedEventHandler]] should be used instead in order to keep compatibility between official and community content.}} |Description=
 
____________________________________________________________________________________________
 
____________________________________________________________________________________________
  
| '''onMapSingleClick''' command |= Syntax
+
| [[onMapSingleClick]] command |SYNTAX=
  
|p1=command: [[String]] |= Parameter 1
+
|p1= command: [[String]] or [[Code]] |PARAMETER1=
  
| [[Nothing]] |= Return value
+
| [[Nothing]] |RETURNVALUE=
 +
 
 +
|s2= params [[onMapSingleClick]] command |SYNTAX2=
 +
 
 +
|p21= params: [[Anything]] |PARAMETER21=
 +
 
 +
|p22= command: [[String]] or [[Code]] |PARAMETER22=
 +
 
 +
|r2= [[Nothing]] |RETURNVALUE2=
 
____________________________________________________________________________________________
 
____________________________________________________________________________________________
| x1 = <code>'''onMapSingleClick "'''<nowiki>'</nowiki>SoldierWB' [[createUnit]] [_pos, [[group]] [[player]]]; true;'''"'''</code>
 
'''ArmA:''' Creates a soldier unit at the position clicked.|= Example 1
 
  
| x2 = <code>'''onMapSingleClick "'''_grp1 [[move]] _pos; onMapSingleClick <nowiki>''</nowiki>; true;'''"'''</code>
+
|x1= '''ArmA:''' Creates a soldier unit at the position clicked:
'''ArmA:''' Orders "_grp1" to move to position clicked. Disables further map-click actions.| = Example 2
+
<code>[[onMapSingleClick]] "'SoldierWB' [[createUnit]] [_pos, [[group]] [[player]]]; true";</code> |EXAMPLE1=
 +
 
 +
|x2= '''ArmA:''' Orders "grp1" to move to position clicked. Disables further map-click actions:
 +
<code>[[onMapSingleClick]] "grp1 [[move]] _pos; [[onMapSingleClick]] <nowiki>'</nowiki>'; [[true]]";</code> |Example 2=
 +
 
 +
|x3= '''OFP:''' In OFP single quotes cannot be used for string definition, so two double-quotes have to be used instead:
 +
<code>[[onMapSingleClick]] "'SoldierWB' [[createUnit]] [_pos, [[group]] [[player]]]; [[true]]";</code> |EXAMPLE3=
  
| x3 = <code>'''onMapSingleClick "'''""SoldierWB"" [[createUnit]] [_pos, [[group]] [[player]]]; true;'''"'''</code>
+
|x4= <code>{{cc|The following code will disable Shift+click waypoint marker creation}}
'''OFP:''' In OFP single quotes cannot be used for string definition, so two double-quotes have to be used instead. |= Example 1
+
[[onMapSingleClick]] {_shift};</code>|EXAMPLE4=
  
 +
|x5= <code>{{cc|Pass params to onMapSingleClick code}}
 +
[[player]] [[onMapSingleClick]] {[[hint]] ("Hello " + [[name]] _this)}; {{cc|Hello KK}}</code> |EXAMPLE5=
  
| [[onGroupIconClick]], [[onDoubleClick]] |= See also
+
|x6= <code>{{cc|Pass params to onMapSingleClick code '''and''' disable Shift+click waypoint marker creation}}
 +
[[player]] [[onMapSingleClick]] "[[hint]] (""Hello "" + [[name]] [[_this]]); _shift"; {{cc|Hello KK}}</code> |EXAMPLE6=
  
 +
| [[onGroupIconClick]] |SEEALSO=
 
}}
 
}}
  
Line 51: Line 65:
 
<!-- Note Section BEGIN -->
 
<!-- Note Section BEGIN -->
 
<dd class="notedate">Posted on 8 July, 2009
 
<dd class="notedate">Posted on 8 July, 2009
<dt class="note">'''[[User:General Barron|General Barron]]'''<dd class="note">
+
<dt class="note">[[User:General Barron|General Barron]]
 +
<dd class="note">
 
See my [http://www.ofpec.com/editors-depot/index.php?action=details&id=292&game=ArmA Multiple OnMapSingleClick] script to allow you to add multiple events to the onMapSingleClick event. Some minor editing of the scripts would be required to use them in Arma.
 
See my [http://www.ofpec.com/editors-depot/index.php?action=details&id=292&game=ArmA Multiple OnMapSingleClick] script to allow you to add multiple events to the onMapSingleClick event. Some minor editing of the scripts would be required to use them in Arma.
 
<!-- Note Section END -->
 
<!-- Note Section END -->
Line 60: Line 75:
 
<!-- Note Section BEGIN -->
 
<!-- Note Section BEGIN -->
  
<dd class="notedate">Posted on March 16, 2013 - 12:33
+
<!-- Note Section END -->
<dt class="note">'''[[User:Mlacix|Mlacix]]'''<dd class="note">
+
</dl>
''onMapSingleClick'' have some problem to run '''[[execVM]]''' command. The problem coused by the execVM itself, but there is a way to fix it. Here you can see two example.
 
  
Not working:
+
<h3 style="display:none">Bottom Section</h3>
  onMapSingleClick "if (_alt) then {[_shift,_alt,_pos] execVM 'arty_menu.sqf'};";
+
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
 +
[[Category:Scripting Commands OFP 1.96|{{uc:{{PAGENAME}}}}]]
 +
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
 +
[[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]]
 +
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
 +
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
 +
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
  
Working:
+
<!-- CONTINUE Notes -->
  onMapSingleClick "if (_alt) then {_a = [_shift, _alt, _pos] execVM 'arty_menu.sqf'; };";
+
<dl class="command_description">
 
+
<dd class="notedate">Posted on April 1, 2016 - 00:25 (UTC)</dd>
Difference:
+
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
  _a = [_shift, _alt, _pos] execVM 'arty_menu.sqf'; //You can create it in and outside of the onMapSingleClick scope.
+
<dd class="note">
 
+
<tt>_units</tt> param is supposed to return what [[groupSelectedUnits]] returns. Player must be [[leader]] and some [[units]] in the [[group]] must be selected on the group bar. However selected units are connected with group orders menu, which interferes with map click. In other words, when you click on the main map, the map gets focus and group orders menu closes, deselecting any selected unit, so <tt>_units</tt> is [] pretty much all the time.  
The difference is that if you want to use execVM in that scope, then you need to add it to a variable (global and local both work). This is an '''execVM''' issue, not an '''exec''' one. With *.SQS files it's working without any problem.
+
</dd>
 
 
<!-- Note Section END -->
 
 
</dl>
 
</dl>
 +
<!-- DISCONTINUE Notes -->

Revision as of 23:07, 2 September 2019

Introduced with Operation Flashpoint: Resistance version 1.851.85
Hover & click on the images for descriptions

Description

Description:
Define action performed when user clicks in map by executing command string. The code is executed on every click, until the command is
  • removed via onMapSingleClick "", or
  • replaced by onMapSingleClick "SomeOtherCommand(s)"
the string receives 5 (localised in scope) variables:
  • _this: Anything - Params passed to onMapSingleClick
  • _pos: Array - Clicked position
  • _units: Array - Units which were selected (via function keys) before opening the map (may be non-functional in Arma)
  • _shift: Boolean - Whether <Shift> was pressed when clicking on the map
  • _alt: Boolean - Whether <Alt> was pressed when clicking on the map
In Arma 3 the code should return true only if you wish to override default engine handling of the mouse click on map (see example #4)
For older games, when click is processed, code should ultimately return true back to the engine. If false is returned, default processing by the game engine is done. Return value of any other type (including Nothing) is an error. In such case default processing by the game engine is done, and error message may be displayed.

Arma 3 logo black.png
Since Arma 3 v1.57 a stackable MissionEventHandler is available and should be used instead: MapSingleClick.
Before that, the functions BIS_fnc_addStackedEventHandler and BIS_fnc_removeStackedEventHandler should be used instead in order to keep compatibility between official and community content.

Syntax

Syntax:
onMapSingleClick command
Parameters:
command: String or Code
Return Value:
Nothing

Alternative Syntax

Syntax:
params onMapSingleClick command
Parameters:
params: Anything
command: String or Code
Return Value:
Nothing

Examples

Example 1:
ArmA: Creates a soldier unit at the position clicked: onMapSingleClick "'SoldierWB' createUnit [_pos, group player]; true";
Example 2:
ArmA: Orders "grp1" to move to position clicked. Disables further map-click actions: onMapSingleClick "grp1 move _pos; onMapSingleClick ''; true";
Example 3:
OFP: In OFP single quotes cannot be used for string definition, so two double-quotes have to be used instead: onMapSingleClick "'SoldierWB' createUnit [_pos, group player]; true";
Example 4:
// The following code will disable Shift+click waypoint marker creation onMapSingleClick {_shift};
Example 5:
// Pass params to onMapSingleClick code player onMapSingleClick {hint ("Hello " + name _this)}; // Hello KK
Example 6:
// Pass params to onMapSingleClick code and disable Shift+click waypoint marker creation player onMapSingleClick "hint (""Hello "" + name _this); _shift"; // Hello KK

Additional Information

See also:
onGroupIconClick

Notes

i
Only post proven facts here. Report bugs on the Feedback Tracker and discuss on the Arma Discord or on the Forums.

Notes

Posted on 8 July, 2009
General Barron
See my Multiple OnMapSingleClick script to allow you to add multiple events to the onMapSingleClick event. Some minor editing of the scripts would be required to use them in Arma.

Notes

Bottom Section

Posted on April 1, 2016 - 00:25 (UTC)
Killzone Kid
_units param is supposed to return what groupSelectedUnits returns. Player must be leader and some units in the group must be selected on the group bar. However selected units are connected with group orders menu, which interferes with map click. In other words, when you click on the main map, the map gets focus and group orders menu closes, deselecting any selected unit, so _units is [] pretty much all the time.