OutputConsole: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(added notes about limitations)
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
__NOTOC__
This outputs the specified text string to the console window (accessed with F8 or ~ key). It can be specified as a message to certain player(s) or all players.
This outputs the specified text string to the console window (accessed with F8 or ~ key). It can be specified as a message to certain player(s) or all players.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">bool outputConsole ( string text, [ element visibleTo=getrootelement() ] )</syntaxhighlight>  
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">bool outputConsole ( string text )</syntaxhighlight>
 
===Required Arguments===
*'''text:''' The text string that you wish to send to the console window
</section>
 
<section name="Server" class="server" show="true"><syntaxhighlight lang="lua">bool outputConsole ( string text, [ element visibleTo=getRootElement() ] )</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
Line 10: Line 18:
===Optional Arguments===  
===Optional Arguments===  
*'''visibleTo:''' This specifies who the chat is visible to. Any players in this element will see the chat message. See [[visibility]].
*'''visibleTo:''' This specifies who the chat is visible to. Any players in this element will see the chat message. See [[visibility]].
{{Note|'''visibleTo''' can also be a Team object, in this case, the text will be visible to all the players of that team.}}</section>


==Example==  
==Remarks==
<syntaxhighlight lang="lua">root = getRootElement ()
The serverside function has a limitation of 1000 characters for the text parameter. Anything beyond 1000 characters is trimmed away. This limitation does not apply to the clientside version.
addEventHandler ( "onPlayerConsole", root, "onConsole" )
 
function onConsole ( message )
==Example==
local command = gettok(message, 1, 32) --The varible "command" equals text a player types in the console
<section name="Server" class="server" show="true">This code creates two console commands. One, 'public', will post a message in the consoles of all players, and the other, 'private', will post a message in only the console of the player that executed the command.
if (command == "!public") then --If players typed text equals !public
<syntaxhighlight lang="lua">
outputChatBox ( "Public console message" ) --Display console message to all players
function message(player,command)
elseif (command == "!private") then --If players typed text equals !private
if command == "public" then
        outputChatBox ( "Private console message", source ) --Send message to whoever entered the text !private
outputConsole("Public console message")
else
outputConsole("Private console message",player)
end
end
end</syntaxhighlight>
end
addCommandHandler("public",message)
addCommandHandler("private",message)
</syntaxhighlight></section>
 
==See Also==
{{Server functions}}

Latest revision as of 10:54, 18 January 2020

This outputs the specified text string to the console window (accessed with F8 or ~ key). It can be specified as a message to certain player(s) or all players.

Syntax

Click to collapse [-]
Client
bool outputConsole ( string text )

Required Arguments

  • text: The text string that you wish to send to the console window
Click to collapse [-]
Server
bool outputConsole ( string text, [ element visibleTo=getRootElement() ] )

Required Arguments

  • text: The text string that you wish to send to the console window

Optional Arguments

  • visibleTo: This specifies who the chat is visible to. Any players in this element will see the chat message. See visibility.
[[{{{image}}}|link=|]] Note: visibleTo can also be a Team object, in this case, the text will be visible to all the players of that team.

Remarks

The serverside function has a limitation of 1000 characters for the text parameter. Anything beyond 1000 characters is trimmed away. This limitation does not apply to the clientside version.

Example

Click to collapse [-]
Server
This code creates two console commands. One, 'public', will post a message in the consoles of all players, and the other, 'private', will post a message in only the console of the player that executed the command.
function message(player,command)
	if command == "public" then
		outputConsole("Public console message")
	else
		outputConsole("Private console message",player)
	end
end
addCommandHandler("public",message)
addCommandHandler("private",message)

See Also