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 position float[3]{$posx,$posy,$posz}
  set $targetObject rotation float[3]{$angle*$rotMaskx,$angle*$rotMasky,$angle*$rotMaskz}
  return $angle
}
rcar $car = get scriptowner car
rcar $localcar = get local car
rcarmodel $toit = get generic model 27 of $car
rcarmodel $toit_2 = get generic model 28 of $car
rcarmodel $filet = get generic model 36 of $car
set $toit scriptcontrolled 1
set $toit_2 scriptcontrolled 1
//set $filet scriptcontrolled 1
float $toit_move
float $toit_rot
float $toit_pos
float $toit_rot_2
float $toit_move_2
float $filet_move
float $filet_rotation
shared int $keydown2 = 0
shared float $state = 0
shared float $toggle2 = 1
shared int $mode2 = 0
float $speed = 0.00012
while 1
{
   if $car == $localcar
   { 
   	set $filet position float[3]{0.0, 0.91, -0.050}
    if is key 88 pressed
    {
	if $keydown2 == 0
	{
		$toggle2 = - $toggle2
		$keydown2 = 1
	}
    }
    if is key 87 pressed and $state == 0
    {
	if $mode2 < 3
	{
		$mode2 + = 1
		$state = 1
		wait(250)
	}
	else
	{
		$mode2 = 0
		$state = 1
		wait(250)
	}
    }
    if $keydown2 == 1
    {
	$state = $state + $speed*$toggle2
	if $state < 0
	{
		$state = 0
		$keydown2 = 0
	}
	if $state > 1
	{
		$state = 1
		$keydown2 = 0
	}
    }
    else
    {
     $keydown2 = 0    
    }
    if $mode2 == 0
    {
	$toit_rot = move($toit, $state, 0.0, 1.185, 0.12, 0.001, 0.0, 1.185, 0.12)
	$toit_rot_2 = move($toit_2, $state, 0.0, -991.185, 0.12, 0.001, 0.0, -991.185, 0.12)
	$state = 0
    }	
    if $mode2 == 1
	{
		$state = $state + $speed*$toggle2
		if $state < 0
		{
			$state = 0
			$keydown2 = 0
		}
		if $state > 1
		{
			$state = 1
			$keydown2 = 0
		}
	$toit_rot = rotate($toit, $state, $toit_rot, 0.0, 1.185, 0.12, 0.0, 1.0, 0.0, 0.00003, 0.00003, 0.00, 0.04)
	$toit_rot_2 = 0
	$toit_move = 0
	$toit_move_2 = 0
	}
    if $mode2 == 2
	{
		$state = $state + $speed*$toggle2
		if $state < 0
		{
			$state = 0
			$keydown2 = 0
		}
		if $state > 1
		{
			$state = 1
			$keydown2 = 0
		}
		if $state > 0.90
		{
		$mode2 + = 1
		$state = 1
		$state = $state + $speed*$toggle2
		}
	$toit_rot = rotate($toit, $state, $toit_rot, 0.0, 1.185, 0.12, 0.0, 1.0, 0.0, 0.00015, 0.00015, 0.00, 0.04)
	$toit_rot_2 = 0
	$toit_move = 0
	$toit_move_2 = 0
	}
    if $mode2 == 3
	{
	$state = $state + $speed*$toggle2
	if $state < 0
	{
		$state = 0
		$keydown2 = 0
	}
	if $state > 1
	{
		$state = 1
		$keydown2 = 0
	}
	if $state > 0.98
	{
		$toit_move_2 = move($toit_2, $state, 0.0, 1.183, -0.68, 0.001, 0.0, 1.18, -0.68)
		$filet_rotation = rotate ($filet, $state*0.2, $filet_rotation, 0, 0, 0, 0.0, 1.0, 0.0, 0.0100, 0.0100, 0.0, 1.15) //The filet goes up
		$filet_move = move($filet, $state*0.3, 0.0, 0.91, -0.05, 0.0, 0.00, 0.91, -0.05)
		$toit_rot = 0
		$toit_rot_2 = 0
		$toit_move = 0
	}
	else
	{
		$toit_rot = move($toit, $state, 0.0, -991.185, 0.12, 0.001, 0.0, -991.185, 0.12)
		$toit_rot_2 = rotate($toit_2, $state, $toit_rot_2, 0.0, 1.27, -0.68, 0.0, 1.0, 0.0, 0.00011, 0.00011, -0.13, 0.00)
		$toit_move = move($toit_2, $state, 0.0, 1.185, -1.45, 0.001, 0.0, 1.19, -0.68)
		$toit_move_2 =0
	}
	}
  }
  interrupt
}