func float move(rcarmodel $targetObject, float $state, float $position_x, float $position_y, float $position_z, float $speed, float $max_x, float $max_y, float $max_z)
{
	float $position_x_n = $state*($max_x-$position_x) + $position_x
	float $position_y_n = $state*($max_y-$position_y) + $position_y
	float $position_z_n = $state*($max_z-$position_z) + $position_z
	float $max_move=0
	if $position_x_n < $max_x
	{
	$position_x_n = $position_x_n - $speed
	}
	if $position_x_n > $max_x
	{
	$position_x_n = $position_x_n + $speed
	}
	if $position_y_n <= $max_y
	{
	$max_move=0
	$position_y_n = $position_y_n - 1*$speed
		if $max_move == 0
		{
			if $position_z_n > $max_z
			{
			$position_z_n = $position_z_n + 0*$speed*interval
			}
		}
	}
	if $position_y_n >= $max_y
	{
	$max_move=1
	$position_y_n = $position_y_n + 1*$speed
		if $max_move ==1
		{
			if $position_z_n < $max_z
			{
			$position_z_n = $position_z_n - 0*$speed*interval
			}
			if $position_z_n > $max_z
			{
			$position_z_n = $position_z_n + 0*$speed*interval
			}
		}
	}
set $targetObject position float[3]{$position_x_n,$position_y_n,$position_z_n}
return $position_x_n
}
func float rotate(rcarmodel $targetObject, float $targetState, float $angle, float $posx, float $posy, float $posz, float $rotMaskx, float $rotMasky, float $rotMaskz, float $incRate, float $decRate, float $minAngle, float $maxAngle)
{
  float $targetAngle = $targetState*($maxAngle-$minAngle) + $minAngle
  if $targetAngle > $angle
  {
    $angle = $angle + $incRate
  }
  if $targetAngle < $angle
  {
    $angle = $angle - $decRate
  }
  if $angle < $minAngle
  {
    $angle = $minAngle
  }
  if $angle > $maxAngle
  {
    $angle = $maxAngle
  }
  set $targetObject rotation float[3]{$angle*$rotMaskx,$angle*$rotMasky,$angle*$rotMaskz}
  return $angle
}
rcar $car = get scriptowner car
rcar $localcar = get local car
rcarmodel $imp = get generic model 0 of $car
set $imp scriptcontrolled 1
float $imp_move
float $imp_rot
int $keydown = 0
float $state = 0
float $state2 = 0
float $toggle = 0
float $speed = 0.00019
int $mode = 1
rcarmodel $filet = get generic model 7 of $car
//set $filet scriptcontrolled 1
float $filet_rotation = 0
float $filet_move
while 1
{
   if $car == $localcar
   { 
	set $filet position float[3]{0.0, 1.010, 0.001}
    if is key 86 pressed
    {
	if $keydown == 0
	{
		$toggle = 1
		$keydown = 1
	}
    }
    if $keydown == 1
    {
	$state = $state + $speed*$toggle
		if $state < 0
		{
			$state = 0
			//$keydown = 0
		}
		if $state2 < 0
		{
			$state2 = 0
			$keydown = 0
		}
		if $state > 1
		{
			$state = 1
			//$keydown = 0
		}
		if $state2 > 1
		{
			$state2 = 1
			$keydown = 0
		}
    }
    else
    {
     $keydown = 0    
    }
    if $mode > 0
	{
		if $state < 0
		{
			$state = 0
			$keydown = 0
		}
		if $state2 < 0
		{
			$state2 = 0
			$keydown = 0
		}
		if $state > 1
		{
			$state = 1
			$keydown = 0
		}
		if $state2 > 1
		{
			$state2 = 1
			$keydown = 0
		}
		if is key 88 pressed
		{
				$toggle = - 1
				$keydown = 1
				if is key 86 pressed
				{
					$speed = 0
				}
				else
				{
					$speed = 0.00008
				}
		}
		if is key 86 pressed
		{
				$toggle =  1
				$keydown = 1
				if is key 88 pressed
				{
					$speed = 0
				}
				else
				{
					$speed = 0.00008
				}
		}
		if $state < 0.25
		{
			$state2 = 0
			$state = $state + $speed*$toggle
			$imp_move = move($imp, $state, 0.00, 0.00, 0.0, 0.0, 0.00, 0.085, 0.00)
			$imp_rot = rotate($imp, $state, $imp_rot, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
		}
		if $state > 0.25
		{
			$state2 = $state2 + $speed*$toggle*1.25
			$imp_rot = rotate($imp, $state2, $imp_rot, 0, 0.02, 0, 0.0, -1.0, 0.0, 0.00015, 0.00015, 0.0, 0.08)
			$imp_move = move($imp, $state2, 0.00, 0.02, 0.00, 0.0, 0.00, 0.08, -0.9)
		}
		if $state > 0.10
		{
			$filet_rotation = rotate ($filet, $state2, $filet_rotation, 0.00, 0.00, 0.00, 0.0, 1.0, 0.0, 0.0100, 0.0100, 0.00, 0.96) //The filet goes up
			$filet_move = move($filet, $state, 0.0, 1.01, 0.001, 0.001, 0.00, 0.99, 0.03)
		}
	}
  }
  //paint $state at float[2]{20,110}
  interrupt
}