OnConsole: Difference between revisions
Jump to navigation
Jump to search
m (See Also for server events) |
m (→Example) |
||
Line 17: | Line 17: | ||
:'''NOTE:''' this script is for example purposes only. This can be done in a more efficient way with [[addCommandHandler]]. | :'''NOTE:''' this script is for example purposes only. This can be done in a more efficient way with [[addCommandHandler]]. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function input_Console ( text ) --when a player types in the console | function input_Console ( text ) --when a player types in the console | ||
-- if it's an ingame player, | -- if it's an ingame player, | ||
Line 34: | Line 33: | ||
end | end | ||
end | end | ||
addEventHandler ( "onConsole", getRootElement(), input_Console ) -- add an event handler for onConsole | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Client events}} | {{See also/Server event|Client events}} |
Revision as of 08:00, 24 February 2008
This event is triggered when a player types a message into his console.
Parameters
string theMessage
- theMessage: a string representing the message typed into the console.
Source
The source of this event is the client that entered the message in the console. This can be a player or the server console.
Example
This example adds the me command into the script. For example, if a player called Bob types "me likes pie" in console, it will display "* Bob likes pie" in the chatbox.
- NOTE: this script is for example purposes only. This can be done in a more efficient way with addCommandHandler.
function input_Console ( text ) --when a player types in the console -- if it's an ingame player, if ( getElementType ( source ) == "player" ) then --split the command by spaces (ASCII 32) and get the first piece of text local command = gettok ( text, 1, 32 ) --if the first piece of text was "me", if ( command == "me" ) then --get the player's name local playerName = getClientName ( source ) -- get the action text by substracting the first three characters ("me ") local actionText = string.sub ( text, 3 ) -- announce the me command into the chatbox outputChatBox ( "* " .. playerName .. " " .. actionText, getRootElement(), 255, 255, 0 ) end end end addEventHandler ( "onConsole", getRootElement(), input_Console ) -- add an event handler for onConsole
See Also
Client events
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled