IsCursorShowing: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (nevermind)
Tag: Manual revert
 
(14 intermediate revisions by 11 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{Server client function}}
This fake function is for use with blah & blah and does blahblahblabhalbhl
{{Note|This function only handles the cursor state set by the [[showCursor]] function, ignoring it if the console, chatbox, or menu is open.}}
{{Note|If you use this function on the server-side, keep in mind that it only detects the [[showCursor]] function executed on the server-side and does not detect the function executed on the client-side.}}
 
==Purpose==
This function determines the state of a player's cursor.


==Syntax==  
==Syntax==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
returnType functionName ( arguments )
bool isCursorShowing ( player playerElement )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''playerElement:''' The [[player]] from whom we want to retrieve the cursor state.
*'''argumentName:''' description
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool isCursorShowing ( )
</syntaxhighlight>


<!-- Only include this section below if there are optional arguments -->
===No Arguments===  
===Optional Arguments===  
On the client-side, this function doesn't require any arguments because it gets the cursor state of the [[localPlayer]].
{{OptionalArg}}
</section>
*'''argumentName2:''' description
*'''argumentName3:''' description


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if the player's cursor is visible, and ''false'' if it is not.
Returns ''true'' if blah, ''false'' otherwise.
 
==Example==
<section name="Server (Simple)" class="server" show="true">
This example creates a function to set the state of the player's cursor using the [[showCursor]] function.
<syntaxhighlight lang="lua">
function toggleCursor(playerElement)
    if playerElement and isElement(playerElement) then -- Check whether the given element exists
        local cursorState = isCursorShowing(playerElement) -- Retrieve the state of the player's cursor
        local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state
 
        showCursor(playerElement, cursorStateOpposite) -- Setting the new cursor state
    end
end
</syntaxhighlight>
</section>
 
<section name="Server (Complex)" class="server" show="true">
This example creates a function that gets the state of the player's cursor and outputs it to the chatbox using the [[outputChatBox]] function.
<syntaxhighlight lang="lua">
function outputCursor(playerElement)
    if playerElement and isElement(playerElement) then -- Check whether the given element exists
        local cursorState = isCursorShowing(playerElement) -- Retrieve the state of the player's cursor
        local cursorStateText = cursorState and "visible" or "hidden" -- Calculate the context from the boolean variable.
 
        outputChatBox("Your cursor is " .. cursorStateText .. ".", playerElement) -- Output the text in the chatbox according to the cursor state.
    end
end
</syntaxhighlight>
</section>
 
<section name="Client (Simple)" class="client" show="true">
This example creates a function to set the state of the player's cursor using the [[showCursor]] function.
<syntaxhighlight lang="lua">
function toggleCursor()
    local cursorState = isCursorShowing() -- Retrieve the state of the player's cursor
    local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state


==Example==
    showCursor(cursorStateOpposite) -- Setting the new cursor state
<!-- Explain what the example is in a single sentance -->
end
This example does...
</syntaxhighlight>
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
If you are already advanced in scripting, using this code is recommended, as it is much more compact:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function toggleCursor()
blabhalbalhb --abababa
    showCursor(not isCursorShowing())
--This line does this...
end
mooo
</syntaxhighlight>
</syntaxhighlight>
</section>
<section name="Client (Complex)" class="client" show="true">
This example creates a function that allows the player to change the state of the cursor using the [[showCursor]] and [[bindKey]] functions.
<syntaxhighlight lang="lua">
function toggleCursor()
    local cursorState = isCursorShowing() -- Retrieve the state of the player's cursor
    local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state
    showCursor(cursorStateOpposite) -- Setting the new cursor state
end
bindKey("m", "down", toggleCursor) -- Assigning our toggleCursor function to the 'm' key press.
</syntaxhighlight>
If you are already advanced in scripting, using this code is recommended, as it is much more compact:
<syntaxhighlight lang="lua">
bindKey("m", "down",
    function()
        showCursor(not isCursorShowing())
    end
)
</syntaxhighlight>
</section>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Cursor_functions}}
{{FunctionArea_functions}}
 
[[Category:Incomplete]]
[[hu:isCursorShowing]]

Latest revision as of 15:09, 6 November 2024

[[{{{image}}}|link=|]] Note: This function only handles the cursor state set by the showCursor function, ignoring it if the console, chatbox, or menu is open.
[[{{{image}}}|link=|]] Note: If you use this function on the server-side, keep in mind that it only detects the showCursor function executed on the server-side and does not detect the function executed on the client-side.

Purpose

This function determines the state of a player's cursor.

Syntax

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

Required Arguments

  • playerElement: The player from whom we want to retrieve the cursor state.
Click to collapse [-]
Client
bool isCursorShowing ( )

No Arguments

On the client-side, this function doesn't require any arguments because it gets the cursor state of the localPlayer.

Returns

Returns true if the player's cursor is visible, and false if it is not.

Example

Click to collapse [-]
Server (Simple)

This example creates a function to set the state of the player's cursor using the showCursor function.

function toggleCursor(playerElement)
    if playerElement and isElement(playerElement) then -- Check whether the given element exists
        local cursorState = isCursorShowing(playerElement) -- Retrieve the state of the player's cursor
        local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state

        showCursor(playerElement, cursorStateOpposite) -- Setting the new cursor state
    end
end
Click to collapse [-]
Server (Complex)

This example creates a function that gets the state of the player's cursor and outputs it to the chatbox using the outputChatBox function.

function outputCursor(playerElement)
    if playerElement and isElement(playerElement) then -- Check whether the given element exists
        local cursorState = isCursorShowing(playerElement) -- Retrieve the state of the player's cursor
        local cursorStateText = cursorState and "visible" or "hidden" -- Calculate the context from the boolean variable.

        outputChatBox("Your cursor is " .. cursorStateText .. ".", playerElement) -- Output the text in the chatbox according to the cursor state.
    end
end
Click to collapse [-]
Client (Simple)

This example creates a function to set the state of the player's cursor using the showCursor function.

function toggleCursor()
    local cursorState = isCursorShowing() -- Retrieve the state of the player's cursor
    local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state

    showCursor(cursorStateOpposite) -- Setting the new cursor state
end

If you are already advanced in scripting, using this code is recommended, as it is much more compact:

function toggleCursor()
    showCursor(not isCursorShowing())
end
Click to collapse [-]
Client (Complex)

This example creates a function that allows the player to change the state of the cursor using the showCursor and bindKey functions.

function toggleCursor()
    local cursorState = isCursorShowing() -- Retrieve the state of the player's cursor
    local cursorStateOpposite = not cursorState -- The logical opposite of the cursor state

    showCursor(cursorStateOpposite) -- Setting the new cursor state
end

bindKey("m", "down", toggleCursor) -- Assigning our toggleCursor function to the 'm' key press.

If you are already advanced in scripting, using this code is recommended, as it is much more compact:

bindKey("m", "down",
    function()
        showCursor(not isCursorShowing())
    end
)

See Also