IsCursorShowing: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function is used to determine whether or not a player's cursor is showing for 'click-events'.
{{Server client function}}
 
This function is used to determine whether or not a player's cursor is showing.
{{Note|This retrieves the cursor state that has been set using [[showCursor]], and thus doesn't take into account the cursor shown while the chatbox, menu or console are open. Also, keep in mind that while the client is aware of cursor states set from the server, the server doesn't know about cursor states set from the client.}}
==Syntax==  
==Syntax==  
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool isCursorShowing ( player thePlayer )
bool isCursorShowing ( player thePlayer )
Line 8: Line 10:


===Required Arguments===  
===Required Arguments===  
*'''thePlayer''' The player you want to check
*'''thePlayer:''' The [[player]] you want to get cursor state of.
 
===Returns===
Returns ''true'' if the player's cursor is showing, ''false'' if it isn't or if invalid parameters were passed.
</section>


<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool isCursorShowing ( )
</syntaxhighlight>
===Returns===
===Returns===
Returns ''true'' if the player's cursor is showing for 'click-events'.
Returns ''true'' if the player's cursor is showing, ''false'' if it isn't.
</section>


==Example==  
==Example==  
This example shows the players cursor, then prints "success" if it was shown successfully.
<section name="Example" class="server" show="true">
This serverside function toggles a player's cursor state.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
thePlayer = getPlayerFromNick ( "Dave" ) -- grab the player named Dave
function toggleCursor ( thePlayer )
if ( thePlayer ) then -- if we got him
local currentState = isCursorShowing ( thePlayer ) -- get the current cursor state as a boolean
  showCursor ( thePlayer, true ) -- make his cursor show
local oppositeState = not currentState              -- get the new state as its logical opposite
  if ( isCursorShowing ( thePlayer ) ) then -- did it show?
showCursor ( thePlayer, oppositeState )             -- set it as the new cursor state
    outputChatBox ( "success" ) -- print "success" to the chat box
  end
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>
<section name="Clientside Example" class="client" show="true">
With little of tweaking this can also be used clientside
<syntaxhighlight lang="lua">
function toggleCursor ()
        local currentState = isCursorShowing ()  -- get the current cursor state as a boolean
        local oppositeState = not currentState              -- get the new state as its logical opposite
        showCursor ( oppositeState )            -- set it as the new cursor state
end
</syntaxhighlight>
And a more compact version
<syntaxhighlight lang="lua">
[lua]
bindKey ("b", "down",                            -- binds B key to toggle cursor state
        function()
                showCursor( not isCursorShowing() )
        end)
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Cursor_functions}}
{{Cursor_functions}}
[[hu:isCursorShowing]]

Revision as of 10:33, 13 October 2018

This function is used to determine whether or not a player's cursor is showing.

[[{{{image}}}|link=|]] Note: This retrieves the cursor state that has been set using showCursor, and thus doesn't take into account the cursor shown while the chatbox, menu or console are open. Also, keep in mind that while the client is aware of cursor states set from the server, the server doesn't know about cursor states set from the client.

Syntax

Click to collapse [-]
Server
bool isCursorShowing ( player thePlayer )

Required Arguments

  • thePlayer: The player you want to get cursor state of.

Returns

Returns true if the player's cursor is showing, false if it isn't or if invalid parameters were passed.

Click to collapse [-]
Client
bool isCursorShowing ( )

Returns

Returns true if the player's cursor is showing, false if it isn't.

Example

Click to collapse [-]
Example

This serverside function toggles a player's cursor state.

function toggleCursor ( thePlayer )
	local currentState = isCursorShowing ( thePlayer )  -- get the current cursor state as a boolean
	local oppositeState = not currentState              -- get the new state as its logical opposite
	showCursor ( thePlayer, oppositeState )             -- set it as the new cursor state
end
Click to collapse [-]
Clientside Example

With little of tweaking this can also be used clientside

function toggleCursor ()
        local currentState = isCursorShowing ()  -- get the current cursor state as a boolean
        local oppositeState = not currentState              -- get the new state as its logical opposite
        showCursor ( oppositeState )             -- set it as the new cursor state
end

And a more compact version

[lua]
bindKey ("b", "down",                            -- binds B key to toggle cursor state
        function()
                showCursor( not isCursorShowing() )
        end)

See Also