SetPedControlState: Difference between revisions
Zangomangu (talk | contribs) (Add a note on crouching) |
|||
(11 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client function}} | {{Client function}} | ||
This function makes a [[ped]] or [[player]] press or release a certain [[control names|control]]. | |||
This function makes a [[ped]] press or release a certain control. | {{Note|You can't use enter_exit or enter_passenger on a ped. Please use [[setPedEnterVehicle]] and [[setPedExitVehicle]].}} | ||
{{Note|To make a ped crouch, set the control to ''true'' and reset to ''false'' after one frame. Use [[setTimer]] with 0ms. Do the same to make the ped stand again.}} | |||
==Syntax== | ==Syntax== | ||
Line 8: | Line 9: | ||
bool setPedControlState ( ped thePed, string control, bool state ) | bool setPedControlState ( ped thePed, string control, bool state ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[Ped]]:setControlState}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
Line 16: | Line 18: | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if successful, ''false'' if otherwise. | Returns ''true'' if successful, ''false'' if otherwise. | ||
==Remarks== | |||
If you set the control state on the localPlayer element, then the control state is synchronized to every other client as if the input was made through the game input. But if you set any control states to server-side peds then the control state is not automatically synchronized. This behaviour is unaffected by being the syncer of the server-side ped or not. Let's assume that the syncer client calls setPedControlState on the ped. The other game clients - the ones where setPedControlState was not manually called by scripts - will see the ped teleport around. It will clearly look as if synchronization were broken. | |||
==Example== | ==Example== | ||
<section name="Client" class="client" show="true"> | <section name="Client" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function newPed() | function newPed() | ||
local x, y, z = getElementPosition(localPlayer) | local x, y, z = getElementPosition(localPlayer) | ||
local ped = createPed(0, x + 1, y, z) | |||
setPedControlState( | if ped then | ||
setPedControlState(ped, "forwards", true) | |||
end | |||
end | end | ||
addCommandHandler("ped", newPed) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
==Changelog== | |||
{{ChangelogHeader}} | |||
{{ChangelogItem|1.5.5-3.11427|Works with the [[getLocalPlayer|local player]] as well. Deprecated [[setControlState]] and [[getControlState]].}} | |||
==See Also== | ==See Also== | ||
{{Client ped functions}} | {{Client ped functions}} |
Latest revision as of 09:13, 3 August 2023
This function makes a ped or player press or release a certain control.
Syntax
bool setPedControlState ( ped thePed, string control, bool state )
OOP Syntax Help! I don't understand this!
- Method: Ped:setControlState(...)
Required Arguments
- thePed: the ped you want to press or release a control.
- control: the name of the control of which to change the state. See control names for a list of valid names.
- state: the new control state. true means pressed, false is released.
Returns
Returns true if successful, false if otherwise.
Remarks
If you set the control state on the localPlayer element, then the control state is synchronized to every other client as if the input was made through the game input. But if you set any control states to server-side peds then the control state is not automatically synchronized. This behaviour is unaffected by being the syncer of the server-side ped or not. Let's assume that the syncer client calls setPedControlState on the ped. The other game clients - the ones where setPedControlState was not manually called by scripts - will see the ped teleport around. It will clearly look as if synchronization were broken.
Example
function newPed() local x, y, z = getElementPosition(localPlayer) local ped = createPed(0, x + 1, y, z) if ped then setPedControlState(ped, "forwards", true) end end addCommandHandler("ped", newPed)
Changelog
Version | Description |
---|
1.5.5-3.11427 | Works with the local player as well. Deprecated setControlState and getControlState. |
See Also
- canPedBeKnockedOffBike
- getPedAnalogControlState
- getPedAnimation
- getPedBonePosition
- getPedCameraRotation
- getPedControlState
- getPedMoveState
- getPedOxygenLevel
- getPedSimplestTask
- getPedTargetCollision
- getPedTargetEnd
- getPedTargetStart
- getPedTask
- getPedVoice
- getPedWeaponMuzzlePosition
- givePedWeapon
- isPedBleeding
- isPedDoingTask
- isPedReloadingWeapon
- isPedTargetingMarkerEnabled
- setAnalogControlState
- setPedAimTarget
- setPedAnalogControlState
- setPedBleeding
- setPedCameraRotation
- setPedCanBeKnockedOffBike
- setPedControlState
- setPedEnterVehicle
- setPedExitVehicle
- IsPedFootBloodEnabled
- setPedFootBloodEnabled
- setPedLookAt
- setPedOxygenLevel
- setPedTargetingMarkerEnabled
- setPedVoice
- Shared
- addPedClothes
- getPedClothes
- removePedClothes
- createPed
- getPedAmmoInClip
- getPedArmor
- getPedFightingStyle
- getPedOccupiedVehicle
- getPedOccupiedVehicleSeat
- getPedStat
- getPedTarget
- getPedTotalAmmo
- getPedWalkingStyle
- getPedWeapon
- getPedWeaponSlot
- getPedContactElement
- getValidPedModels
- isPedChoking
- isPedDead
- isPedDoingGangDriveby
- isPedDucked
- isPedHeadless
- isPedInVehicle
- isPedOnFire
- isPedOnGround
- isPedWearingJetpack
- killPed
- removePedFromVehicle
- setPedAnimation
- setPedAnimationProgress
- setPedAnimationSpeed
- setPedArmor
- setPedDoingGangDriveby
- setPedFightingStyle
- setPedHeadless
- setPedOnFire
- setPedStat
- setPedWalkingStyle
- setPedWeaponSlot
- warpPedIntoVehicle