
   /* AMX Mod script.
   *
   * (c) 2004, BMJ
   * This file is provided as is (no warranties, ha!)
   *
   * This plugin is an extension of the mp_fadetoblack server cvar.
   *  This  plugin  is compatible with CS, but could be tweaked for other
   mods.
   *
   * amx_fadetoblack <0/1/2/3> - enables or disables extended fadetoblack
   *    0 = disabled
   *    1 = "fadetoblack" only players who are playing on a LAN
   *    2  = "fadetoblack" only players who are playing on a LAN, and who
   are on the same team
   *
   *
   */
   //#define  USE_IMMUNITY // Un-comment this line if you don't want this
   to affect players with immunity
   #include <amxmod>
   new bool:g_lan[33] = { false, ... };
   new g_ip_1[33] = { 0, ... };
   new g_ip_2[33] = { 0, ... };
   new g_ip_3[33] = { 0, ... };
   new g_ip_4[33] = { 0, ... };
   new i, j;
   public plugin_init()
   {
      register_plugin("AMX fadetoblack", "1.0", "BMJ");
      register_event("DeathMsg", "handle_deathmsg", "a");
      register_event("ResetHUD", "handle_resethud", "be", "1=1");
      register_cvar("amx_fadetoblack", "2");
   }
   public client_connect(id)
   {
      new IP[32];
      get_user_ip(id, IP, 31, 1);
      for (i = 0; i < 31; i++)
         if (IP[i] == '.')
            IP[i] = ' ';
      new buff_1[4];
      new buff_2[4];
      new buff_3[4];
      new buff_4[4];
      parse(IP, buff_1, 4, buff_2, 4, buff_3, 4, buff_4, 4);
      g_ip_1[id] = strtonum(buff_1);
      g_ip_2[id] = strtonum(buff_2);
      g_ip_3[id] = strtonum(buff_3);
      g_ip_4[id] = strtonum(buff_4);
      g_lan[id] = false;
      for (i = 0; i < 33; i++)
         if  ((g_ip_1[id]  ==  g_ip_1[i]) && (g_ip_2[id] == g_ip_2[i]) &&
   (g_ip_3[id] == g_ip_3[i]) && (g_ip_4[id] == g_ip_4[i]) && (id != i))
            g_lan[id] = g_lan[i] = true;
   }
   public client_disconnect(id)
   {
      if (g_lan[id])
      {
         for (i = 0; i < 33; i++)
            if ((g_ip_1[id] == g_ip_1[i]) && (g_ip_2[id] == g_ip_2[i]) &&
   (g_ip_3[id] == g_ip_3[i]) && (g_ip_4[id] == g_ip_4[i]))
            {
               g_lan[i] = false;
               for (j = 0; j < 33; j++)
                  if   ((g_ip_1[j]   ==   g_ip_1[i])   &&  (g_ip_2[j]  ==
   g_ip_2[i])  && (g_ip_3[j] == g_ip_3[i]) && (g_ip_4[j] == g_ip_4[i]) &&
   (j != i))
                     g_lan[i] = true;
            }
         g_ip_1[id] = g_ip_2[id] = g_ip_3[id] = g_ip_4[id] = 0;
         g_lan[id] = false;
      }
   }
   public handle_deathmsg()
   {
      if (!get_cvar_num("amx_fadetoblack"))
         return;
      if (!g_lan[read_data(2)])
         return;

      #if defined USE_IMMUNITY
      if (get_user_flags(read_data(2)) & ADMIN_IMMUNITY)
         return;
      #endif
      new param[2]; param[0] = read_data(2);
      if (get_cvar_num("amx_fadetoblack") == 1)
      {
         message_begin(MSG_ONE,  get_user_msgid("ScreenFade"), {0, 0, 0},
   param[0]);
         write_short(3<<12);
         write_short(5<<8);
         write_short(1<<0);
         write_byte(0);
         write_byte(0);
         write_byte(0);
         write_byte(255);
         message_end();
         set_task(2.5, "hold_fade", 0, param, 1);
      }
      else if (get_cvar_num("amx_fadetoblack") == 2)
      {
         if ((get_user_team(param[0]) == 1) && fade_t())
         {
            message_begin(MSG_ONE,  get_user_msgid("ScreenFade"),  {0, 0,
   0}, param[0]);
            write_short(3<<12);
            write_short(5<<8);
            write_short(1<<0);
            write_byte(0);
            write_byte(0);
            write_byte(0);
            write_byte(255);
            message_end();
            set_task(2.5, "hold_fade", 0, param, 1);
         }
         else if ((get_user_team(param[0]) == 2) && fade_ct())
         {
            message_begin(MSG_ONE,  get_user_msgid("ScreenFade"),  {0, 0,
   0}, param[0]);
            write_short(3<<12);
            write_short(5<<8);
            write_short(1<<0);
            write_byte(0);
            write_byte(0);
            write_byte(0);
            write_byte(255);
            message_end();
            set_task(2.5, "hold_fade", 0, param, 1);
         }
      }
   }
   public handle_resethud()
   {
      for (i = 0; i < 33; i++)
      {
         if (is_user_connected(i) && !is_user_bot(i))
         {
            message_begin(MSG_ONE,  get_user_msgid("ScreenFade"),  {0, 0,
   0}, i);
            write_short(1<<0);
            write_short(1<<0);
            write_short(1<<1);
            write_byte(0);
            write_byte(0);
            write_byte(0);
            write_byte(0);
            message_end();
         }
      }
   }
   public hold_fade(param[])
   {
      message_begin(MSG_ONE,  get_user_msgid("ScreenFade"),  {0,  0,  0},
   param[0]);
      write_short(1<<0);
      write_short(1<<0);
      write_short(1<<2);
      write_byte(0);
      write_byte(0);
      write_byte(0);
      write_byte(255);
      message_end();
      if (get_cvar_num("amx_fadetoblack") == 1)
      {
         client_print(param[0], print_chat, " ");
         client_print(param[0],  print_chat, "You and one or more players
   are on a LAN.");
         client_print(param[0],   print_chat,   "You   may  not  spectate
   freely.");
      }
      else if (get_cvar_num("amx_fadetoblack") == 2)
      {
         client_print(param[0], print_chat, " ");
         client_print(param[0],  print_chat, "You and one or more of your
   teammates are on a LAN.");
         client_print(param[0],  print_chat, "You may not spectate freely
   unless you are on different teams.");
      }
   }
   fade_t()
   {
      new Num = 0;
      for (i = 0; i < 33; i++)
      {
         if (g_lan[i] && (get_user_team(i) == 1))
            Num++;
      }
      return (Num > 1) ? true : false;
   }
   fade_ct()
   {
      new Num = 0;
      for (i = 0; i < 33; i++)
      {
         if (g_lan[i] && (get_user_team(i) == 2))
            Num++;
      }
      return (Num > 1) ? true : false;
   }
