/***************************************************************************************************
                            AMX Eject CD

  Version: 0.1
  Author: KRoTaL

 Commands:

  amx_ejectcd <name, #userid, authid, @CT, @TERRORIST, * (all)>     -  opens the players' CD Drive.
  amx_closecd <name, #userid, authid, @CT, @TERRORIST, * (all)>     -  closes the players' CD Drive.
  amx_popcd <name, #userid, authid, @CT, @TERRORIST, * (all)>     -  randomly opens and closes the player's CD Drive.

  You must have ADMIN_SLAY flag to use these commands.

 Cvar:

  popcd_num 5 - number of times to pop the player's CD Drive.



  Based on Bad HAL 9000's plugin.


***************************************************************************************************/

#include <amxmod>
#include <amxmisc>

new popcount[33]

public plugin_init()
{
  register_plugin("Eject CD", "0.1", "KRoTaL")
  register_concmd("amx_ejectcd", "amx_eject_cd", ADMIN_SLAY, ": <name/#id/authid/@CT/@TERRORIST/ *(all)> opens the player's CD Drive")
  register_concmd("amx_closecd", "amx_close_cd", ADMIN_SLAY, ": <name/#id/authid/@CT/@TERRORIST/ *(all)> closes the player's CD Drive")
  register_concmd("amx_popcd", "amx_pop_cd", ADMIN_SLAY, ": <name/#id/authid/@CT/@TERRORIST/ *(all)> randomly opens and closes the player's CD Drive")
  register_cvar("popcd_num", "5")
}

public client_connect(id)
{
  popcount[id] = 0
}

public amx_eject_cd(id, level, cid)
{
  if (!cmd_access(id, level, cid, 2))
  {
    return PLUGIN_HANDLED
  }

  new arg[32]
  read_argv(1, arg, 31)
  new i, players[32], inum, player
  if(arg[0] == '@')
  {
    get_players(players, inum, "e", arg[1])
    if(inum == 0)
    {
          console_print(id, "No users in such team")
          return PLUGIN_HANDLED
    }
    for(i = 0; i < inum; ++i)
    {
      player = players[i]
      client_cmd(player, "cd eject")
      set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 1)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 2)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 3)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 4)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
    }
  }
  else if(arg[0] == '*')
  {
    get_players(players, inum)
    if(inum == 0)
    {
          console_print(id, "No users in such team")
          return PLUGIN_HANDLED
    }
    for(i = 0; i < inum; ++i)
    {
      player = players[i]
      client_cmd(player, "cd eject")
      set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 1)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 2)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 3)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 4)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
    }
  }
  else
  {
    player = cmd_target(id, arg, 11)
    if (!player)
      return PLUGIN_HANDLED

    client_cmd(player, "cd eject")
    set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 1)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 2)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 3)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 4)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
  }

  return PLUGIN_HANDLED
}

public amx_close_cd(id, level, cid)
{
  if (!cmd_access(id, level, cid, 2))
  {
    return PLUGIN_HANDLED
  }

  new arg[32]
  read_argv(1,arg,32)
  new i, players[32], inum, player
  if(arg[0] == '@')
  {
    get_players(players, inum, "e", arg[1])
    if(inum == 0)
    {
          console_print(id, "No users in such team")
          return PLUGIN_HANDLED
    }
    for(i = 0; i < inum; ++i)
    {
      player = players[i]
      client_cmd(player, "cd close")
      set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 1)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 2)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 3)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 4)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
    }
  }
  else if(arg[0] == '*')
  {
    get_players(players, inum)
    if(inum == 0)
    {
          console_print(id, "No users in such team")
          return PLUGIN_HANDLED
    }
    for(i = 0; i < inum; ++i)
    {
      player = players[i]
      client_cmd(player, "cd close")
      set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 1)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 2)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 3)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 4)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
    }
  }
  else
  {
    player = cmd_target(id, arg, 11)
    if (!player)
      return PLUGIN_HANDLED

    client_cmd(player, "cd close")
    set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 1)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 2)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 3)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 6.0, 0.1, 0.2, 4)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
  }

  return PLUGIN_HANDLED
}

public amx_pop_cd(id, level, cid)
{
  if (!cmd_access(id,level,cid,2))
  {
    return PLUGIN_HANDLED
  }

  new arg[32]
  read_argv(1,arg,32)
  new i, players[32], inum, player
  if(arg[0] == '@')
  {
    get_players(players, inum, "e", arg[1])
    if(inum == 0)
    {
          console_print(id, "No users in such team")
          return PLUGIN_HANDLED
    }
    for(i = 0; i < inum; ++i)
    {
      player = players[i]
      client_cmd(player, "cd eject")
      set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 1)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 2)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 3)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 4)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_task(random_float(3.0, 6.0), "close_cd", players[i])
    }
  }
  else if(arg[0] == '*')
  {
    get_players(players, inum)
    if(inum == 0)
    {
          console_print(id, "No users in such team")
          return PLUGIN_HANDLED
    }
    for(i = 0; i < inum; ++i)
    {
      player = players[i]
      client_cmd(player, "cd eject")
      set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 1)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 2)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 3)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 4)
      show_hudmessage(player, "YOU ARE GETTING HACKED!")
      set_task(random_float(3.0, 6.0), "close_cd", players[i])
    }
  }
  else
  {
    player = cmd_target(id, arg, 11)
    if (!player)
      return PLUGIN_HANDLED

    client_cmd(player, "cd eject")
    set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 1)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 2)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 3)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 4)
    show_hudmessage(player, "YOU ARE GETTING HACKED!")
    set_task(random_float(3.0, 6.0), "close_cd", player)
  }

  return PLUGIN_HANDLED
}

public open_cd(id)
{
  client_cmd(id, "cd eject")
  set_hudmessage(255, 255, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 1)
  show_hudmessage(id, "YOU ARE GETTING HACKED!")
  set_hudmessage(255, 0, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 2)
  show_hudmessage(id, "YOU ARE GETTING HACKED!")
  set_hudmessage(0, 0, 255, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 3)
  show_hudmessage(id, "YOU ARE GETTING HACKED!")
  set_hudmessage(0, 255, 0, random_float(0.1, 0.7), random_float(0.2, 0.9), 0, 1.0, 4.0, 0.1, 0.2, 4)
  show_hudmessage(id, "YOU ARE GETTING HACKED!")
  set_task(random_float(3.0, 6.0), "close_cd", id)
}

public close_cd(id)
{
  popcount[id]++
  client_cmd(id, "cd close")
  if(popcount[id] < get_cvar_num("popcd_num"))
  {
    set_task(random_float(3.0, 6.0), "open_cd", id)
  }
  else
  {
    popcount[id] = 0
  }
}
