
   /* AMXMOD script.
   *
   * (c) Copyright 2000-2002, Vantage (aka Mouse)
   * This file is provided as is (no warranties).
   *
   * mapcapscore.sma
   *
   */
   /*
   *    THIS PLUGIN DOES NOT CHANGE YOUR SERVER'S NAME! (sorry for caps!)
   *
   *    This  plugin replaces server name on client's scoreboard with the
   map cap score. ie  ALLIES 1 - AXIS 0
   */
   #include <amxmod>
   #define  ALLBITS  0xFF   // So total number of max cap points in a map
   is 8. Lets me know if there are maps with greater then 8.
   new allies_caps
   new axis_caps
   new cur_total_caps   // Total cap points in the map currently playing
   new cur_total_capsbits // In bits
   new map_cap_score[2]
   new gmsg_ServerName
   public allies_cap()
   {
       remove_task(4154)  //  Remove check score task since it'll call it
   below
       new cap_point_num = read_data(1)

       if(cap_point_num  >= cur_total_caps){   // Save/Get current number
   of cap points
           cur_total_caps = cap_point_num + 1
           cur_total_capsbits = power2(cur_total_caps)
       }

       allies_caps |= (1<<cap_point_num)
       axis_caps &= (1<<cap_point_num) ^ ALLBITS
       new team[1]
       set_task(0.5,"check_mapcap",4154,team,1)
       return PLUGIN_CONTINUE
   }
   public axis_cap()
   {
       remove_task(4154)        //  Remove  check  score task since it'll
   call it below
       new cap_point_num = read_data(1)

       if(cap_point_num  >= cur_total_caps){   // Save/Get current number
   of cap points
           cur_total_caps = cap_point_num + 1
           cur_total_capsbits = power2(cur_total_caps)
       }
       allies_caps &= (1<<cap_point_num) ^ ALLBITS
       axis_caps |= (1<<cap_point_num)
       new team[1]
       team[0] = 1
       set_task(0.5,"check_mapcap",4154,team,1)

       return PLUGIN_CONTINUE
   }
   public caps_reset()
   {
       remove_task(4154)        //  Since caps are being reset no need to
   check mapcaps
       new cap_point_num = read_data(1)
       if(cap_point_num  >=  cur_total_caps){  // Save/Get current number
   of cap points
           cur_total_caps = cap_point_num + 1
           cur_total_capsbits = power2(cur_total_caps)
       }

       new mask = (1<<cap_point_num) ^ ALLBITS
       allies_caps &= mask
       axis_caps &= mask
       return PLUGIN_CONTINUE
   }
   public check_mapcap(team[])
   {
       if(team[0]){  // Axis scored so check
           if(!(axis_caps ^ cur_total_capsbits)){ // If axis map capped
               map_cap_score[team[0]] += 1
               send_score_all()
           }
       }
       else{        // Allies scored so check
           if(!(allies_caps  ^  cur_total_capsbits)){  //  If  allies map
   capped
               map_cap_score[team[0]] += 1
               send_score_all()
           }
       }
   }
   //************
   public gmsg_fServerName(id)
   {
       new score[21]
       format(score,20,"Allies %d - Axis
   %d",map_cap_score[0],map_cap_score[1])  //  When first connecting send
   player score
       message_begin( MSG_ONE, gmsg_ServerName, {0,0,0},id)
       write_string(score)
       message_end()
       return PLUGIN_CONTINUE
   }
   //****************  When mp_clan_restartround is done
   public clan_reset_delay(id)
   {
       new time_till = read_data(1)
       set_task(float(time_till),"clan_reset_round",0)
       return PLUGIN_CONTINUE
   }
   public clan_reset_round()
   {
       map_cap_score[0] = 0 // reset scores
       map_cap_score[1] = 0
       send_score_all()
   }
   //****************
   public send_score_all()
   {
       new score[21]
       format(score,20,"Allies %d - Axis
   %d",map_cap_score[0],map_cap_score[1])
       message_begin(  MSG_ALL,  gmsg_ServerName,  {0,0,0}) // Send reset
   scores
       write_string(score)
       message_end()
   }
   // Math **************************
   public power2(powernum)  // Find bitmask of current map, caps total
   {
       return (1<<powernum) - 1
   }
   public plugin_init()
   {
       register_plugin("Map Cap Score","0.9.3.5","Vantage aka Mouse")
       register_event("SetObj", "caps_reset","a","2=0")
       register_event("SetObj",  "allies_cap","a","2=1")  // allies cap a
   point
       register_event("SetObj",  "axis_cap","a","2=2")  //  axis  caps  a
   point
       register_event("ServerName", "gmsg_fServerName","b")
       register_event("ClanTimer", "clan_reset_delay","a")
       gmsg_ServerName = get_user_msgid("ServerName");
       return PLUGIN_CONTINUE
   }
