OnActionKey: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Event|Client|1.5.5}} {{FuncDescription|Called when the player pressed a specific key that is an "action". For example the space-bar for jumping.}} {{FuncSyntax|OnActionKey(EventType, ActionName, KeyName)}} {{FuncParameters}} {{FuncParam|EventType|The input event of type EInputEvent}} {{FuncParam|ActionName|The name of the action. For example "Jump".}} {{FuncParam|KeyName|The name of the key as a string.}} == Example == <syntaxhighlight lang="Lua"> function OnA..."
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Info|Event|Client|1.5.5}}
{{Info|Event|Client|1.5.5}}


{{FuncDescription|Called when the player pressed a specific key that is an "action". For example the space-bar for jumping.}}
{{FuncDescription|Called when the player pressed a specific key that is an "action". For example the space-bar for jumping.
 
Returning '''false''' in this function cancels the action.}}


{{FuncSyntax|OnActionKey(EventType, ActionName, KeyName)}}
{{FuncSyntax|OnActionKey(EventType, ActionName, KeyName)}}
Line 9: Line 11:
{{FuncParam|ActionName|The name of the action. For example "Jump".}}
{{FuncParam|ActionName|The name of the action. For example "Jump".}}
{{FuncParam|KeyName|The name of the key as a string.}}
{{FuncParam|KeyName|The name of the key as a string.}}
List of all ActionNames
[[File:ActionNames.PNG]]


== Example ==
== Example ==
<syntaxhighlight lang="Lua">
<syntaxhighlight lang="Lua">
function OnActionKey(EventType, ActionName, KeyName)
function OnActionKey(EventType, ActionName, KeyName)
AddPlayerChat(key)
AddPlayerChat(ActionName)
if ActionName == "Jump" then
if ActionName == "Jump" then
return false -- This will cancel the action. In this case the player is unable to jump.
return false -- This will cancel the action. In this case the player is unable to jump.

Latest revision as of 19:55, 23 February 2022

OnActionKey

Type: Event
Context: Client
Introduced: v1.5.5

Description

Called when the player pressed a specific key that is an "action". For example the space-bar for jumping.

Returning false in this function cancels the action.

Syntax

OnActionKey(EventType, ActionName, KeyName)

Parameters

  • EventType
    The input event of type EInputEvent
  • ActionName
    The name of the action. For example "Jump".
  • KeyName
    The name of the key as a string.

List of all ActionNames

Example

function OnActionKey(EventType, ActionName, KeyName)
	AddPlayerChat(ActionName)
	if ActionName == "Jump" then
		return false -- This will cancel the action. In this case the player is unable to jump.
	end
end
AddEvent("OnActionKey", OnActionKey)

See also