
cleanallhud()
{
  if(isDefined(level.clock)) level.clock destroy();
  if(isDefined(level.ex_axisicon)) level.ex_axisicon destroy();
  if(isDefined(level.ex_axisnumber)) level.ex_axisnumber destroy();
  if(isDefined(level.ex_deadaxisicon)) level.ex_deadaxisicon destroy();
  if(isDefined(level.ex_deadaxisnumber)) level.ex_deadaxisnumber destroy();
  if(isDefined(level.ex_alliedicon)) level.ex_alliedicon destroy();
  if(isDefined(level.ex_alliednumber)) level.ex_alliednumber destroy();
  if(isDefined(level.ex_deadalliedicon)) level.ex_deadalliedicon destroy();
  if(isDefined(level.ex_deadalliednumber)) level.ex_deadalliednumber destroy();
  if(isDefined(level.ex_gtsmsg)) level.ex_gtsmsg destroy();

  // fade out modinfo, move to centre and fade in
  if(isDefined(level.ex_modinfo))
  {
    level.ex_modinfo fadeOverTime(1);
    level.ex_modinfo.alpha = 0;
    wait 1;
    level.ex_modinfo.x = 320;
    level.ex_modinfo.alignX = "center";
    level.ex_modinfo fadeOverTime(1);
    level.ex_modinfo.alpha = 0.8;
    wait 1;
  }
}

cleanplayerend()
{
  maps\mp\gametypes\_hud_teamscore::removePlayerHUD();
  maps\mp\gametypes\_hud_playerscore::removePlayerHUD();

  if(isdefined(self.ex_parachute)) self.ex_parachute delete();
  if(isdefined(self.ex_anchor)) self.ex_anchor delete();
  
  if(level.ex_ranksystem)
  {
    if(isDefined(self.ex_rankhud0)) self.ex_rankhud0 destroy();
    if(isDefined(self.ex_rankhud1)) self.ex_rankhud1 destroy();
    if(isDefined(self.ex_rankhud2)) self.ex_rankhud2 destroy();
  }
}

cleanplayer()
{
  [[level.ex_clearlnb]]("self",5);

  if(isDefined(self.ex_sintimer)) self.ex_sintimer destroy();
  if(isDefined(self.ex_sintimertxt)) self.ex_sintimertxt destroy();
  if(isDefined(self.ex_laserdot)) self.ex_laserdot destroy();
  if(isDefined(self.ex_sprinthud)) self.ex_sprinthud destroy();
  if(isDefined(self.ex_sprinthud_back)) self.ex_sprinthud_back destroy();
  if(isDefined(self.ex_sprinthud_hint)) self.ex_sprinthud_hint destroy();
  if(isDefined(self.ex_sintimer)) self.ex_sintimer destroy();
  if(isDefined(self.ex_sintimertxt)) self.ex_sintimertxt destroy();
  if(isDefined(self.ex_laserdot)) self.ex_laserdot destroy();
  if(isDefined(self.ex_firstaidicon)) self.ex_firstaidicon destroy();
  if(isDefined(self.ex_firstaidtxt)) self.ex_firstaidtxt destroy();
  if(isDefined(self.ex_firstaidval)) self.ex_firstaidval destroy();
  if(isDefined(self.ex_rankhud)) self.ex_rankhud destroy();
  if(isDefined(self.mortar_available_icon)) self.mortar_available_icon destroy();
  if(isDefined(self.artillery_available_icon)) self.artillery_available_icon destroy();
  if(isDefined(self.airstrike_available_icon)) self.airstrike_available_icon destroy();
  if(isDefined(self.ex_binocular_hint)) self.ex_binocular_hint destroy();
  if(isdefined(self.ex_parachute)) self.ex_parachute delete();
  if(isdefined(self.ex_anchor)) self.ex_anchor delete();

  if(isDefined(self.ex_bloodonscreen)) self.ex_bloodonscreen destroy();
  if(isDefined(self.ex_bloodonscreen1)) self.ex_bloodonscreen1 destroy();
  if(isDefined(self.ex_bloodonscreen2)) self.ex_bloodonscreen2 destroy();
  if(isDefined(self.ex_bloodonscreen3)) self.ex_bloodonscreen3 destroy();

  if(isDefined(self.ex_expmsg1)) self.ex_expmsg1 destroy();
  if(isDefined(self.ex_expmsg2)) self.ex_expmsg2 destroy();
  if(isDefined(self.ex_expmsg3)) self.ex_expmsg3 destroy();

  if(isDefined(self.ex_pbbgrd)) self.ex_pbbgrd destroy();
  if(isDefined(self.ex_pb)) self.ex_pb destroy();
  if(isDefined(self.ex_actimer)) self.ex_actimer destroy();
  if(isDefined(self.ex_tripwarning)) self.ex_tripwarning destroy();

  if(isDefined(self.ex_bleedmsg)) self.ex_bleedmsg destroy();
  if(isDefined(self.ex_roundnumber)) self.ex_roundnumber destroy();

  if(level.ex_bulletholes && isDefined(self.ex_bulletholes))
  {
    for(i = 0; i < self.ex_bulletholes.size; i++)
    {
      if(isDefined(self.ex_bulletholes[i])) self.ex_bulletholes[i] destroy();
    }
  }

  if(isDefined(self.ex_healthbar)) self.ex_healthbar destroy();
  if(isDefined(self.ex_healthback)) self.ex_healthback destroy();
  if(isDefined(self.ex_healthcross)) self.ex_healthcross destroy();

  if(isDefined(self.ex_srvlogoback)) self.ex_srvlogoback destroy();
  if(isDefined(self.ex_srvlogofront)) self.ex_srvlogofront destroy();

  if(isDefined(self.ex_headmarker))
  {
    self.ex_headmarker stoploopsound();
    self.ex_sprintreco = false;
    self.ex_headmarker unlink();
    self.ex_headmarker delete();
  }

  if(isDefined(self.ex_spinemarker))
  {
    self.ex_spinemarker unlink();
    self.ex_spinemarker delete();
  }

  if(isDefined(self.ex_elbowmark))
  {
    self.ex_elbowmarker unlink();
    self.ex_elbowmarker delete();
  }

  if(isDefined(self.ex_eyemarker))
  {
    self.ex_eyemarker unlink();
    self.ex_eyemarker delete();
  }

  if(isDefined(self.ex_thumbmarker))
  {
    self.ex_thumbmarker unlink();
    self.ex_thumbmarker delete();
  }

}

movieMode()
{
  level endon("ex_gameover");
  self endon("disconnect");

  if(isDefined(self.ex_letterboxtop)) while(isPlayer(self) && isDefined(self.ex_letterboxtop)) wait 0.05;

  wait 0.05;

  if(isPlayer(self))
  {
    self.ex_letterboxtop = newClientHudElem(self);
    self.ex_letterboxtop.alignX = "left";
    self.ex_letterboxtop.alignY = "top";
    self.ex_letterboxtop.x = 0;
    self.ex_letterboxtop.sort = - 50;
    self.ex_letterboxtop.alpha = 0;
    self.ex_letterboxtop setShader("black", 640, 80);
  
    self.ex_letterboxbottom = newClientHudElem(self);
    self.ex_letterboxbottom.alignX = "left";
    self.ex_letterboxbottom.alignY = "top";
    self.ex_letterboxbottom.x = 0;
    self.ex_letterboxbottom.sort = - 50;
    self.ex_letterboxbottom.alpha = 0;
    self.ex_letterboxbottom setShader("black", 640, 80);
  
    self.ex_letterboxtop fadeOverTime(4);
    self.ex_letterboxtop.alpha = 1;
    self.ex_letterboxbottom fadeOverTime(4);
    self.ex_letterboxbottom.alpha = 1;
  
    for(i = 0; i < 80; i++)
    {
      if(isDefined(self.ex_letterboxtop)) self.ex_letterboxtop.y = -80 + i;
      if(isDefined(self.ex_letterboxtop)) self.ex_letterboxbottom.y = 480 - i;
      wait 0.02;
    }
  }
}

movieRemove()
{
  level endon("ex_gameover");
  self endon("disconnect");

  if(!level.forcerespawn)
  {
    if(isDefined(self.ex_letterboxtop))
    {
      self.ex_letterboxtop fadeOverTime(4);
      self.ex_letterboxtop.alpha = 0;
    }

    if(isDefined(self.ex_letterboxbottom))
    {
      self.ex_letterboxbottom fadeOverTime(4);
      self.ex_letterboxbottom.alpha = 0;
    }

    for(i = 0; i < 80; i++)
    {
      if(isDefined(self.ex_letterboxtop)) self.ex_letterboxtop.y = 0 - i;
      if(isDefined(self.ex_letterboxtop)) self.ex_letterboxbottom.y = 400 + i;

      wait 0.02;
    }

    if(isDefined(self.ex_letterboxtop)) self.ex_letterboxtop destroy();
    if(isDefined(self.ex_letterboxbottom)) self.ex_letterboxbottom destroy();
  }
}
