SetControlState: Difference between revisions
Jump to navigation
Jump to search
m (Moved the section header) |
m (This function is shared) |
||
(7 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{Shared function}} | ||
__NOTOC__ | __NOTOC__ | ||
Sets a state of a specified player's control, as if they pressed or released it. | Sets a state of a specified player's control, as if they pressed or released it. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">bool setControlState ( player thePlayer, string control, bool state ) </syntaxhighlight> | <syntaxhighlight lang="lua">bool setControlState ( player thePlayer, string control, bool state ) </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''thePlayer:''' The player you wish to set the control state of. | *'''thePlayer:''' The player you wish to set the control state of. | ||
Line 16: | Line 11: | ||
===Returns=== | ===Returns=== | ||
Returns 'true' if the control state was successfully set, 'false' otherwise. | Returns ''true'' if the control state was successfully set, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle. | This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onPlayerEnterVehicle ( theVehicle, seat, jacked ) | function onPlayerEnterVehicle ( theVehicle, seat, jacked ) | ||
toggleControl ( source, "accelerate", false ) -- disable the accelerate key | |||
toggleControl ( source, "brake_reverse", false ) -- disable the brake_reverse key | |||
toggleControl ( source, "handbrake", false ) -- disable the handbrake key | |||
setControlState ( source, "accelerate", true ) -- force the accelerate key on | |||
end | end | ||
addEventHandler ( " | addEventHandler ( "onPlayerVehicleEnter", root, onPlayerEnterVehicle ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Changelog== | |||
{{ChangelogHeader}} | |||
{{ChangelogItem|1.5.5-3.11427|Deprecated client-side. Use [[setPedControlState]] and [[getPedControlState]] client-side.}} | |||
==See Also== | ==See Also== | ||
{{Input functions}} | {{Input functions}} |
Latest revision as of 00:00, 30 April 2024
Sets a state of a specified player's control, as if they pressed or released it.
Syntax
bool setControlState ( player thePlayer, string control, bool state )
Required Arguments
- thePlayer: The player you wish to set the control state of.
- control: The control that you want to set the state of. See control names for a list of possible controls.
- state: A boolean value representing whether or not the key will be set to pressed or not.
Returns
Returns true if the control state was successfully set, false otherwise.
Example
This example will disable the use of the accelerate, brake/reverse and handbrake keys, then force the accelerate on for any player who enters a vehicle.
function onPlayerEnterVehicle ( theVehicle, seat, jacked ) toggleControl ( source, "accelerate", false ) -- disable the accelerate key toggleControl ( source, "brake_reverse", false ) -- disable the brake_reverse key toggleControl ( source, "handbrake", false ) -- disable the handbrake key setControlState ( source, "accelerate", true ) -- force the accelerate key on end addEventHandler ( "onPlayerVehicleEnter", root, onPlayerEnterVehicle )
Changelog
Version | Description |
---|
1.5.5-3.11427 | Deprecated client-side. Use setPedControlState and getPedControlState client-side. |
See Also
- addCommandHandler
- bindKey
- executeCommandHandler
- getCommandHandlers
- getFunctionsBoundToKey
- getKeyBoundToFunction
- isControlEnabled
- removeCommandHandler
- toggleAllControls
- toggleControl
- unbindKey