Difference between revisions of "ToggleControl"

From Multi Theft Auto: Wiki
m (Needs checking!)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
{{Server client function}}
 
{{Server client function}}
 +
{{Needs Checking|By enabling a control all bindings belonging to it seem to be deleted. (tested clientside) --[[User:NeonBlack|NeonBlack]] 16:48, 28 August 2009 (UTC)}}
 
Enables or disables the use of a GTA control for a specific player.
 
Enables or disables the use of a GTA control for a specific player.
  

Revision as of 16:48, 28 August 2009

Dialog-information.png This article needs checking.

Reason(s): By enabling a control all bindings belonging to it seem to be deleted. (tested clientside) --NeonBlack 16:48, 28 August 2009 (UTC)

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.
  • enable: 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.
  • enable: 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 ( getVehicleID ( 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 )

Note: The same can be achieved by using setVehicleGunsEnabled.

Click to expand [+]
Example 2

See Also