ToggleControl: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
 
(18 intermediate revisions by 14 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
Enables or disables the use of a gta control for a specified player.
{{Server client function}}
Enables or disables the use of a GTA control for a specific player.
{{Note| If you want to disable weapons fire, remember to also disable the control '''action''' in addition to the control '''fire'''.}}


==Syntax==  
==Syntax==  
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">bool toggleControl ( player thePlayer, string control, bool enabled ) </syntaxhighlight>  
<syntaxhighlight lang="lua">bool toggleControl ( player thePlayer, string control, bool enabled ) </syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''thePlayer:''' The player you wish to toggle the control ability of.
*'''thePlayer:''' The player you wish to toggle the control ability of.
*'''control:''' The control that you want to toggle the ability of.
*'''control:''' The control that you want to toggle the ability of. See [[control names]] for a list of possible controls.
*'''enable:''' A boolean value representing whether or not the key will be usable or not.
*'''enabled:''' A boolean value representing whether or not the key will be usable or not.
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">bool toggleControl ( string control, bool enabled ) </syntaxhighlight>
 
===Required Arguments===
*'''control:''' The control that you want to toggle the ability of. See [[control names]] for a list of possible controls.
*'''enabled:''' A boolean value representing whether or not the key will be usable or not.
</section>
 
==Returns==
This function ''true'' if the control was set successfully, ''false'' otherwise.


==Example==   
==Example==   
This function will disable the use of the vehicle secondary-fire key for anyone in a hydra, consequently removing the ability to fire rockets.
<section name="Example 1" class="server" show="true">
This function will disable the use of the vehicle secondary-fire key for anyone in a Hydra, consequently removing the ability to fire rockets.
<syntaxhighlight lang="lua">
function disableFireForHydra ( theVehicle, seat, jacked )
    if ( getElementModel ( theVehicle ) == 520 ) then -- if they entered a hydra
        toggleControl ( source, "vehicle_secondary_fire", false ) -- disable their fire key
    else -- if they entered another vehicle
        toggleControl ( source, "vehicle_secondary_fire", true ) -- enable their fire key
    end
end
addEventHandler ( "onPlayerVehicleEnter", root, disableFireForHydra )
</syntaxhighlight>
</section>
<section name="Example 2" class="client" show="true">
This function will disable the use of the vehicle secondary-fire key for anyone in a Hydra, consequently removing the ability to fire rockets.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerEnterVehicle", root, "onPlayerEnterVehicle" )
function disableFireForHydra ( theVehicle, seat )
function onPlayerEnterVehicle ( theVehicle, seat, jacked )
    if ( getElementModel ( theVehicle ) == 520 ) then -- if they entered a hydra
  if ( getVehicleID ( theVehicle ) == 520 ) then -- if they entered a hydra
        toggleControl ( "vehicle_secondary_fire", false ) -- disable their fire key
    toggleControl ( source, "vehicle_secondary_fire", false ) -- disable their fire key
    else -- if they entered another vehicle
  else -- if they entered another vehicle
        toggleControl ( "vehicle_secondary_fire", true ) -- enable their fire key
    toggleControl ( source, "vehicle_secondary_fire", true ) -- enable their fire key
    end
  end
end
end
addEventHandler ( "onClientPlayerVehicleEnter", localPlayer, disableFireForHydra )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Input functions}}
{{Input functions}}

Latest revision as of 08:43, 4 November 2020

Enables or disables the use of a GTA control for a specific player.

[[{{{image}}}|link=|]] Note: If you want to disable weapons fire, remember to also disable the control action in addition to the control fire.

Syntax

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

Required Arguments

  • thePlayer: The player you wish to toggle the control ability of.
  • control: The control that you want to toggle the ability of. See control names for a list of possible controls.
  • enabled: A boolean value representing whether or not the key will be usable or not.
Click to collapse [-]
Client
bool toggleControl ( string control, bool enabled ) 

Required Arguments

  • control: The control that you want to toggle the ability of. See control names for a list of possible controls.
  • enabled: A boolean value representing whether or not the key will be usable or not.

Returns

This function true if the control was set successfully, false otherwise.

Example

Click to collapse [-]
Example 1

This function will disable the use of the vehicle secondary-fire key for anyone in a Hydra, consequently removing the ability to fire rockets.

function disableFireForHydra ( theVehicle, seat, jacked )
    if ( getElementModel ( theVehicle ) == 520 ) then -- if they entered a hydra
        toggleControl ( source, "vehicle_secondary_fire", false ) -- disable their fire key
    else -- if they entered another vehicle
        toggleControl ( source, "vehicle_secondary_fire", true ) -- enable their fire key
    end
end
addEventHandler ( "onPlayerVehicleEnter", root, disableFireForHydra )
Click to collapse [-]
Example 2

This function will disable the use of the vehicle secondary-fire key for anyone in a Hydra, consequently removing the ability to fire rockets.

function disableFireForHydra ( theVehicle, seat )
    if ( getElementModel ( theVehicle ) == 520 ) then -- if they entered a hydra
        toggleControl ( "vehicle_secondary_fire", false ) -- disable their fire key
    else -- if they entered another vehicle
        toggleControl ( "vehicle_secondary_fire", true ) -- enable their fire key
    end
end
addEventHandler ( "onClientPlayerVehicleEnter", localPlayer, disableFireForHydra )

See Also