
   /* AMX Mod script.
   *
   * (c) 2003, OLO
   * This file is provided as is (no warranties).
   *
   * Plugin works with Stats Settings Plugin. Just run both of them.
   * By amx_statscfg command (from Stats Settings Plugin)
   * you will be able to set all settings and save them to a file.
   *
   * Example of usage for some options:
   * amx_ststacfg on ShowAttackers
   * amx_ststacfg on SayHP
   *
   * Accept able are also parts of name:
   * amx_statscfg off say
   * amx_statscfg on show
   *
   * Original Plugin (stats.amx) written by OLO.
   * Modified by Vapok with help from SidLuke.
   *
   * Kudos to SidLuke for completion of DoDStats Module.
   *
   * Requires DoDStats Module (AMX & MM)
   */
   #include <amxmod>
   #include <amxmisc>
   #include <dodstats>
   // You can also manualy enable these options by setting them to 1
   // For example:
   // public ShowAttackers = 1
   // However amx_statscfg command is recommended
   public ShowAttackers  // shows attackers
   public ShowVictims    // shows victims
   public ShowKiller     // shows killer
   public EndPlayer      // displays player stats at the end of map
   public EndTop15       // displays top15 at the end of map
   public  KillerHpAp     //  displays killer hp&ap to victim console and
   screen
   public SayHP          // displays information about user killer
   public SayStats       // displays players stats and rank
   public SayTop15       // displays first 15. players
   public SayRank        // displays user position in rank
   public SayStatsMe     // displays user stats
   new g_Killers[33][4]
   new g_Buffer[2048]
   new g_userPosition[33]
   new g_userState[33]
   new g_userPlayers[33][32]
   new  g_bodyParts[8][]  =  {"whole body","head","chest","stomach","left
   arm","right arm","left leg","right leg"}
   new g_disabledMsg[] = "Server has disabled that option"
   public plugin_init() {
     register_plugin("Advanced DoD Stats","0.9.4","Vapok")
     register_event("DeathMsg","eDeathMsg","a")
     register_event("ResetHUD","eResetHud","b")
     register_event("30","eInterMission","a")
     register_clcmd("say  /hp","cmdKiller",0,"- displays info. about your
   killer")
     register_clcmd("say    /statsme","cmdStatsMe",0,"-   displays   your
   stats")
     register_clcmd("say /stats","cmdStats",0,"- displays others stats")
     register_clcmd("say    /top15","cmdTop15",0,"-   displays   top   15
   players")
     register_clcmd("say   /rank","cmdRank",0,"-   displays  your  server
   stats")
     register_menucmd(register_menuid("Server
   Stats"),1023,"actionStatsMenu")
   }
   new g_addStast[] = "amx_statscfg add ^"%s^" %s"
   public plugin_cfg(){
     server_cmd(g_addStast,"Show Attackers","ShowAttackers")
     server_cmd(g_addStast,"Show Victims","ShowVictims")
     server_cmd(g_addStast,"Show killer","ShowKiller")
     server_cmd(g_addStast,"Stats at the end of map","EndPlayer")
     server_cmd(g_addStast,"Top15 at the end of map","EndTop15")
     server_cmd(g_addStast,"Show killer hp&ap","KillerHpAp")
     server_cmd(g_addStast,"Say /hp","SayHP")
     server_cmd(g_addStast,"Say /stats","SayStats")
     server_cmd(g_addStast,"Say /top15","SayTop15")
     server_cmd(g_addStast,"Say /rank","SayRank")
     server_cmd(g_addStast,"Say /statsme","SayStatsMe")
   }
   /* build list of attackers */
   getAttackers(id) {
     new name[32],wpn[32], stats[9],body[8],found=0
     new pos = copy(g_Buffer,2047,"Attackers:^n")
     new amax = get_maxplayers()
     for(new a = 1; a <= amax; ++a){
       if(get_user_astats(id,a,stats,body,wpn,31)){
         found = 1
         if (stats[0])
           format(wpn,31," -- %s",wpn)
         else
           wpn[0] = 0
         get_user_name(a,name,31)
         pos   +=   format(g_Buffer[pos],2047-pos,"%s  --  %d  dmg  /  %d
   hit(s)%s^n",name,stats[6],stats[5],wpn)
       }
     }
     return found
   }
   /* build list of victims */
   getVictims(id) {
     new name[32],wpn[32], stats[9],body[8],found=0
     new pos = copy(g_Buffer,2047,"Victims:^n")
     new amax = get_maxplayers()
     for(new a = 1; a <= amax; ++a){
       if(get_user_vstats(id,a,stats,body,wpn,31)){
         found = 1
         if (stats[1])
           format(wpn,31," -- %s",wpn)
         else
           wpn[0] = 0
         get_user_name(a,name,31)
         pos   +=   format(g_Buffer[pos],2047-pos,"%s  --  %d  dmg  /  %d
   hit(s)%s^n",name,stats[6],stats[5],wpn)
       }
     }
     return found
   }
   /* build list of hita for AV List */
   getHits(id,killer) {
     new stats[9], body[8], pos = 0
     g_Buffer[0] = 0
     get_user_astats(id,killer,stats,body)
     for(new a = 1; a < 8; ++a)
       if(body[a])
         pos             +=            format(g_Buffer[pos],2047-pos,"%s:
   %d^n",g_bodyParts[a],body[a])
   }
   /* get top 15 */
   getTop15(){
     new stats[9], body[8], name[32]
     new pos =
   copy(g_Buffer,2047,"#   nick                           kills/deaths/sc
   ore          hits/shots/headshots^n")
     new imax = get_statsnum()
     if (imax > 15) imax = 15
     for(new a = 0; a < imax; ++a){
       get_stats(a,stats,body,name,31)
       pos +=
   format(g_Buffer[pos],2047-pos,"%2d.  %-28.27s    %d/%d/%d
            %d/%d/%d^n",a+1,name,stats[0],stats[1],stats[7],stats[5],stat
   s[4],stats[2])
     }
   }
   /* build list of hits for say hp */
   getMyHits(id,killed) {
     new name[32], stats[9], body[8], found = 0
     get_user_name(killed,name,31)
     new pos = format(g_Buffer,2047,"You hit %s in:",name)
     get_user_vstats(id,killed,stats,body)
     for(new a = 1; a < 8; ++a){
       if(body[a]){
         found = 1
         pos      +=      format(g_Buffer[pos],2047-pos,"      %s:     %d
   ",g_bodyParts[a],body[a])
       }
     }
     return found
   }
   /* save hits and damage */
   public eDamage(id) {
     if (g_Killers[id][0]) {
       if ( ShowKiller ){
         new name[32], stats[9], body[8], wpn[33], mstats[9], mbody[8]
         get_user_name(g_Killers[id][0],name,31)
         get_user_astats(id,g_Killers[id][0],stats,body,wpn,31)
         get_user_vstats(id,g_Killers[id][0],mstats,mbody)
         set_hudmessage(220,80,0,0.05,0.15,0, 6.0, 12.0, 1.0, 2.0, 1)
         getHits(id,g_Killers[id][0])
         show_hudmessage(id,"%s killed you with %s^nfrom distance of %.2f
   meters.^nHe  did  %d  damage  to  you  with  %d  hit(s)^nand still has
   %dhp.^nYou did %d damage to him with %d hit(s).^nHe hits you in:^n%s",
             name,wpn,float(g_Killers[id][3]) *
   0.0254,  stats[6],stats[5],    g_Killers[id][1],
               mstats[6],mstats[5],g_Buffer )
       }
       if ( ShowVictims && getVictims(id) ){
         set_hudmessage(0,80,220,0.55,0.60,0, 6.0, 12.0, 1.0, 2.0, 4)
         show_hudmessage(id,g_Buffer)
       }
       if ( ShowAttackers  && getAttackers(id)){
         set_hudmessage(220,80,0,0.55,0.35,0, 6.0, 12.0, 1.0, 2.0, 3)
         show_hudmessage(id,g_Buffer)
       }
     }
   }
   /* save state at death */
   public eDeathMsg() {
     new killer = read_data(1)
     new victim = read_data(2)
     if (killer != victim && killer) {
       new vorigin[3], korigin[3]
       get_user_origin(victim,vorigin)
       get_user_origin(killer,korigin)
       g_Killers[victim][0] = killer
       g_Killers[victim][1] = get_user_health(killer)
       g_Killers[victim][2] = get_user_armor(killer)
       g_Killers[victim][3] = get_distance(vorigin,korigin)
       eDamage(victim)
     }
   }
   public eResetHud( id )
     g_Killers[ id ][0] = 0
   public cmdKiller(id) {
     if ( !SayHP ){
       client_print(id,print_chat, g_disabledMsg )
       return PLUGIN_HANDLED
     }
     if (g_Killers[id][0]) {
       new name[32], stats[9], body[8], wpn[33], mstats[9], mbody[8]
       get_user_name(g_Killers[id][0],name,31)
       get_user_astats(id,g_Killers[id][0],stats,body,wpn,31)
       get_user_vstats(id,g_Killers[id][0],mstats,mbody)
       client_print(id,print_chat,"%s killed you with %s from distance of
   %.2f meters",  name,wpn,float(g_Killers[id][3]) * 0.0254 )
       client_print(id,print_chat,"He did %d damage to you with %d hit(s)
   and still had %dhp and %dap",
         stats[6],stats[5], g_Killers[id][1],g_Killers[id][2] )
       client_print(id,print_chat,"You  did  %d  damage  to  him  with %d
   hit(s)",mstats[6], mstats[5] )
       if (getMyHits(id,g_Killers[id][0]))
   client_print(id,print_chat,g_Buffer)
     }
     else {
       client_print(id,print_chat,"You have no killer...")
     }
     return PLUGIN_CONTINUE
   }
   public cmdStatsMe(id){
     if ( !SayStatsMe ){
       client_print(id,print_chat, g_disabledMsg )
       return PLUGIN_HANDLED
     }
     displayStats(id,id)
     return PLUGIN_CONTINUE
   }
   public displayStats(id,dest) {
     new name[32], stats[9], body[8]
     get_user_wstats(id,0,stats,body)
     new   pos   =  format(g_Buffer,2047,"Kills:  %d^nDeaths:  %d^nScore:
   %d^nDamage: %d^nHits: %d^nShots: %d^n^n",
       stats[0],stats[1],stats[7],stats[6],stats[5],stats[4])
     for(new a = 1; a < 40; ++a) {
       if (get_user_wstats(id,a,stats,body)){
         if ( is_melee(a) )
           stats[4] = -1;
         get_wpnname(a,name,31)
         pos   +=   format(g_Buffer[pos],2047-pos,"%s   shots:  %d  hits:
   %d  damage: %d  kills: %d  deaths: %d^n",
           name,stats[4],stats[5],stats[6],stats[0],stats[1])
       }
     }
     get_user_name(id,name,31)
     show_motd(dest,g_Buffer,name)
     return PLUGIN_CONTINUE
   }
   public cmdRank(id){
     if ( !SayRank ){
       client_print(id,print_chat, g_disabledMsg )
       return PLUGIN_HANDLED
     }
     displayRank(id,id)
     return PLUGIN_CONTINUE
   }
   displayRank(id,dest) {
     new name[32], stats[9], body[8]
     new rank_pos = get_user_stats(id,stats,body)
     new   pos  =  format(g_Buffer,2047,"Kills:  %d^nDeaths:  %d^nDamage:
   %d^nHits: %d^nShots: %d^n^n",
       stats[0],stats[1],stats[6],stats[5],stats[4])
     pos  +=  format(g_Buffer[pos],2047-pos,"Hits:^n%s:  %d^n%s:  %d^n%s:
   %d^n%s: %d^n%s: %d^n%s: %d^n%s: %d^n^n",
       g_bodyParts[1],body[1],g_bodyParts[2],body[2],g_bodyParts[3],body[
   3], g_bodyParts[4],body[4],
       g_bodyParts[5],body[5],g_bodyParts[6],body[6],g_bodyParts[7],body[
   7])
     format(g_Buffer[pos],2047-pos,"%s       rank      is      %d      of
   %d",(id==dest)?"Your":"His", rank_pos,get_statsnum())
     get_user_name(id,name,31)
     show_motd(dest,g_Buffer,name)
   }
   public cmdTop15(id) {
     if ( !SayTop15 ){
       client_print(id,print_chat, g_disabledMsg )
       return PLUGIN_HANDLED
     }
     getTop15()
     show_motd(id,g_Buffer,"Top 15")
     return PLUGIN_CONTINUE
   }
   public endGameStats(){
     if ( EndPlayer ){
       new players[32], inum
       get_players(players,inum)
       for(new i = 0; i < inum; ++i)
         displayStats(players[i],players[i])
     }
     else if ( EndTop15 ) {
       new players[32], inum
       get_players(players,inum)
       getTop15()
       for(new i = 0; i < inum; ++i)
         show_motd(players[i],g_Buffer,"Top 15")
     }
   }
   public eInterMission()
     set_task(1.0,"endGameStats")
   public cmdStats(id){
     if ( !SayStats ){
       client_print(id,print_chat, g_disabledMsg )
       return PLUGIN_HANDLED
     }
     showStatsMenu(id,g_userPosition[id]=0)
     return PLUGIN_CONTINUE
   }
   public actionStatsMenu(id,key){
     switch(key){
     case 7: {
       g_userState[id] = 1 - g_userState[id]
       showStatsMenu(id,g_userPosition[id])
     }
     case 8: showStatsMenu(id,++g_userPosition[id])
     case 9: showStatsMenu(id,--g_userPosition[id])
     default:{
       new option = g_userPosition[id] * 7 + key
       new index = g_userPlayers[id][option]
       if (is_user_connected(index)){
         if (g_userState[id])
           displayRank(index,id)
         else
           displayStats(index,id)
       }
       showStatsMenu(id,g_userPosition[id])
       }
     }
     return PLUGIN_HANDLED
   }
   showStatsMenu(id,pos){
     if (pos < 0) return PLUGIN_HANDLED
     new menu_body[512], inum, k = 0, start = pos * 7
     get_players(g_userPlayers[id],inum)
     if (start >= inum) start = pos = g_userPosition[id] = 0
     new  len  = format(menu_body,511,"\yServer Stats\R%d/%d^n\w^n",pos +
   1,((inum/7)+((inum%7)?1:0)))
     new name[32], end = start + 7, keys = (1<<9)|(1<<7)
     if (end > inum) end = inum
     for(new a = start; a < end; ++a){
       get_user_name(g_userPlayers[id][a],name,31)
       keys |= (1<<k)
       len += format(menu_body[len],511-len,"%d. %s^n\w",++k,name)
     }
     len += format(menu_body[len],511-len,"^n8. %s^n\w",g_userState[id] ?
   "Show rank" : "Show stats" )
     if (end != inum){
       len += format(menu_body[len],511-len,"^n9. More...^n0. %s" , pos ?
   "Back" : "Exit" )
       keys |= (1<<8)
     }
     else len += format(menu_body[len],511-len,"^n0. %s" , pos ? "Back" :
   "Exit" )
     show_menu(id,keys,menu_body)
     return PLUGIN_HANDLED
   }
