OutputConsole: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(visibleTo is only serverside argument so I changed this page a little)
Line 4: Line 4:


==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 11: 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.}}
{{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==
==Example==
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.
<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.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function publicMessage ( sourcePlayer, command )
function publicMessage ( sourcePlayer, command )
Line 26: Line 33:
addCommandHandler ( "public", publicMessage )
addCommandHandler ( "public", publicMessage )
addCommandHandler ( "private", privateMessage )
addCommandHandler ( "private", privateMessage )
</syntaxhighlight>
</syntaxhighlight></section>
 
 


==See Also==
==See Also==
{{Server functions}}
{{Server functions}}

Revision as of 08:24, 29 July 2014

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.

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 publicMessage ( sourcePlayer, command )
      outputConsole ( "Public console message" )                -- Display console message for all players
end

function privateMessage ( sourcePlayer, command )
      outputConsole ( "Private console message", sourcePlayer ) -- Send message to whoever entered the /private command
end

addCommandHandler ( "public", publicMessage )
addCommandHandler ( "private", privateMessage )

See Also