ToggleControl: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(8 intermediate revisions by 7 users not shown)
Line 10: Line 10:
*'''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. See [[control names]] for a list of possible controls.
*'''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>
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
Line 17: Line 17:
===Required Arguments===  
===Required Arguments===  
*'''control:''' The control that you want to toggle the ability of. See [[control names]] for a list of possible controls.
*'''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>


Line 28: Line 28:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function disableFireForHydra ( theVehicle, seat, jacked )
function disableFireForHydra ( theVehicle, seat, jacked )
     if ( getVehicleID ( theVehicle ) == 520 ) then -- if they entered a hydra
     if ( getElementModel ( theVehicle ) == 520 ) then -- if they entered a hydra
         toggleControl ( source, "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
Line 34: Line 34:
     end
     end
end
end
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), disableFireForHydra )
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), disableFireForHydra )
</syntaxhighlight>
</syntaxhighlight>
''Note: The same can be achieved by using [[setVehicleGunsEnabled]]''.
</section>
</section>
<section name="Example 2" class="client" show="false">
<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.
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">
function disableFireForHydra ( theVehicle, seat )
function disableFireForHydra ( theVehicle, seat )
     if ( getVehicleID ( theVehicle ) == 520 ) then -- if they entered a hydra
     if ( getElementModel ( theVehicle ) == 520 ) then -- if they entered a hydra
         toggleControl ( "vehicle_secondary_fire", false ) -- disable their fire key
         toggleControl ( "vehicle_secondary_fire", false ) -- disable their fire key
     else -- if they entered another vehicle
     else -- if they entered another vehicle
Line 48: Line 47:
     end
     end
end
end
addEventHandler ( "onClientPlayerEnterVehicle", getLocalPlayer(), disableFireForHydra )
addEventHandler ( "onClientPlayerVehicleEnter", getLocalPlayer(), disableFireForHydra )
</syntaxhighlight>
</syntaxhighlight>
''Note: The same can be achieved by using [[setVehicleGunsEnabled]]''.
</section>
</section>


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

Revision as of 13:53, 14 September 2017

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

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", getRootElement(), 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", getLocalPlayer(), disableFireForHydra )

See Also