
   /*
   *
   *   Diveing Kit
   *   Version 1.0
   *   Author: AssKicR;   to_asskicr@hotmail.com (MSN)  DaAssKicR (AIM)
   *   Thanks to Lazy for the Staying Underwater code :)
   *
   *   This  plugin  will  add  a  diving  kit to Counter-Strike. You can
   buy/sell your kit
   *   While using it you will be able to breathe underewater
   *   You  can set the cost of the Diving kit and enable/disable buyzone
   & buytime.
   *
   *   Requirements:
   *      Compiled on 0.9.4.
   *      Should work successfully on 0.9.3
   *      Tested successfully on 0.9.4.
   *      Tested successfully on 0.9.5.
   *
   *   Admin Commands:
   *      amx_divekit  <  nick, uniqueid, #userid, @TEAM, or * > <- Gives
   diving kit to specified client(s)
   *      amx_undivekit  < nick, uniqueid, #userid, @TEAM, or * > <- Take
   Away Diving kit
   *
   *   Client Commands:
   *      say /divekit <- Displays the Diving Kit help menu
   *      buydivekit <- Buys a diving kit for specified player
   *         (Player must be in buyzone if specified by CVAR)
   *      selldivekit  <-  Sells  player's  diving kit for 75% of the buy
   price
   *
   *   Server CVARs:
   *      divekit_cost "1500 - 10000" <- Amount of cash it takes to buy a
   diving kit
   *      divekit_buyzone  1/0  <- If on, player will required to be in a
   buyzone when buying diving kit
   *      divekit_buytime 1/0 <- If on, only allows player to buy diveing
   kits during buytime
   *
   */
   #include <amxmod>
   #include <amxmisc>
   #include <vexd_utilities>
   new bool:AquaKit[33]
   new bool:BuyTimeAllow
   new bool:BuyZoneAllow[33]
   new Float:BuyTimeFloat
   new BuyTimeNum
   new bool:BuyTimeCvar
   new bool:BuyZoneCvar
   //TAKE AWAY CODE BELOW TO REMOVE CONNECT MESSAGE
   public client_connect(id) {
      client_cmd(id,"echo
   ^"====================================================================
   ====^"")
      client_cmd(id,"echo   ^"  [DIVEKIT]  This  server  is  running  the
   divekit plugin.              ^"")
      client_cmd(id,"echo ^"  In order to buy a diving kit, type /divekit
   for details.     ^"")
      client_cmd(id,"echo
   ^"====================================================================
   ====^"")
      AquaKit[id]=false
   }
   //TAKE AWAY CODE ABOVE TO REMOVE CONNECT MESSAGE
   public client_disconnect(id) {
      AquaKit[id]=false

   }
   public ass_diveingkit(id,level,cid) {
      if (!cmd_access(id,level,cid,2)) {
         return PLUGIN_HANDLED
      }
      new target[32]
      read_argv(1,target,31)
      new admin[32]
      get_user_name(id,admin,31)
      if (target[0]=='@') {
         new team[32], inum
         get_players(team,inum,"e",target[1])
         if (inum==0) {
            console_print(id,"[AMX] No clients found on such team.")
            return PLUGIN_HANDLED
         }
         for (new i=0;i<inum;++i) {
            AquaKit[team[i]]=true
            client_print(0,print_chat,"AMX  Command: %s has gave all %s's
   diving kits.",admin,target[1])
         }
      }
      else if (target[0]=='*') {
         new all[32], inum
         get_players(all,inum)
         for (new i=0;i<inum;++i) {
            AquaKit[all[i]]=true
            client_print(0,print_chat,"AMX   Command:  %s  has  gave  all
   clients diving kits.",admin)
         }
      }
      else {
         new player = cmd_target(id,target,0)
         new playername[32]
         get_user_name(player,playername,31)
         if (!player) {
            return PLUGIN_HANDLED
         }
         AquaKit[player]=true
         client_print(0,print_chat,"AMX Command: %s has given %s a diving
   kit.",admin,playername)
      }
      return PLUGIN_HANDLED
   }
   public ass_undiveingkit(id,level,cid) {
      if (!cmd_access(id,level,cid,2)) {
         return PLUGIN_HANDLED
      }
      new target[32]
      read_argv(1,target,31)
      new admin[32]
      get_user_name(id,admin,31)
      if (target[0]=='@') {
         new team[32], inum
         get_players(team,inum,"e",target[1])
         if (inum==0) {
            console_print(id,"[AMX] No clients found on such team.")
            return   PLUGIN_HANDLED
         }
         for (new i=0;i<inum;i++) {
            AquaKit[team[i]]=false
            client_print(0,print_chat,"AMX Command: %s sabotaged all %s's
   diving kits.",admin,target[1])
         }
      }
      else if (target[0]=='*') {
         new all[32], inum
         get_players(all,inum)
         for (new i=0;i<inum;++i) {
            AquaKit[all[i]]=false
            client_print(0,print_chat,"AMX    Command:    %s    sabotaged
   everyones diving kits.",admin)
         }
      }
      else {
         new player = cmd_target(id,target,0)
         new playername[32]
         get_user_name(player,playername,31)
         if (!player) {
            return PLUGIN_HANDLED
         }
         AquaKit[player]=false
         client_print(0,print_chat,"AMX Command: %s sabotaged %s's diving
   kit.",admin,playername)
      }
      return PLUGIN_HANDLED
   }
   public cost_force() {
      if (get_cvar_num("divekit_cost") < 1500) {
         set_cvar_num("divekit_cost",1500)
      }
      if (get_cvar_num("divekit_cost") > 10000) {
         set_cvar_num("divekit_cost",10000)
      }
      return PLUGIN_CONTINUE
   }
   public RoundTime()
   {
      if ( read_data(1)==get_cvar_num("mp_freezetime") || read_data(1)==6
   ) // freezetime starts
      {
         remove_task(701) // remove buytime task
         BuyTimeAllow = true
         BuyTimeFloat = get_cvar_float("mp_buytime") * 60
         BuyTimeNum = floatround(BuyTimeFloat,floatround_floor)
         BuyTimeCvar = (get_cvar_num("divekit_buytime")) ? true : false
         BuyZoneCvar = (get_cvar_num("divekit_buyzone")) ? true : false
      }
      else // freezetime is over
      {
         set_task(BuyTimeFloat,"BuyTimeTask",701)
      }
      return PLUGIN_CONTINUE
   }
   public BuyTimeTask()
   {
      BuyTimeAllow = false // buytime is over
   }
   public BuyIcon(id) // player is in buyzone?
   {
      if (read_data(1))
         BuyZoneAllow[id] = true
      else
         BuyZoneAllow[id] = false
      return PLUGIN_CONTINUE
   }
   public Check(id) // check if player can buy
   {
      if ( !is_user_alive(id)){
         client_print(id,print_center,"You cannot buy while dead.")
         return false
      }

      if ((!BuyZoneAllow[id]&&BuyZoneCvar) ) {
         client_print(id,print_center,"You  cannot  buy  outside  of  the
   buyzone.")
         return false
      }

      if (BuyTimeCvar) {
         if (!CheckTime(id))
            return false
      }
      return true
   }
   public CheckTime(id) // check buytime
   {
      if (!BuyTimeAllow)
      {
         client_print(id,print_center,"%d  seconds  have passed...^n^nYou
   can't buy anything now!",BuyTimeNum)
         return false
      }
      return true
   }
   public buy_divekit(id) {
      new name[32]
      get_user_name(id,name,31)
      new userCash = get_user_money(id)
      new shade_cost = get_cvar_num("divekit_cost")

      if (AquaKit[id]) {
         client_print(id,print_chat,"[DIVEKIT]   You   currently  have  a
   diving kit.")
         return PLUGIN_HANDLED
      }
      if (!Check(id)) {
         return PLUGIN_HANDLED
      }
      if (!is_user_alive(id)) {
         return   PLUGIN_HANDLED
      }
      if (userCash < shade_cost) {
         client_print(id,print_center,"You have insufficient funds!")
         client_print(id,print_chat,"[DIVEKIT]  You  do  not  have enough
   money to buy a diving kit. You need $%i.",shade_cost)
         return   PLUGIN_HANDLED
      }
      else if (userCash >= shade_cost) {
         AquaKit[id]=true
         set_user_money(id,userCash - shade_cost,1)
         client_print(id,print_chat,"[DIVEKIT]   You   have  successfully
   bought a diving kit.")
         return   PLUGIN_HANDLED
      }

      return PLUGIN_HANDLED
   }
   public sell_divekit(id) {
      new name[32]
      get_user_name(id,name,31)
      new userCash = get_user_money(id)
      new shade_sell = get_cvar_num("divekit_cost")*2/3

      if (!AquaKit[id]) {
         client_print(id,print_chat,"[DIVEKIT]  You currently do not have
   a diving kit.")
      }
      if (AquaKit[id]) {
         AquaKit[id]=false
         set_user_money(id,userCash + shade_sell,1)
         client_print(id,print_chat,"[DIVEKIT]  You have sold your diving
   kit for 75 percent of the sell price.")
      }
      return PLUGIN_HANDLED
   }
   public HandleSay(id) {
      new Speech[192]
      read_args(Speech,192)
      remove_quotes(Speech)
      if(   (containi(Speech,   "water")   !=  -1)  ||  (containi(Speech,
   "diving")   !=   -1)   ||   (containi(Speech,   "damage")  !=  -1)  ||
   (containi(Speech, "breathe") != -1) ){
            client_print(id,print_chat,  "[DIVEKIT]  You can buy a Diving
   Kit on this server. Type /divekit for details.")
         }
      return PLUGIN_CONTINUE
   }
   public divekit_help(id)
   {
     new buffer[1024]
     new len = copy( buffer ,  1023 ,  "Buy Diving Kit:^n\
     Bind a key to buydivekit -- OR -- Type buydivekit in console^n^n\
     Sell Diving Kit:^n\
     Bind a key to selldivekit -- OR -- type selldivekit in console^n^n\
     In  order  to bind a key you must open your console and use the bind
   command: ^n\
     Bind ^"key^" ^"command^" ^n^n" )

     len  +=  copy(  buffer[len] ,  1023-len , "In this case the commands
   are ^"buydivekit^" & ^"selldivekit^".^nHere are some examples:^n\
       bind / buydivekit            bind / selldivekit^n^n\
     When you have the Diving kit:^n\
     - You will be able to breathe underwater. ")
     show_motd(id,buffer ,"Diving Kit Help:")
     return PLUGIN_HANDLED
   }
   public UnderTheSea( )
   {
      for( new i = 0; i < 33; i++ )
      {
         if ( is_user_alive( i ) && AquaKit[i] )
         {
            if ( Entvars_Get_Int( i, EV_INT_waterlevel ) == 3 )
            {
               Entvars_Set_Float(          i,         EV_FL_air_finished,
   Entvars_Get_Float( i, EV_FL_air_finished ) + 2.0 )
            }
         }
      }

      return PLUGIN_CONTINUE
   }
   public plugin_init() {
      register_plugin("Diving Kit","1.0","AssKicR/(Lazy)")
      register_clcmd("buydivekit","buy_divekit")
      register_clcmd("selldivekit","sell_divekit")
      register_concmd("amx_divekit","ass_diveingkit",ADMIN_LEVEL_A,"<
   Nick, UniqueID, #userid, @TEAM, or * > gives player an diving kit")
      register_concmd("amx_undivekit","ass_undiveingkit",ADMIN_LEVEL_A,"<
   Nick, UniqueID< #userid, @TEAM, or * > removes player's diving kit")
      register_cvar("divekit_cost","8000")
      register_cvar("divekit_buyzone","1")
      register_cvar("divekit_buytime","1")
      register_event("StatusIcon","BuyIcon","be","2=buyzone")
      register_event("RoundTime","RoundTime","bc")
      register_clcmd("say","HandleSay",0)
      register_clcmd("say  /divekit",  "divekit_help",0,":  Opens Divekit
   help menu")
      set_task(0.5,"cost_force",0,"",0,"b")
      set_task( 1.0, "UnderTheSea", 44, "", 0, "b" )
      return PLUGIN_CONTINUE
   }
