OutputConsole: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
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>  
<syntaxhighlight lang="lua">bool outputConsole ( string text, [ element visibleTo=getRootElement() ] )</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
Line 12: Line 13:
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.


==Example==  
==Example==
<syntaxhighlight lang="lua">root = getRootElement ()
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.
addCommandHandler ( "onPlayerConsole", root, "onConsole" )
<syntaxhighlight lang="lua">
function onConsole ( message )
function publicMessage ( sourcePlayer, command )
local command = gettok(message, 1, 32) --The varible "command" equals text a player types in the console
      outputConsole ( "Public console message" )               -- Display console message for all players
if (command == "!public") then --If players typed text equals !public
end
outputConsole ( "Public console message" ) --Display console message to all players
 
elseif (command == "!private") then --If players typed text equals !private
function privateMessage ( sourcePlayer, command )
        outputConsole ( "Private console message", source ) --Send message to whoever entered the text !private
      outputConsole ( "Private console message", sourcePlayer ) -- Send message to whoever entered the /private command
end
end
end</syntaxhighlight>
 
addCommandHandler ( "public", publicMessage )
addCommandHandler ( "private", privateMessage )
</syntaxhighlight>





Revision as of 18:22, 16 August 2007

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

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.

Note: visibleTo can also be a Team object, in this case, the text will be visible to all the players of that team.

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.

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