setControlState
Client
Presses or releases one of a ped's controls as if it were a key, for example to make it walk, jump or shoot.
Also exists on the server, with its own implementation: setControlState
bool setControlState(string control, bool state [, ped thePed = localPlayer])
Parameters
| Name | Type | Description |
|---|---|---|
| thePed | ped | The ped or the local player. It can be left out, which means the local player.default localPlayer |
| control | string | The control's name, case insensitive. |
| state | bool | true to hold it down, false to release it. |
Returns
true if the state was applied. false if the control name does not exist or the ped cannot take controls.
On an analog control (walking, steering, accelerating, braking), true presses it all the way and releases the opposite control. A control turned off with toggleControl does not reach the game, even when a script presses it.
Example
addCommandHandler("autorun", function()
local running = not getControlState("forwards")
setControlState("forwards", running)
setControlState("sprint", running)
end)Coming from MTABesides MTA's controls, MYMP has
block (melee block) and reload.NoteOn a remote player the function returns
true but does nothing. On the local player, the player's own input on that control replaces the script's state.