IsControlEnabled: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
__NOTOC__
This fake function is for use with blah & blah and does blahblahblabhalbhl
Checks whether a GTA control is enabled or disabled for a certain player.


==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">
bool isControlEnabled ( player theplayer, string (control) )
bool isControlEnabled ( player thePlayer, string control )
</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 -->
*'''thePlayer:''' The player you wish the control status of.
*'''argumentName:''' description
*'''control:''' The control you wish to check. See [[control names]] for a list of possible controls.
</section>
 
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">bool isControlEnabled ( string control ) </syntaxhighlight>  
 
===Required Arguments===
*'''control:''' The control you wish to check. See [[control names]] for a list of possible controls.
</section>


<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===
{{OptionalArg}}
*'''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 control is enabled, ''false'' otherwise.
Returns ''true'' if blah, ''false'' otherwise.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
<section name="Example 1" class="server" show="true">
This example does...
This example uses a command handler to allow a player to toggle whether he can use vehicle weapons by disabling or enabling the primary and secondary vehicle fire keys. The command handler is trigged with 'toggleweapons'
<!-- 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 -->
<syntaxhighlight lang="lua">function changeWeaponControls ( player, commandName )
<syntaxhighlight lang="lua">
--Check to see if the player can use primary/secondary vehicle fire controls
--This line does...
        primaryWeaponControl = isControlEnabled ( player, "vehicle_fire" )
blabhalbalhb --abababa
        secondaryWeaponControl = isControlEnabled ( player, "vehicle_secondary_fire" )
--This line does this...
--Toggle the use of the primary vehicle fire control ability.
mooo
        if ( primaryWeaponControl == true ) then
</syntaxhighlight>
            toggleControl ( player, "vehicle_fire", false )
        outputChatBox ( "Disabled your ability to use primary vehicle weapons." )
        else
            toggleControl ( player, "vehicle_fire", true )
        outputChatBox ( "Enabled your ability to use primary vehicle weapons." )
        end
        --Toggle the use of the secondar vehicle fire control ability.
        if ( secondaryWeaponControl == true ) then
            toggleControl ( player, "vehicle_secondary_fire", false )
        outputChatBox ( "Disabled your ability to use secondary vehicle weapons." )
        else
            toggleControl ( player, "vehicle_secondary_fire", true )
        outputChatBox ( "Enabled your ability to use secondary vehicle weapons." )
        end
end 
addCommandHandler ( "toggleweapons", changeWeaponControls )</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 -->
{{Input functions}}
{{FunctionArea_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function

Latest revision as of 19:54, 1 April 2013

Checks whether a GTA control is enabled or disabled for a certain player.

Syntax

Click to collapse [-]
Server
bool isControlEnabled ( player thePlayer, string control )

Required Arguments

  • thePlayer: The player you wish the control status of.
  • control: The control you wish to check. See control names for a list of possible controls.
Click to collapse [-]
Client
bool isControlEnabled ( string control ) 

Required Arguments

  • control: The control you wish to check. See control names for a list of possible controls.


Returns

Returns true if control is enabled, false otherwise.

Example

Click to collapse [-]
Example 1

This example uses a command handler to allow a player to toggle whether he can use vehicle weapons by disabling or enabling the primary and secondary vehicle fire keys. The command handler is trigged with 'toggleweapons'

function changeWeaponControls ( player, commandName )
	--Check to see if the player can use primary/secondary vehicle fire controls
        primaryWeaponControl = isControlEnabled ( player, "vehicle_fire" )
        secondaryWeaponControl = isControlEnabled ( player, "vehicle_secondary_fire" )
	--Toggle the use of the primary vehicle fire control ability.
        if ( primaryWeaponControl == true ) then
             toggleControl ( player, "vehicle_fire", false )
    	     outputChatBox ( "Disabled your ability to use primary vehicle weapons." )
        else
             toggleControl ( player, "vehicle_fire", true )
    	     outputChatBox ( "Enabled your ability to use primary vehicle weapons." )
        end
        --Toggle the use of the secondar vehicle fire control ability.
        if ( secondaryWeaponControl == true ) then
             toggleControl ( player, "vehicle_secondary_fire", false )
    	     outputChatBox ( "Disabled your ability to use secondary vehicle weapons." )
        else
             toggleControl ( player, "vehicle_secondary_fire", true )
    	     outputChatBox ( "Enabled your ability to use secondary vehicle weapons." )
        end
end  
addCommandHandler ( "toggleweapons", changeWeaponControls )

See Also