- Documentation
- Server functions
- setPedControlState
Function
setPedControlState
Presses or releases a virtual control of a ped, e.g. forwards (walk forward) or sprint. For NPCs every player's game carries out forwards, backwards and sprint, so the ped walks or runs the way it faces; other control names are stored for scripts and returned by getPedControlState. Names are the same as in bindKey/toggleControl (e.g. fire, jump, crouch, walk).
Syntax
bool setPedControlState(ped ped, string control, bool state)Arguments
pedped- A player or an NPC.
controlstring- Control name, e.g.
"forwards","backwards","sprint","walk","jump","fire". It must be a valid name (isValidControlName). statebooltrue= pressed,false= released.
Returns
true on success, false for a bad name.
Example
local walker = createPed(7, 2490, -1670, 13.3, 180)
setPedControlState(walker, "forwards", true)
setTimer(setPedControlState, 5000, 1, walker, "forwards", false)
See also
getPedControlStateChecks whether a ped's control is pressed according to the state set by scripts (setPedControlStateorsetPedAnalogControlState). It does not read the keys a player physically presses; usegetControlStateon the client for that.getPedControlStatesReturns at once a list of every ped control that scripts set as pressed. Handy for debugging NPCs or for saving and later restoring their state.setPedAnalogControlStateSets a ped's analog control within 0-1, i.e. how hard it is "pressed" (e.g. 0.5 = half throttle). The value is stored for scripts; in addition any value above 0 presses the regular control of that name and 0 releases it, so for NPCsforwards,backwardsandsprintwork in the game as withsetPedControlState(without graded strength).