
   /* AMX Mod script.
   *
   * HLstats /skill plugin
   *  by JustinHoMi
   *
   */
   #include <amxmod>
   #include <amxmisc>
   #include <mysql>
   #include <mthread>
   new mhost[64]
   new muser[32]
   new mpass[32]
   new mdb[32]
   new mprefix[16]
   new mysql = 0
   #define NUM_NAMES 3
   public sql_init(){
       get_cvar_string("amx_hlstats_host",mhost,63)
       get_cvar_string("amx_hlstats_user",muser,31)
       get_cvar_string("amx_hlstats_pass",mpass,31)
       get_cvar_string("amx_hlstats_db",mdb,31)
       get_cvar_string("amx_hlstats_prefix",mprefix,15)
       new merror[32]
       mysql = mysql_connect(mhost,muser,mpass,mdb,merror,31)
       if(mysql < 1){
           server_print("[AMX]   MySQL   error  :  could  not  connect  :
   '%s'",merror)
       }
       else{
           server_print("[AMX] HLstats Plugin successfully connected.")
       }
       return PLUGIN_CONTINUE
   }
   public say_skill(id){
       new idx[2]
       idx[0] = id
       new tid =
   thread_run("skill_thread",idx,2,"",THREAD_SYSPRIO_LOW,THREAD_QUEUE_LOC
   AL)
       if(!tid) server_print("[HLSTATS] Skill: failure creating thread!")
       return PLUGIN_CONTINUE
   }
   public skill_thread(tid,idx[]){
       new id = idx[0]
       new authid[17]
       get_user_authid(id,authid,16)
       new query[256]
       format(query,255,"select        a.skill       from       %sPlayers
   a,%sPlayerUniqueIds b where a.playerId=b.playerId and \
           b.uniqueId='%s'",mprefix,mprefix,authid)
       mysql_query(mysql,query)
       new merror[32]
       mysql_error(mysql,merror,31)
       if (merror[0]){
           server_print("[AMX] MYSQL error: %s",merror)
           return PLUGIN_HANDLED
       }
       new skill[10]
       if(mysql_nextrow(mysql)>0)
       mysql_getfield(mysql,1,skill,9)
       format(query,255,"select  count(skill)  from %sPlayers where skill
   >=%s and hideranking=0",mprefix,skill)
       mysql_query(mysql,query)
       mysql_error(mysql,merror,31)
       if (merror[0]){
           server_print("[AMX] MYSQL error: %s",merror)
           return PLUGIN_HANDLED
       }
       new rank[16]
       if(mysql_nextrow(mysql)>0)
       mysql_getfield(mysql,1,rank,15)
       format(query,128,"select count(skill) from %sPlayers",mprefix)
       mysql_query(mysql,query)
       mysql_error(mysql,merror,31)
       if (merror[0]){
           server_print("[AMX] MYSQL error: %s",merror)
           return PLUGIN_HANDLED
       }
       new totalplayers[16]
       if(mysql_nextrow(mysql)>0)
       mysql_getfield(mysql,1,totalplayers,15)
       client_print(id,print_chat,"[HLSTATS] you are ranked %s of %s with
   %s points!",rank,totalplayers,skill)
       return PLUGIN_HANDLED
   }
   public admin_lastname(id,level,cid){
       if (!cmd_access(id,level,cid,2))
           return PLUGIN_HANDLED
       new idx[2]
       idx[0] = id
       new tid =
   thread_run("lastname_thread",idx,2,"",THREAD_SYSPRIO_LOW,THREAD_QUEUE_
   LOCAL)
       if(!tid)  server_print("[AMX  HLSTATS]  Lastname: failure creating
   thread!")
       return PLUGIN_HANDLED
   }
   public lastname_thread(tid,idx[]){
       new id = idx[0]
       new arg[33]
       read_argv(1,arg,33)
       new player = find_player("c",arg)
       if (!player) player = find_player("bl",arg)
       if(player){
           new authid[17]
           get_user_authid(player,authid,16)
           new query[256]
           format(query,255,"select    a.name   from   %sPlayerNames   a,
   %sPlayerUniqueIds b where b.uniqueId='%s' \
               AND     b.playerId=a.playerId     ORDER    BY    a.lastuse
   DESC",mprefix,mprefix,authid)
           mysql_query(mysql,query)
           new merror[32]
           mysql_error(mysql,merror,31)
           if (merror[0]){
               server_print("[AMX HLSTATS] MYSQL error: %s",merror)
               return PLUGIN_HANDLED
           }
           new i = 0
           new last[33] = ""
           new msg[196]
           while(mysql_nextrow(mysql)&&(i<NUM_NAMES)){
               if(i>0) add(msg,195,", ")
               mysql_getfield(mysql,1,last,32)
               add(msg,195,last)
               i++
           }
           new name[33]
           get_user_name(player,name,32)
           console_print(id,"[AMX] Last names for %s: %s",name,msg)
       }
       return PLUGIN_HANDLED
   }
   public plugin_end()
   {
       if (mysql > 0)
           mysql_close(mysql)
       return PLUGIN_CONTINUE
   }
   public plugin_init(){
       register_plugin("HLstats skill","0.9.4","JustinHoMi")
       register_cvar("amx_hlstats_host","127.0.0.1")
       register_cvar("amx_hlstats_user","root")
       register_cvar("amx_hlstats_pass","pass")
       register_cvar("amx_hlstats_db","hlstats")
       register_cvar("amx_hlstats_prefix","hlstats_")
       register_clcmd("say /skill","say_skill")
       register_clcmd("say_team /skill","say_skill")
       register_concmd("amx_lastname","admin_lastname",ADMIN_IMMUNITY,"<
   authid or part of nick >")
       set_task(3.0,"sql_init")
       return PLUGIN_CONTINUE
   }
