GetControlState

From Multi Theft Auto: Wiki
Revision as of 17:08, 8 July 2006 by MrJax (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Gets a state of a specified player's control. Note: Only works for the keys MTA synchronises between clients.

Syntax

bool getControlState ( player thePlayer, string control ) 

Required Arguments

  • thePlayer: The player you wish to get the control state of.
  • control: The control that you want to get the state of.

Returns

Returns the state of the control if found, 'false' otherwise.

Example

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

addEventHandler ( "onPlayerSpawn", root, "onPlayerSpawn" )
function onPlayerSpawn ( theSpawnpoint )
  killPlayerIfTheyPressThisKey ( source, "fire" ) -- start a repeating check
end

function killPlayerIfTheyPressThisKey ( thePlayer, key )
  if ( getControlState ( thePlayer, key ) ) then -- if they're pressing the fire key
    killPlayer ( thePlayer ) -- kill them
  else -- otherwise..
    setTimer ( "killPlayerIfTheyPressThisKey", 500, 1, thePlayer, key ) -- call this function again in 500ms
  end
end

See Also