SetPedAnalogControlState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Client function}}  
{{Client function}}  
__NOTOC__  
__NOTOC__  
Sets an analog state of a specified player's control, as if they pressed or released it.
Sets an analog state of a specified [[ped]]'s control, as if they pressed or released it.
 
This function only works on [[ped]]s, to change the analog control state for a player, please use [[setAnalogControlState]].


==Syntax==  
==Syntax==  
Line 9: Line 11:
*'''thePed:''' The ped you wish to set the control state of.
*'''thePed:''' The ped 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.
*'''control:''' The control that you want to set the state of. See [[control names]] for a list of possible controls.
*'''state:''' A float value representing a full analog push ( 1 ) or full release ( 0 ). If no value is provided, the analog control is removed.
*'''state:''' A [[float]] between 0 and 1 indicating the amount the control is pressed.


===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==   
<syntaxhighlight lang="lua">--todo</syntaxhighlight>
This example uses setPedAnalogControlState to very slowly accelerate a ped-controlled NRG-500.
<syntaxhighlight lang="lua">
function createAnalogControlTest( )
    local playerPosition = Vector3( getElementPosition( localPlayer ) )
    local theVehicle = createVehicle( 522, playerPosition )
    local thePed = createPed( 0, playerPosition )
 
    warpPedIntoVehicle( thePed, theVehicle )


==Requirements==
    setPedAnalogControlState( thePed, "accelerate", 0.05 )
{{Requirements|n/a|1.3.0-9.04185|}}
    setPedAnalogControlState( thePed, "vehicle_left", 1 )
end
addCommandHandler( "analogcontroltest", createAnalogControlTest )
</syntaxhighlight>


==See Also==
==See Also==
{{Ped functions}}
{{Client ped functions}}

Latest revision as of 17:04, 7 November 2024

Sets an analog state of a specified ped's control, as if they pressed or released it.

This function only works on peds, to change the analog control state for a player, please use setAnalogControlState.

Syntax

bool setPedAnalogControlState ( ped thePed, string control, float state ) 

Required Arguments

  • thePed: The ped 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 float between 0 and 1 indicating the amount the control is pressed.

Returns

Returns true if the control state was successfully set, false otherwise.

Example

This example uses setPedAnalogControlState to very slowly accelerate a ped-controlled NRG-500.

function createAnalogControlTest( )
    local playerPosition = Vector3( getElementPosition( localPlayer ) )
    local theVehicle = createVehicle( 522, playerPosition )
    local thePed = createPed( 0, playerPosition )

    warpPedIntoVehicle( thePed, theVehicle )

    setPedAnalogControlState( thePed, "accelerate", 0.05 )
    setPedAnalogControlState( thePed, "vehicle_left", 1 )
end
addCommandHandler( "analogcontroltest", createAnalogControlTest )

See Also