ToggleControl: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 12: | Line 12: | ||
==Example== | ==Example== | ||
<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. | 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"> | ||
Line 24: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
''Note: The same can be achieved by using [[setVehicleGunsEnabled]]''. | ''Note: The same can be achieved by using [[setVehicleGunsEnabled]]''. | ||
</section> | |||
<section name="Example 2" class="client" show="false"> | |||
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 ( 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 ( "onClientPlayerEnterVehicle", getLocalPlayer(), disableFireForHydra ) | |||
</syntaxhighlight> | |||
''Note: The same can be achieved by using [[setVehicleGunsEnabled]]''. | |||
</section> | |||
==See Also== | ==See Also== | ||
{{Input functions}} | {{Input functions}} |
Revision as of 14:51, 29 August 2007
Enables or disables the use of a GTA control for a specific player.
Syntax
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.
Example
Click to collapse [-]
Example 1This 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 ( "onPlayerEnterVehicle", getRootElement(), disableFireForHydra )
Note: The same can be achieved by using setVehicleGunsEnabled.
Click to expand [+]
Example 2See Also
- addCommandHandler
- bindKey
- executeCommandHandler
- getCommandHandlers
- getFunctionsBoundToKey
- getKeyBoundToFunction
- isControlEnabled
- removeCommandHandler
- toggleAllControls
- toggleControl
- unbindKey