getControlState
Server
Tells whether a player is pressing a control, going by the keys their client last sent.
Also exists on the client, with its own implementation: getControlState
bool getControlState(player thePlayer, string control)
Parameters
| Name | Type | Description |
|---|---|---|
| thePlayer | player | The player. |
| control | string | The control's name, case insensitive. |
Returns
true if the control is pressed. false if it is not, if the server does not receive that control, if the element is not a player or if the control name does not exist.
Vehicle controls only count while the player is in a vehicle, and on-foot ones only outside.
Example
setTimer(function()
for _, player in ipairs(getElementsByType("player")) do
if getControlState(player, "horn") then
outputServerLog(getPlayerName(player) .. " is honking")
end
end
end, 1000, 0)NoteThe server only receives some controls. On foot:
fire, forwards, backwards, left, right, enter_exit, jump, sprint, crouch, action, walk, aim_weapon, block and reload. In a vehicle: vehicle_fire, vehicle_secondary_fire, vehicle_left, vehicle_right, steer_forward, steer_back, accelerate, brake_reverse, horn, handbrake and enter_exit. The others always give false.