inGameUISetEventHandler: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\[\[Category:[ _]?Scripting[ _]Commands[ _]Take[ _]On[ _]Helicopters(\|.*)?\]\]" to "{{GameCategory|tkoh|Scripting Commands}}")
m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(80 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma1 |Game name=
|game1= arma1
|1.00|Game version=
|version1= 1.00


|eff= local|Multiplayer Effects=
|game2= arma2
|version2= 1.00


|gr1= GUI Control - Event Handlers |GROUP1=
|game3= arma2oa
|gr2= Event Handlers |GROUP2=
|version3= 1.50
|gr3= Interaction |GROUP3=
____________________________________________________________________________________________


| Sets given event handler of in-game UI. If EH function returns [[true]], performed action is overridden. Event handlers available are:
|game4= tkoh
|version4= 1.00
 
|game5= arma3
|version5= 0.50
 
|eff= local
 
|gr1= GUI Control - Event Handlers
|gr2= Event Handlers
|gr3= Interaction
 
|descr= Sets given event handler of in-game UI. If EH function returns [[true]], performed action is overridden. Event handlers available are:
* "PrevAction" - mouse scroll up
* "PrevAction" - mouse scroll up
* "Action" - action key press
* "Action" - action key press
* "NextAction" - mouse scroll down
* "NextAction" - mouse scroll down
This is "set" type EH, which means it will replace previously set EH of the same type. So to remove EH, set another one with empty string "" for the function.
In order to remove a previously added event handler, set it again with an empty ''code'' string {{hl|""}}.
<br><br>
Since Arma 3 v1.49.131743 this EH returns array of params for selected/activated action in ''_this'' variable:
* 0: [[Object]] - target object to which action is attached
* 1: [[Object]] - caller object, basically [[player]]
* 2: [[Number]] - index of the action in action menu (0 - top most)
* 3: [[String]] - engine based action name ("User" for user added actions)
* 4: [[String]] - [[localize]]d action plain text as seen by the caller
* 5: [[Number]] - action ''priority'' value
* 6: [[Boolean]] - action ''showWindow'' value
* 7: [[Boolean]] - action ''hideOnUse'' value
* 8: [[String]] - action ''shortcut'' name or ""
* 9: [[Boolean]] - action menu visibility (on first scroll or action press the menu is still invisible, so no action is performed, only menu is shown). See also: [[isActionMenuVisible]]
* 10: [[String]] - EH event name|DESCRIPTION=
____________________________________________________________________________________________


| '''inGameUISetEventHandler''' [handlerName, function] |SYNTAX=
{{Feature|important|This is a "set" command, which means event handlers are not stackable and will replace previously set event handlers of the same type.}}


|p1= [handlerName, function]: [[Array]] |PARAMETER1=
{{Feature|arma3|Since {{arma3}} v1.50 the event handler receives an array of the selected/activated action's arguments in {{hl|_this}} variable:
|p2= handlerName: [[String]] |PARAMETER2=
<sqf>params ["_target", "_caller", "_index", "_engineName", "_text", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_visibleMenu", "_eventName"];</sqf>
* _target: [[Object]] - target object to which action is attached
* _caller: [[Object]] - caller object, basically [[player]]
* _index: [[Number]] - index of the action in action menu (0 - top most)
* _engineName: [[String]] - engine based action name ("User" for user added actions)
* _text: [[String]] - [[localize]]d action plain text as seen by the caller
* _priority: [[Number]] - action ''priority'' value
* _showWindow: [[Boolean]] - action ''showWindow'' value
* _hideOnUse: [[Boolean]] - action ''hideOnUse'' value
* _shortcut: [[String]] - action ''shortcut'' name or ""
* _visibleMenu: [[Boolean]] - [[isActionMenuVisible|action menu visibility]] - on first scroll or action press the menu is still invisible, the menu is shown but no action is performed
* _eventName: [[String]] - event name
}}


|p3= function: [[String]] |PARAMETER3=
|s1= [[inGameUISetEventHandler]] [handlerName, code]


|p1= handlerName: [[String]]


| [[Nothing]] |RETURNVALUE=
|p2= code: [[String]]


|x1= <code>[[inGameUISetEventHandler]] ["Action","hint 'Lights, Camera, Action!'; [[true]]"];</code>|EXAMPLE1=
|r1= [[Nothing]]


|x2= <code>[[inGameUISetEventHandler]] ["PrevAction", "[[hint]] [[str]] _this; [[false]]"];
|x1= <sqf>
[[inGameUISetEventHandler]] ["NextAction", "[[hint]] [[str]] _this; [[false]]"];
inGameUISetEventHandler ["Action", "hint 'Lights, Camera, Action!'; true"];
[[inGameUISetEventHandler]] ["Action", "[[hint]] [[str]] _this; [[false]]"];</code>|EXAMPLE2=
sleep 10;
inGameUISetEventHandler ["Action", ""]; // removes the "Action" EH
</sqf>


|x3= Deny any weapon disassembly: <code>[[inGameUISetEventHandler]] ["Action", "
|x2= <sqf>
[[if]] (_this [[select]] 3 == 'DisAssemble') [[then]] {
inGameUISetEventHandler ["PrevAction", "hint str _this; false"];
[[hint]] 'You are not allowed to do this';  
inGameUISetEventHandler ["NextAction", "hint str _this; false"];
[[true]]
inGameUISetEventHandler ["Action", "hint str _this; false"];
</sqf>
 
|x3= Deny any weapon disassembly:
<sqf>
inGameUISetEventHandler ["Action", "
if (_this select 3 == 'DisAssemble') then {
hint 'You are not allowed to do this';
true
}
}
"];</code>|EXAMPLE3=
"];
</sqf>


|x4= Detect explosive/mine placement:<code>onMagazineUse = '
|x4= Detect explosive/mine placement:
[[params]] ["_target", "", "", "_action", "", "", "", "", "", "", "_event"];
<sqf>
[[if]] (_action == "UseMagazine") [[then]] {
private _onMagazineUse = '
[[if]] (_event == "Action") [[then]] {
params ["_target", "", "", "_action", "", "", "", "", "", "", "_event"];
0 = _target [[spawn]] {
if (_action == "UseMagazine") then {
[[waitUntil]] {!(all_magazines [[isEqualTo]] [[magazines]] _this)};
if (_event == "Action") then {
_target spawn {
waitUntil {!(all_magazines isEqualTo magazines _this)};
{
{
0 = all_magazines [[deleteAt]] (all_magazines [[find]] _x);
0 = all_magazines deleteAt (all_magazines find _x);
} [[count]] [[magazines]] _this;
} count magazines _this;
[[hint]] [[format]] ["Magazine Used: %1", all_magazines [[select]] 0];
hint format ["Magazine Used: %1", all_magazines select 0];
}
};
} [[else]] {
} else {
all_magazines = [[magazines]] _target;
all_magazines = magazines _target;
};
};
};
};
[[false]]
false
';
';
[[inGameUISetEventHandler]] ["PrevAction", onMagazineUse];
inGameUISetEventHandler ["PrevAction", _onMagazineUse];
[[inGameUISetEventHandler]] ["NextAction", onMagazineUse];
inGameUISetEventHandler ["NextAction", _onMagazineUse];
[[inGameUISetEventHandler]] ["Action", onMagazineUse];</code>|EXAMPLE4=
inGameUISetEventHandler ["Action", _onMagazineUse];
____________________________________________________________________________________________
</sqf>


| [[isActionMenuVisible]], [[addEventHandler]], [[ctrlAddEventHandler]], [[displayAddEventHandler]], [[actionIDs]], [[actionParams]], [[addAction]], [[setUserActionText]], [[showHUD]], [[inputAction]], [[removeAction]], [[removeAllActions]], [[action]], [[enableWeaponDisassembly]] |SEEALSO=
|seealso= [[isActionMenuVisible]] [[addEventHandler]] [[ctrlAddEventHandler]] [[displayAddEventHandler]] [[actionIDs]] [[actionParams]] [[addAction]] [[setUserActionText]] [[showHUD]] [[inputAction]] [[removeAction]] [[removeAllActions]] [[action]] [[enableWeaponDisassembly]]
}}


{{Note
|user= AgentRev
|timestamp= 20160512205100
|text= In case of the "Action" event, (''_showWindow'' {{!}}{{!}} ''_visibleMenu'') also denotes if the action is performed or not. For example, if the action menu is closed or fading off, pressing Spacebar will bring it up and trigger an "Action" event; in that case, ''_visibleMenu'' is false. But if the action menu is open, and Spacebar is pressed to perform the selected action, then ''_visibleMenu'' will be true. If ''_showWindow'' is true, then it means the action was performed, regardless of ''_visibleMenu''.
}}
}}
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section END -->
</dl>
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|INGAMEUISETEVENTHANDLER]]
{{GameCategory|arma1|Scripting Commands}}
{{GameCategory|arma2|Scripting Commands}}
{{GameCategory|arma3|Scripting Commands}}
{{GameCategory|tkoh|Scripting Commands}}
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on May 12, 2016 - 20:51 (UTC)</dd>
<dt class="note">[[User:AgentRevolution|AgentRev]]</dt>
<dd class="note">
In case of the "Action" event, (param 6 || param 9) also denotes if the action is performed or not. For example, if the action menu is closed or fading off, pressing Spacebar will bring it up and trigger an "Action" event; in that case, param 9 (action menu visibility) is false. But if the action menu is open, and Spacebar is pressed to perform the selected action, then param 9 will be true. If param 6 (showWindow) is true, then it means the action was performed, regardless of param 9.
</dd>
</dl>
<!-- DISCONTINUE Notes -->
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on February 08, 2017 - 18:53 (UTC)</dd>
<dt class="note">[[User:Pierre MGI|Pierre MGI]]</dt>
<dd class="note">
This powerful command can override the actions (previous/next/action), depending on true/false return.<br>But, the command overrides itself, no matter of the returned value. That means, if two mods or scripts are using the same command parameter, say 'action', the last inGameUISetEventHandler 'action' will override the first one.<br>Example:<br>trigger1 :
<code>inGameUISetEventHandler ["Action","hint 'action for mod 1';true "];// true or false doesn't matter here</code>
trigger2 (delayed):
<code>inGameUISetEventHandler ["Action","false "];// true or false doesn't matter here</code>
trigger2 will run after trigger1, then, you'll never see the hint, what ever the trigger2 action code could be. What ever could be the last code, it will override all previous ones.<br>You have to group these codes in a same event handler.<br>But, beyond this, inGameUISetEventHandler is not stackable and implies a competition between scripts (or mods) using it.
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 19:43, 3 September 2024

Hover & click on the images for description

Description

Description:
Sets given event handler of in-game UI. If EH function returns true, performed action is overridden. Event handlers available are:
  • "PrevAction" - mouse scroll up
  • "Action" - action key press
  • "NextAction" - mouse scroll down
In order to remove a previously added event handler, set it again with an empty code string "".
This is a "set" command, which means event handlers are not stackable and will replace previously set event handlers of the same type.
Arma 3
Since Arma 3 v1.50 the event handler receives an array of the selected/activated action's arguments in _this variable:

params ["_target", "_caller", "_index", "_engineName", "_text", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_visibleMenu", "_eventName"];

  • _target: Object - target object to which action is attached
  • _caller: Object - caller object, basically player
  • _index: Number - index of the action in action menu (0 - top most)
  • _engineName: String - engine based action name ("User" for user added actions)
  • _text: String - localized action plain text as seen by the caller
  • _priority: Number - action priority value
  • _showWindow: Boolean - action showWindow value
  • _hideOnUse: Boolean - action hideOnUse value
  • _shortcut: String - action shortcut name or ""
  • _visibleMenu: Boolean - action menu visibility - on first scroll or action press the menu is still invisible, the menu is shown but no action is performed
  • _eventName: String - event name
Groups:
GUI Control - Event HandlersEvent HandlersInteraction

Syntax

Syntax:
inGameUISetEventHandler [handlerName, code]
Parameters:
handlerName: String
code: String
Return Value:
Nothing

Examples

Example 1:
inGameUISetEventHandler ["Action", "hint 'Lights, Camera, Action!'; true"]; sleep 10; inGameUISetEventHandler ["Action", ""]; // removes the "Action" EH
Example 2:
inGameUISetEventHandler ["PrevAction", "hint str _this; false"]; inGameUISetEventHandler ["NextAction", "hint str _this; false"]; inGameUISetEventHandler ["Action", "hint str _this; false"];
Example 3:
Deny any weapon disassembly:
inGameUISetEventHandler ["Action", " if (_this select 3 == 'DisAssemble') then { hint 'You are not allowed to do this'; true } "];
Example 4:
Detect explosive/mine placement:
private _onMagazineUse = ' params ["_target", "", "", "_action", "", "", "", "", "", "", "_event"]; if (_action == "UseMagazine") then { if (_event == "Action") then { _target spawn { waitUntil {!(all_magazines isEqualTo magazines _this)}; { 0 = all_magazines deleteAt (all_magazines find _x); } count magazines _this; hint format ["Magazine Used: %1", all_magazines select 0]; }; } else { all_magazines = magazines _target; }; }; false '; inGameUISetEventHandler ["PrevAction", _onMagazineUse]; inGameUISetEventHandler ["NextAction", _onMagazineUse]; inGameUISetEventHandler ["Action", _onMagazineUse];

Additional Information

See also:
isActionMenuVisible addEventHandler ctrlAddEventHandler displayAddEventHandler actionIDs actionParams addAction setUserActionText showHUD inputAction removeAction removeAllActions action enableWeaponDisassembly

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
AgentRev - c
Posted on May 12, 2016 - 20:51 (UTC)
In case of the "Action" event, (_showWindow || _visibleMenu) also denotes if the action is performed or not. For example, if the action menu is closed or fading off, pressing Spacebar will bring it up and trigger an "Action" event; in that case, _visibleMenu is false. But if the action menu is open, and Spacebar is pressed to perform the selected action, then _visibleMenu will be true. If _showWindow is true, then it means the action was performed, regardless of _visibleMenu.