rcar $car = get local car	//get car

rcarmodel $ccc = get generic model 3 of $car   //Cruise indicator
rcarmodel $ccl = get generic model 4 of $car   //Limiter indicator
rcarmodel $tc = get generic model 5 of $car   //Traction Control
set $ccc scriptcontrolled 1
set $ccl scriptcontrolled 1
set $tc scriptcontrolled 1

shared int $cccon=0
shared int $cclon=0
shared int $speed=0
int $tcnow=1
int $tclast=1

int $cccdown=0
int $ccldown=0
int $tcdown=0

func void CheckInput()
{
  if is key 88 pressed			// [X] key
  {
    send "stop engine" to console
  }

  if is key 85 pressed		//Cruise Control key [U]
  {
    if $cccdown == 0		//First press
    {
      $cccdown = 1		//Mark as held down
      if $cccon == 1
      {
        $cccon = 0		//If On, cancel it
      }
      else 
      {
         $cccon = 1		//Turn it on 
         $cclon = 0		//Cancel limiter
         $speed = get $car tachovelocity
      }
    }
  }
  else
  {
    $cccdown = 0		//Mark as released
  }  

  if is key 73 pressed		//Limiter key [I]
  {
    if $ccldown == 0		//First press
    {
      $ccldown = 1		//Mark as held down
      if $cclon == 1
      {
        $cclon = 0		//If On, cancel it
      }
      else 
      {
         $cclon = 1		//Turn it on
         $cccon = 0		//Cancel cruise control
         $speed = get $car tachovelocity
      }
    }
  }
  else
  {
    $ccldown = 0		//Mark as released
  }  
}

func void CheckTC()
{
  if is key 90 pressed			// [Z] key
  {
    if $tcdown == 0			// First press
    {
      $tcdown = 1			// Mark as held down
      $tcnow = 1 - $tcnow		// Toggle TC
    }
  }
  else
  {
    $tcdown = 0				// Key released
  }

  if $tclast != $tcnow
  {
    $tclast = $tcnow
    set $car tc $tcnow
  }
}

func void ShowModels()
{
  if $cccon > 0
    { set $ccc position float[3]{0,0,0} }
  else
    { set $ccc position float[3]{0,0,0.2} }

  if $cclon > 0
    { set $ccl position float[3]{0,0,0} }
  else
    { set $ccl position float[3]{0,0,0.2} }

  int $tcactive = get $car tc active
  int $test = (1 - $tcnow) + $tcactive		//Is disabled or active?

  if $test > 0
    { set $tc position float[3]{0,0,0} }
  else
    { set $tc position float[3]{0,0,0.2} }
}

while 1
{
  CheckInput()
  CheckTC()
  ShowModels()

  interrupt
}