ShowChat: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(13 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}  
{{Server client function}}  
This function is used to show or hide the local player's chat.
This function is used to show or hide the player's chat.


==Syntax==
==Syntax==
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool showChat ( bool show [, bool inputBlocked ] )
</syntaxhighlight>
===Required Arguments===
*'''show:''' A boolean value determining whether to show (''true'') or hide (''false'') the chat.
===Optional Arguments===
{{Added feature/item|1.5.9|1.5.8|20898|
*'''inputBlocked:''' A boolean value determining whether chat input is blocked/hidden, regardless of chat visibility. If unset, this will keep the default behaviour prior to r20898 (''true'' when chat is hidden, ''false'' when chat is visible).
}}
===Returns===
Returns ''true'' if the player's chat was shown or hidden successfully, ''false'' otherwise.
</section>
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool showChat ( bool show )
bool showChat ( player thePlayer, bool show [, bool inputBlocked ] )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===  
===Required Arguments===  
*'''thePlayer:''' The [[player]] whose chat is to be hidden or shown.
*'''show:''' A boolean value determining whether to show (''true'') or hide (''false'') the chat.
*'''show:''' A boolean value determining whether to show (''true'') or hide (''false'') the chat.
===Optional Arguments===
{{Added feature/item|1.5.9|1.5.8|20898|
*'''inputBlocked:''' A boolean value determining whether chat input is blocked/hidden, regardless of chat visibility. If unset, this will keep the default behaviour prior to r20898 (''true'' when chat is hidden, ''false'' when chat is visible).
}}


===Returns===
===Returns===
Returns ''true'' if the player's chat was shown or hidden successfully, ''false'' otherwise.
Returns ''true'' if the player's chat was shown or hidden successfully, ''false'' otherwise.
</section>


==Example==  
==Example==  
Line 18: Line 41:
This example toggle's the player's chat when they press the "'''i'''" key.
This example toggle's the player's chat when they press the "'''i'''" key.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local isChatVisible = true -- let's assume the chat is visible
--This example below is for all versions until 1.4:
function chat ( key, keyState )
local isChatVisible = true --Let's assume the chat is visible as soon as the resource starts.
if ( isChatVisible ) then -- if it's on
 
showChat ( false ) -- turn it off
function chat(key, keyState)
isChatVisible = false
    if isChatVisible then --Check or the chat is visible.
else showChat ( true ) -- if it's off
        showChat(false) --If it is, hide it.
isChatVisible = true -- turn it on
        isChatVisible = false
end
    else
        showChat(true) --If it is not, show it.
        isChatVisible = true
    end
end
end
bindKey ( "i", "down", "toggle chat", chat ) -- the player's "i" key will toggle the chat
 
bindKey("i", "down", chat) --Make a bind key to start the function as soon as a player presses the key 'i'
 
 
--This example below is for version 1.4 and up:
function chat(key, keyState)
    if isChatVisible() then --Check or the chat is visible.
        showChat(false) --If it is, hide it.
    else
        showChat(true) --If it is not, show it.
    end
end
 
bindKey("i", "down", chat) --Make a bind key to start the function as soon as a player presses the key 'i'
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


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

Latest revision as of 21:37, 23 September 2021

This function is used to show or hide the player's chat.

Syntax

Click to collapse [-]
Client
bool showChat ( bool show [, bool inputBlocked ] )

Required Arguments

  • show: A boolean value determining whether to show (true) or hide (false) the chat.

Optional Arguments

  • inputBlocked: A boolean value determining whether chat input is blocked/hidden, regardless of chat visibility. If unset, this will keep the default behaviour prior to r20898 (true when chat is hidden, false when chat is visible).

Returns

Returns true if the player's chat was shown or hidden successfully, false otherwise.

Click to collapse [-]
Server
bool showChat ( player thePlayer, bool show [, bool inputBlocked ] )

Required Arguments

  • thePlayer: The player whose chat is to be hidden or shown.
  • show: A boolean value determining whether to show (true) or hide (false) the chat.

Optional Arguments

  • inputBlocked: A boolean value determining whether chat input is blocked/hidden, regardless of chat visibility. If unset, this will keep the default behaviour prior to r20898 (true when chat is hidden, false when chat is visible).

Returns

Returns true if the player's chat was shown or hidden successfully, false otherwise.

Example

Click to collapse [-]
Client

This example toggle's the player's chat when they press the "i" key.

--This example below is for all versions until 1.4:
local isChatVisible = true --Let's assume the chat is visible as soon as the resource starts.

function chat(key, keyState)
    if isChatVisible then --Check or the chat is visible.
        showChat(false) --If it is, hide it.
        isChatVisible = false
    else
        showChat(true) --If it is not, show it.
        isChatVisible = true
    end
end

bindKey("i", "down", chat) --Make a bind key to start the function as soon as a player presses the key 'i'


--This example below is for version 1.4 and up:
function chat(key, keyState)
    if isChatVisible() then --Check or the chat is visible.
        showChat(false) --If it is, hide it.
    else
        showChat(true) --If it is not, show it.
    end
end

bindKey("i", "down", chat) --Make a bind key to start the function as soon as a player presses the key 'i'

See Also