getControlState | Multi Theft Auto: Wiki Skip to content

getControlState

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function will check if a player is pressing a particular control. Controls are those that affect GTA. If you wish to get the state of another key, use bindKey and a command function.

Syntax

getControlState ( )

Code Examples

server

This example starts a repeating check when a player spawns, if a player presses the fire key, they'll be killed.

function onPlayerSpawn ( theSpawnpoint )
killPlayerIfTheyPressThisKey ( source, "fire" ) -- start a repeating check
end
addEventHandler ( "onPlayerSpawn", root, onPlayerSpawn )
function killPlayerIfTheyPressThisKey ( thePlayer, key )
if ( getControlState ( thePlayer, key ) ) then -- if they're pressing the fire key
outputChatBox ( "Violence will not be tolerated!", thePlayer )
killPed ( thePlayer ) -- kill them
else -- otherwise..
setTimer ( killPlayerIfTheyPressThisKey, 500, 1, thePlayer, key ) -- call this function again in 500ms
end
end

See Also