GetPedAnalogControlState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Remove obsolete Requirements section)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
{{Needs_Example}}
This function retrieves the analog control state of a [[ped]], as set by [[setPedAnalogControlState]].
This function retrieves the analog control state of a ped, as set by [[setPedAnalogControlState]].


==Syntax==
==Syntax==
Line 12: Line 11:


===Optional Arguments===
===Optional Arguments===
{{New feature/item|3.0160|1.5.7|20383|
{{New feature/item|3.0158|1.5.7|20383|
*'''rawValue:''' A bool indicating if it should return the raw player input value (will always return script value for non-player peds).
*'''rawValue:''' A [[bool]] indicating if it should return the raw player input value (will always return script value for non-player peds).
}}
}}


===Returns===
===Returns===
Returns a float between 0 ( full release ) and 1 ( full push ) indicating the amount the control is pushed.
Returns a [[float]] between 0 (full release) and 1 (full push) indicating the amount the control is pushed.


<section name="Client-side example" class="client" show="true">
==Example==
This exmaple creating a ped can drive with command '''/drive'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
x, y, z = getElementPosition(localPlayer)
local ped = createPed(0, 0,0,3)
rotX, rotY, rotZ = getElementRotation(localPlayer)
local vehicle = createVehicle(554,0,0,3)
CJ = createPed(0, x, y, z)
warpPedIntoVehicle(ped, vehicle)
CJ2 = createPed(0, x, y, z)
copcar = createVehicle(597, x, y+5, z+2)
copcar2 = createVehicle(597, x+2, y+10, z+4)
warpPedIntoVehicle(CJ2, copcar2, 0)
warpPedIntoVehicle(CJ, copcar, 0)


function onGetCJAnalogControlState()
addCommandHandler("drive",function()
setPedAnalogControlState(CJ, "accelerate", 0.90)
    isDriving = getPedAnalogControlState ( ped, "accelerate" ) -- get the analaog state of (accelerate)
if getPedAnalogControlState(CJ, "accelerate", 0.90) then
    if isDriving==1 then -- checks if equals 1 that means is driving
setPedAnalogControlState(CJ2, "brake_reverse", 0.90)
        outputChatBox("Ped is driving stoping..")
end
        setPedAnalogControlState( ped, "accelerate", 0 ) -- set the analaog (accelerate) to 0
end
    else
addEventHandler("onClientRender", getRootElement(), onGetCJAnalogControlState)
        outputChatBox("Starting drive")
        setPedAnalogControlState( ped, "accelerate", 1 ) -- set the analaog (accelerate) to 1
    end
end)
</syntaxhighlight>
</syntaxhighlight>
</section>
<br /><br />
* This example was created by '''Hydra'''.
==Requirements==
{{Requirements|n/a|1.3.0-9.04185|}}


==See Also==
==See Also==

Latest revision as of 17:12, 7 November 2024

This function retrieves the analog control state of a ped, as set by setPedAnalogControlState.

Syntax

float getPedAnalogControlState ( ped thePed, string controlName [, bool rawValue ] )

Required Arguments

  • thePed: The ped you wish to retrieve the control state of.
  • controlName: The control. See control names for a list of possible controls.

Optional Arguments

  • rawValue: A bool indicating if it should return the raw player input value (will always return script value for non-player peds).

Returns

Returns a float between 0 (full release) and 1 (full push) indicating the amount the control is pushed.

Example

This exmaple creating a ped can drive with command /drive

local ped = createPed(0, 0,0,3)
local vehicle = createVehicle(554,0,0,3)
warpPedIntoVehicle(ped, vehicle)

addCommandHandler("drive",function()
    isDriving = getPedAnalogControlState ( ped, "accelerate" ) -- get the analaog state of (accelerate)
    if isDriving==1 then -- checks if equals 1 that means is driving
        outputChatBox("Ped is driving stoping..")
        setPedAnalogControlState( ped, "accelerate", 0 ) -- set the analaog (accelerate) to 0 
    else 
        outputChatBox("Starting drive")
        setPedAnalogControlState( ped, "accelerate", 1 ) -- set the analaog (accelerate) to 1 
    end 
end)

See Also