
   /* AMXMOD script.
   *
   * (c) Copyright 2000-2002, Vantage (aka Mouse)
   * This file is provided as is (no warranties).
   *
   *    aimtrain.sma
   */
   /*
   * Free weapon menu's are for CS1.5 (Will update when 1.6 is released)
   *
   *  This  plugin  was  only  meant  for  non  public  servers  and  few
   people(bots) but you may always try.
   *
   *  at_health_off  - disables/enables spawning with 'invincible' health
   (default: ON)
   *  at_nod_on  -  disables/enables  individual  'God'  Mode  , good for
   playing against bots (default: OFF)
   *
   * at_menu - automatic when selecting knife - can disable
   *
   * Known 'bugs' - Knife stats don't show unless you shoot a gun
   *
   * The first stat flash feature is kinda dumb but I think I have a good
   use for it for the next version.
   * Whenever that will be...
   */
   #include <amxmod>
   #include <amxmisc>
   #include <csstats>
   #define STATS_LIST_MAX 100
   #define ACC_RATIO0 25 // lower accuracy than this = Bad aim
   #define ACC_RATIO1 50 // lower accuracy than this = OK aim
   #define ACC_RATIO2 75 // lower accuracy than this = Good aim
   #define STATS1_CHAN 11
   #define STATS2_CHAN 12
   #define STATS3_CHAN 13
   #define STATS4_CHAN 14
   stock const Float:FREE_BUY_TIME = 15.0  // How long before you can buy
   another free weapon/item
   new stats_list1[33][STATS_LIST_MAX + 1],stats_list2[33][STATS_LIST_MAX
   + 1],
      stats_list3[33][STATS_LIST_MAX  + 1],stats_list4[33][STATS_LIST_MAX
   + 1]
   new weapon_ammo[33][2]
   new STATSCLR0[3] =   { 255, 255, 255}// Bad aim color (default white)
   new STATSCLR1[3] =   { 5, 255, 5}  // Ok aim color  (default green)
   new  STATSCLR2[3]  =   {  255,  100,  10} // Good aim color   (default
   orange)
   new STATSCLR3[3] =   { 255, 5, 5}  // Great aim color (default red)
   new previous_shots[33], previous_hits[33], previous_damage[33]
   new   previous_head[33],   previous_chest[33],   previous_stomach[33],
   previous_arms[33], previous_legs[33]
   new     shots_list[33][4],    hits_list[33][4],    damage_list[33][4],
   accuracy_list[33][4]
   new    head_list[33][4],    chest_list[33][4],    stomach_list[33][4],
   arms_list[33][4], legs_list[33][4]
   new color_list[33][12]
   stock  const Float:STATS_XCOORD = 0.35  //default starting x coord for
   stats
   stock  const Float:STATS_YCOORD = 0.65  //default starting y coord for
   stats
   new Float:stats_coords[33][5]
   new first_flash[33] = { 0, ...} // First stat can flash if they want
   new start_invincible = 1  // Everyone starts with "invincible" health
   new no_damage_mode = 0 // No damage mode disabled by default
   new can_buy[33] = { 1, ...}
   new knife_menu[33] = { 1, ...}
   public if_used_weapon(id)
   {
      if(is_user_bot(id)){
         return PLUGIN_CONTINUE
      }
      new weapon = read_data(2)
      new ammo = read_data(3)
      if( (weapon_ammo[id][0] == weapon) && (weapon_ammo[id][1] > ammo) )
   {   // If same weapon and have fired
         remove_task(57)  // remove 'display_stats' set_task since player
   has fired
         new stats_id[2 + 1]
         numtostr(id, stats_id, 2)
         set_task(0.5,"display_stats",57,stats_id,2)  // Display stats if
   not fired in 0.5 seconds
      }
      else if( weapon_ammo[id][0] != weapon  ){ //  If switched weapon
         give_ammo(id,weapon);give_ammo(id,weapon);give_ammo(id,weapon)
         weapon_ammo[id][0] = weapon
         if(weapon_ammo[id][0]  ==  CSW_KNIFE){  //  If  switch to knife,
   show current stats & at_menu...
            show_stats(id)
            if(knife_menu[id]) // If knife menu enabled
               client_cmd(id, "at_menu")
         }
      }
      else  if(  (weapon_ammo[id][0]  == weapon) && (weapon_ammo[id][1] <
   ammo) ){ // If reloaded
         //server_print("RELOAD")
         give_ammo(id,weapon);give_ammo(id,weapon);give_ammo(id,weapon)
         weapon_ammo[id][0] = weapon
      }
      weapon_ammo[id][1] = ammo
      return PLUGIN_CONTINUE
   }
   public display_stats(stats_id[])
   {
      new id = strtonum(stats_id)
      new stats[8], bodyhits[8]
      get_user_vstats(id,0,stats,bodyhits)

      for(new i = 3; i > 0 ; i--){ // copy stats to next index
         shots_list[id][i] = shots_list[id][i-1]
         hits_list[id][i] = hits_list[id][i-1]
         damage_list[id][i] = damage_list[id][i-1]
         accuracy_list[id][i] = accuracy_list[id][i-1]
         head_list[id][i] = head_list[id][i-1]
         chest_list[id][i] = chest_list[id][i-1]
         stomach_list[id][i] = stomach_list[id][i-1]
         arms_list[id][i] = arms_list[id][i-1]
         legs_list[id][i] = legs_list[id][i-1]
      }
      shots_list[id][0]  = stats[4] - previous_shots[id] // Fill in first
   index with current stats
      hits_list[id][0] = stats[5] - previous_hits[id]
      damage_list[id][0] = stats[6] - previous_damage[id]
      head_list[id][0] = bodyhits[1] - previous_head[id]
      chest_list[id][0] = bodyhits[2] - previous_chest[id]
      stomach_list[id][0] = bodyhits[3] - previous_stomach[id]
      arms_list[id][0] = (bodyhits[4] + bodyhits[5]) - previous_arms[id]
      legs_list[id][0] = (bodyhits[6] + bodyhits[7]) - previous_legs[id]
      for(new  i  = 11; i > 4 ; i -= 3){ // copy hud colors to their next
   index
         color_list[id][i] = color_list[id][i-3]
         color_list[id][i-1] = color_list[id][i-4]
         color_list[id][i-2] = color_list[id][i-5]
      }
      if(hits_list[id][0] > 0)      // Get current accuracy
         accuracy_list[id][0]   =   (   hits_list[id][0]   *   100   )  /
   shots_list[id][0]
      else
         accuracy_list[id][0] = 0

      if(accuracy_list[id][0]  <  ACC_RATIO0){  //  Get first stats color
   depending on current accuracy
         color_list[id][0] = STATSCLR0[0]
         color_list[id][1] = STATSCLR0[1]
         color_list[id][2] = STATSCLR0[2]
      }
      else  if(accuracy_list[id][0]  <  ACC_RATIO1){  //  Get first stats
   color depending on current accuracy
         color_list[id][0] = STATSCLR1[0]
         color_list[id][1] = STATSCLR1[1]
         color_list[id][2] = STATSCLR1[2]
      }
      else if(accuracy_list[id][0] < ACC_RATIO2){
         color_list[id][0] = STATSCLR2[0]
         color_list[id][1] = STATSCLR2[1]
         color_list[id][2] = STATSCLR2[2]
      }
      else{
         color_list[id][0] = STATSCLR3[0]
         color_list[id][1] = STATSCLR3[1]
         color_list[id][2] = STATSCLR3[2]
      }


      copy(stats_list4[id],   STATS_LIST_MAX,  stats_list3[id])  //  copy
   stats list to their next 'index'
      copy(stats_list3[id], STATS_LIST_MAX, stats_list2[id])
      copy(stats_list2[id], STATS_LIST_MAX, stats_list1[id])

      // Make first stats row
      format(stats_list1[id], STATS_LIST_MAX,
         "%6d/%-6d  ACC:%-6d  *  D:%-5d*  H:%-2d  C:%-2d  S:%-2d  A:%-2d
    L:%-2d^n",
         hits_list[id][0],shots_list[id][0],
   accuracy_list[id][0],damage_list[id][0],
         head_list[id][0],chest_list[id][0],stomach_list[id][0],arms_list
   [id][0],legs_list[id][0])
      set_hudmessage(color_list[id][0],color_list[id][1],color_list[id][2
   ],stats_coords[id][0],
         stats_coords[id][1]   ,first_flash[id],  2.0,  10.0,  1.0,  2.0,
   STATS1_CHAN)
      show_hudmessage(id,stats_list1[id])
      set_hudmessage(color_list[id][3],color_list[id][4],color_list[id][5
   ],stats_coords[id][0],
         stats_coords[id][2] ,0, 0.0, 10.0, 1.0, 2.0, STATS2_CHAN)
      show_hudmessage(id,stats_list2[id])
      set_hudmessage(color_list[id][6],color_list[id][7],color_list[id][8
   ],stats_coords[id][0],
         stats_coords[id][3] ,0, 0.0, 10.0, 1.0, 2.0, STATS3_CHAN)
      show_hudmessage(id,stats_list3[id])
      set_hudmessage(color_list[id][9],color_list[id][10],color_list[id][
   11],stats_coords[id][0],
         stats_coords[id][4] ,0, 0.0, 10.0, 1.0, 2.0, STATS4_CHAN)
      show_hudmessage(id,stats_list4[id])
      previous_shots[id] = stats[4]
      previous_hits[id] = stats[5]
      previous_damage[id] = stats[6]
      previous_head[id] = bodyhits[1]
      previous_chest[id] = bodyhits[2]
      previous_stomach[id] = bodyhits[3]
      previous_arms[id] = bodyhits[4] + bodyhits[5]
      previous_legs[id] = bodyhits[6] + bodyhits[7]
   }
   public at_reset(id)
   {
      if(start_invincible)
         set_user_health(id, 99940)

      previous_shots[id] = 0
      previous_hits[id] = 0
      previous_damage[id] = 0
      previous_head[id] = 0
      previous_chest[id] = 0
      previous_stomach[id] = 0
      previous_arms[id] = 0
      previous_legs[id] = 0
      return PLUGIN_CONTINUE
   }
   public knife_menu_off(id)
   {
      new name[15 + 1]
      get_user_name(id,name,15)
      if(!knife_menu[id]){
         ++knife_menu[id]
         client_print(id, print_center ,"*** %s - Menu: ON ***",name)
      }
      else{
         knife_menu[id] = 0
         client_print(id, print_center ,"*** %s - Menu: OFF ***",name)
      }
      return PLUGIN_HANDLED
   }
   public start_health(id,level,cid)
   {
       if(!access(id, level))
           return PLUGIN_HANDLED
      if(!start_invincible){
         ++start_invincible
         client_print(0,  print_center  ,"*** Spawn Health = 'Invincible'
   ***")
      }
      else{
         start_invincible = 0
         client_print(0, print_center ,"*** Spawn Health = NORMAL ***")
      }
      return PLUGIN_HANDLED
   }
   public no_damage(id) // no damage mode
   {
      static nod[33]
      new name[15 + 1]
      get_user_name(id,name,15)

      if(no_damage_mode){
         if(!nod[id]){
            set_user_godmode(id, ++nod[id])
            client_print(id,  print_center  ,"***  %s  -  'God' mode = ON
   ***",name)
         }
         else{
            set_user_godmode(id)
            nod[id] = 0
            client_print(id,  print_center  ,"***  %s  - 'God' mode = OFF
   ***",name)
         }
      }
      else
         client_print(id,print_center, "That command is DISABLED")
      return PLUGIN_HANDLED
   }
   public nod_enable(id,level)
   {
       if(!access(id, level))
           return PLUGIN_HANDLED
      if(!no_damage_mode){
         ++no_damage_mode
         client_print(0, print_center ,"*** Damage Mode = Enabled ***")
      }
      else{
         no_damage_mode = 0
         client_print(0, print_center ,"*** Damage Mode = Disabled ***")
      }
      return PLUGIN_HANDLED
   }
   public at_flash(id)  // First stat can flash if they want
   {
      new name[15 + 1]
      get_user_name(id,name,15)
      if(!first_flash[id]){
         ++first_flash[id]
         client_print(id,  print_center  ,"*** %s - First Stat Flash = ON
   ***",name)
      }
      else{
         first_flash[id] = 0
         client_print(id,  print_center ,"*** %s - First Stat Flash = OFF
   ***",name)
      }

      return PLUGIN_HANDLED
   }
   public give_ammo(id,weapon)
   {
      switch(weapon){
         case CSW_GLOCK18, CSW_ELITE, CSW_MP5NAVY, CSW_TMP:
            give_item(id , "ammo_9mm")
         case CSW_M4A1, CSW_SG552, CSW_AUG, CSW_SG550:
            give_item(id , "ammo_556nato")
         case CSW_USP, CSW_MAC10, CSW_UMP45:
            give_item(id , "ammo_45acp")

         case CSW_AK47, CSW_SCOUT, CSW_G3SG1:
            give_item(id , "ammo_762nato")
         case CSW_DEAGLE:
            give_item(id , "ammo_50ae")
         case CSW_P228:
            give_item(id , "ammo_357sig")
         case CSW_P90, CSW_FIVESEVEN:
            give_item(id , "ammo_57mm")
         case CSW_M3, CSW_XM1014:
            give_item(id , "ammo_buckshot")
         case CSW_AWP:
            give_item(id , "ammo_338magnum")
         case CSW_M249:
            give_item(id , "ammo_556natobox")
      }
   }
   public show_stats(id) // display current stats
   {
      set_hudmessage(color_list[id][0],color_list[id][1],color_list[id][2
   ],stats_coords[id][0],
         stats_coords[id][1]   ,first_flash[id],  2.0,  10.0,  1.0,  2.0,
   STATS1_CHAN)
      show_hudmessage(id,stats_list1[id])
      set_hudmessage(color_list[id][3],color_list[id][4],color_list[id][5
   ],stats_coords[id][0],
         stats_coords[id][2] ,0, 0.0, 10.0, 1.0, 2.0, STATS2_CHAN)
      show_hudmessage(id,stats_list2[id])
      set_hudmessage(color_list[id][6],color_list[id][7],color_list[id][8
   ],stats_coords[id][0],
         stats_coords[id][3] ,0, 0.0, 10.0, 1.0, 2.0, STATS3_CHAN)
      show_hudmessage(id,stats_list3[id])
      set_hudmessage(color_list[id][9],color_list[id][10],color_list[id][
   11],stats_coords[id][0],
         stats_coords[id][4] ,0, 0.0, 10.0, 1.0, 2.0, STATS4_CHAN)
      show_hudmessage(id,stats_list4[id])
   }
   public init_coords(id)
   {
      if(!id){
         for(new i = 1 ; i < 33; i++){
            stats_coords[i][0] = STATS_XCOORD
            stats_coords[i][1] = STATS_YCOORD
            stats_coords[i][2] = STATS_YCOORD + 0.08
            stats_coords[i][3] = STATS_YCOORD + 0.13
            stats_coords[i][4] = STATS_YCOORD + 0.18
         }
      }
      else{
         stats_coords[id][2] = stats_coords[id][1] + 0.08
         stats_coords[id][3] = stats_coords[id][1] + 0.13
         stats_coords[id][4] = stats_coords[id][1] + 0.18
      }
   }
   // *******************************  AT Menu
   public menu_at(id)
   {
      new keys = 639
      new at_menu[] = "\yAT Menu\w^n\
      ^n\
      3. ^"Free Weapons^"^n\
      4. ^"Change Stats Position^"^n\
      5. ^"No Damage Mode^"^n\
      6. ^"First Stat Flash^"^n\
      ^n\
      7. ^"Set Knife Menu^"^n\
      ^n\
      0. Exit"
      show_menu(id,keys,at_menu,5) // Show the above menu on screen
      return PLUGIN_HANDLED
   }
   public action_at(id,key)
   {
      switch(key){
         case 0: {
            return PLUGIN_HANDLED
         }
         case 1: {
            return PLUGIN_HANDLED
         }
         case 2: {
            client_cmd(id, "at_weapon") // AT weapon menu
         }
         case 3: {
            client_cmd(id,"at_pos")  // AT position menu
         }
         case 4: {
            client_cmd(id, "say at_nod") // No damage - off/on
         }
         case 5: {
            client_cmd(id, "say at_flash") // First stat flash off/on
         }
         case 6: {
            knife_menu_off(id)      // turn off/on knife menu
         }
         case 9: {
            return PLUGIN_HANDLED
         }
      }
      return PLUGIN_HANDLED
   }
   // **************************** End: AT Menu
   // *******************************  Change Stats Position Menu
   public menu_coords(id)
   {
      new keys = 527
      new coords_menu[] = "\yAT Position\w^n\
      ^n\
      1. ^"Left^"^n\
      2. ^"Right^"^n\
      3. ^"Up^"^n\
      4. ^"Down^"^n\
      ^n\
      0. Exit"
      show_menu(id,keys,coords_menu) // Show the above menu on screen
      return PLUGIN_HANDLED
   }
   public action_coords(id,key)
   {
      switch(key){
         case 0: {
            change_coords(id, key)
         }
         case 1: {
            change_coords(id, key)
         }
         case 2: {
            change_coords(id, key)
         }
         case 3: {
            change_coords(id, key)
         }
         case 9: {
            return PLUGIN_HANDLED
         }
      }
      return PLUGIN_HANDLED
   }
   public change_coords(id, key)
   {
      if(key == 0 || key == 1){
         if(key == 0)
            stats_coords[id][0] -= 0.05
         else
            stats_coords[id][0] += 0.05
         if(stats_coords[id][0] > 0.7 || stats_coords[id][0] < 0.0)
            stats_coords[id][0] = STATS_XCOORD
      }

      if(key == 2 || key == 3){
         if(key == 2)
            stats_coords[id][1] -= 0.05
         else
            stats_coords[id][1] += 0.05
         if(stats_coords[id][1] > 1.0 || stats_coords[id][1] < 0.0)
            stats_coords[id][1] = STATS_YCOORD
         init_coords(id)
      }
      show_stats(id)
      client_cmd(id, "at_pos")

      return PLUGIN_HANDLED
   }
   // **************************** End: Change Stats Position Menu
   // ********************************** Give Weapon Menu
   public menu_weap(id)
   {
      if(!can_buy[id]){
         client_print(id,  print_center,  "You  can  only buy in %.0f sec
   intervals.", FREE_BUY_TIME)
         return PLUGIN_HANDLED
      }
      new keys = 543
      new weap_menu[] = "\yAT Weapons\w^n\
      ^n\
      ALL WEAPONS ACTIVE AND FREE!^n\
      ^n\
      1. ^"Pistols^"^n\
      2. ^"Shotguns^"^n\
      3. ^"Submachine Guns^"^n\
      4. ^"Rifles^"^n\
      5. ^"Machine Gun^"^n\
      ^n\
      0. Exit"
      show_menu(id,keys,weap_menu) // Show the above menu on screen
      return PLUGIN_HANDLED
   }
   public action_weap(id,key)
   {
      new team = (get_user_team(id) - 1)
      switch(key){
         case 0: {
            new pistol_menu[2][] = { "#T_BuyPistol" , "#CT_BuyPistol" }
            show_menu(id,575, pistol_menu[team])
         }
         case 1: {
            show_menu(id,515, "#BuyShotgun")
         }
         case 2: {
            new       subm_menu[2][]       =      {"#T_BuySubMachineGun",
   "#CT_BuySubMachineGun"}
            show_menu(id,543, subm_menu[team])
         }
         case 3: {
            new rifle_menu[2][] = {"#T_BuyRifle", "#CT_BuyRifle"}
            show_menu(id,767, rifle_menu[team])
         }
         case 4: {
            show_menu(id,513, "#BuyMachineGun")
         }
         case 9: {
            return PLUGIN_HANDLED
         }
      }
      return PLUGIN_HANDLED
   }
   public give_pistol(id, key)
   {
      switch(key){
         case 0: {
            at_give_item(id, "weapon_usp")
         }
         case 1: {
            at_give_item(id, "weapon_glock18")
         }
         case 2: {
            at_give_item(id, "weapon_deagle")
         }
         case 3: {
            at_give_item(id, "weapon_p228")
         }
         case 4: {
            at_give_item(id, "weapon_elite")
         }
         case 5: {
            at_give_item(id, "weapon_fiveseven")
         }
         case 9: {
            return PLUGIN_HANDLED
         }
      }

      return PLUGIN_HANDLED
   }
   public give_shotgun(id, key)
   {
      switch(key){
         case 0: {
            at_give_item(id, "weapon_m3")
         }
         case 1: {
            at_give_item(id, "weapon_xm1014")
         }
         case 9: {
            return PLUGIN_HANDLED
         }
      }

      return PLUGIN_HANDLED
   }
   public give_subm(id, key)
   {
      switch(key){
         case 0: {
            at_give_item(id, "weapon_mp5navy")
         }
         case 1: {
            at_give_item(id, "weapon_tmp")
         }
         case 2: {
            at_give_item(id, "weapon_p90")
         }
         case 3: {
            at_give_item(id, "weapon_mac10")
         }
         case 4: {
            at_give_item(id, "weapon_ump45")
         }
         case 9: {
            return PLUGIN_HANDLED
         }
      }

      return PLUGIN_HANDLED
   }
   public give_rifle(id, key)
   {
      switch(key){
         case 0: {
            at_give_item(id, "weapon_ak47")
         }
         case 1: {
            at_give_item(id, "weapon_sg552")
         }
         case 2: {
            at_give_item(id, "weapon_m4a1")
         }
         case 3: {
            at_give_item(id, "weapon_aug")
         }
         case 4: {
            at_give_item(id, "weapon_scout")
         }
         case 5: {
            at_give_item(id, "weapon_awp")
         }
         case 6: {
            at_give_item(id, "weapon_g3sg1")
         }
         case 7: {
            at_give_item(id, "weapon_sg550")
         }
         case 9: {
            return PLUGIN_HANDLED
         }
      }

      return PLUGIN_HANDLED
   }
   public give_machineg(id, key)
   {
      switch(key){
         case 0: {
            at_give_item(id, "weapon_m249")
         }
         case 9: {
            return PLUGIN_HANDLED
         }
      }

      return PLUGIN_HANDLED
   }
   public at_give_item(id, weapon[])
   {
      can_buy[id] = 0 // Getting something, so can't buy anymore...
      new free_id[3]
      numtostr(id, free_id, 2)
      set_task(FREE_BUY_TIME,"free_buy_enable",0,free_id,2)  //  ....Till
   this task execs
      give_item(id, weapon)
   }
   public free_buy_enable(free_id[]) // "enable free buy" task
   {
      new id = strtonum(free_id)
      can_buy[id] = 1
   }
   // *********************************** End: Give Weapon Menu stuff
   public plugin_init()
   {
      register_plugin("Aim Train","0.9.3","Vantage aka Mouse")
      register_event("ResetHUD","at_reset","be")
      register_event("CurWeapon","if_used_weapon","be","1=1")

      register_clcmd("at_health",   "start_health",   ADMIN_LEVEL_A,   "-
   Normal or ^"Invincible^" Start Health")
      register_clcmd("at_nod_on", "nod_enable", ADMIN_LEVEL_A, "- Players
   can use 'God' Mode")
      register_clcmd("say at_flash","at_flash")
      register_clcmd("say at_nod","no_damage")
      register_clcmd("say at_pos", "menu_coords")

      register_clcmd("at_menu", "menu_at")
      register_menucmd(register_menuid("AT Menu"),639,"action_at")
      register_clcmd("at_pos", "menu_coords")
      register_menucmd(register_menuid("AT
   Position"),527,"action_coords")
      register_clcmd("at_weapon", "menu_weap")
      register_menucmd(register_menuid("AT Weapons"),543,"action_weap")
      register_menucmd(register_menuid("#T_BuyPistol"),575,"give_pistol")
      register_menucmd(register_menuid("#CT_BuyPistol"),575,"give_pistol"
   )
      register_menucmd(register_menuid("#BuyShotgun"),515,"give_shotgun")
      register_menucmd(register_menuid("#T_BuySubMachineGun"),543,"give_s
   ubm")
      register_menucmd(register_menuid("#CT_BuySubMachineGun"),543,"give_
   subm")
      register_menucmd(register_menuid("#T_BuyRifle"),767,"give_rifle")
      register_menucmd(register_menuid("#CT_BuyRifle"),767,"give_rifle")
      register_menucmd(register_menuid("#BuyMachineGun"),513,"give_machin
   eg")
      init_coords(0)
      return PLUGIN_CONTINUE
   }
