
//------ SAY /HLSTATS BY KAKSI ------------------------------------------------
------------------------------// 
// 
// This plugin catches the /myhlstats, /hlstats, /rank, /skill, 
// /top15 say commands and returns 
// the information from the HLStats database. 
// 
// 
// 
// Thanks to JustinHomi's and Johnny's hlstats_skill plugins for inspiration 
// 
// CMDS: 
//    say /top15      -- Displays top15 players from HLStats. 
//    say /hlstats      -- Displays player's rank from HLStats. 
//    say /skill      -- Same as /hlstats 
//    say /rank         -- Same as /hlstats 
// 
//    say /myhlstats   -- Opens the CS 1.6 browser and displays the players per
sonal hlstats page 
// 
//------ INSTALLATION ---------------------------------------------------------
------------------------------// 
// 
// -> Compile the plugin and put it in the plugins folder of amx 
// -> Add the plguin to the plugins.ini folder 
// -> Edit the database settings in the top15.php 
// -> Put the top15.php file in the same folder as your hlstats.php file on you
r webserver 
// -> Add the cvars below in your amx.cfg file 
// -> Restart your server and you are done. 
// 
// CVARS: 
//    amx_hlstats_host      -- HLStats database host (IP address) 
//    amx_hlstats_user      -- HLStats database user login name. 
//    amx_hlstats_pass      -- HLStats database password. 
//    amx_hlstats_db        -- HLStats database name 
//    amx_hlstats_prefix    -- HLStats database table prefix 
//    amx_hlstats_url        -- The url to you hlstats withour the final /... (
http://hlstats.gbgonline.net) 
// 
//-----------------------------------------------------------------------------
------------------------------// 

#include <amxmod> 
#include <amxmisc> 
#include <mysql> 

//variables 
new mhost[64] 
new muser[32] 
new mpass[32] 
new mdb[32] 
new hlstats_url[512] 
new hlstats_prefix[32] 
new mysql = 0 

//------------------------------------------------- START PLUGIN --------------
--------------------------// 
public plugin_init() { 

    register_plugin("Say HLStats for Steam","1.1","kaksi") 
       
    register_clcmd("say /myhlstats","say_myhlstats") 
    register_clcmd("say /hlstats","say_skill") 
    register_clcmd("say /skill","say_skill") 
    register_clcmd("say /rank","say_skill")     
    register_clcmd("say /top15","say_top15")
    
    register_cvar("amx_hlstats_host","127.0.0.1")
    register_cvar("amx_hlstats_user","root")
        register_cvar("amx_hlstats_pass","")
        register_cvar("amx_hlstats_db","hlstats")
        register_cvar("amx_hlstats_url","http://www.yoursite.com")
        register_cvar("amx_hlstats_prefix","hlstats_") 
      
        return PLUGIN_CONTINUE 
} 
//------------------------------------------------- END PLUGIN ----------------
------------------------// 

//------------------------------------------------- START CONNECT TO DATABASAE 
----------------------------------------// 
public sql_init(){ 

   //Get server and database info... 
   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_url",hlstats_url,31) 
   get_cvar_string("amx_hlstats_prefix",hlstats_prefix,31) 

   new merror[64] 
   mysql = mysql_connect(mhost,muser,mpass,mdb,merror,63) 

   if(mysql < 1) 
      server_print("[AMX][HLSTATS] MySQL error: could not connect : '%s'",merro
r) 
   else 
      server_print("[AMX][HLSTATS] Successfully connected to the database.") 

   return PLUGIN_CONTINUE 
} 
//------------------------------------------------- END CONNECT TO DATABASAE --
--------------------------------------// 

//------------------------------------------------- START SAY /myhlstats ------
----------------------------------// 
public say_myhlstats(id){ 

   //Load database connection function 
   sql_init() 
    
   new steamid[32] 
   new client_name[32] 
   new query[256] 
   new merror[32] 
   new playerId[16] 
   new url[512] 
   new motd[512] 

    
   //Get user info 
   get_user_authid(id,steamid,31) 
   get_user_name(id,client_name,31) 

   //Format query 
   format(query,255,"SELECT * FROM %splayeruniqueids WHERE uniqueId='%s'",hlsta
ts_prefix,steamid) 
   //Connect to database 
   mysql_query(mysql,query) 
   mysql_error(mysql,merror,31) 
   if (mysql < 1){ 
      server_print("[AMX] MYSQL error: %s",merror) 
      return PLUGIN_HANDLED 
   }else{ 
      server_print("[AMX][HLSTATS] Found PlayerID for %s",client_name) 
   } 
    
    
   if(mysql_nextrow(mysql)>0){ 
      mysql_getfield(mysql,1,playerId,15) 
   } 

   //Format the url's... 
   format(url,511,"%s/hlstats.php?mode=playerinfo&player=%s",hlstats_url,player
Id)    
   format(motd, 511, "Loading...<meta HTTP-EQUIV=^"Refresh^" CONTENT=^"0; URL=%
s^">", url) 
   //Show the browser    
   show_motd(id, motd, "MY HLSTATS BROWSER") 
    
   return PLUGIN_HANDLED 
} 
//------------------------------------------------- END SAY /myhlstats --------
--------------------------------// 

//------------------------------------------------- START FUNCTION SAY /HLSTATS
 ----------------------------------------// 
public say_skill(id){ 

   //Load database connection function 
   sql_init() 

   //Define variables 
   new merror[32] 
   new query[256] 
   new steamid[32] 
   new client_name[32] 
   new skill[16] 
   new rank[16] 
   new totalplayers[16] 

    
    //Get user info 
   get_user_authid(id,steamid,31) 
   get_user_name(id,client_name,31) 
    
   //Format the query 
   format(query,255,"select a.skill from %sPlayers a,%sPlayerUniqueIds b where 
a.playerId=b.playerId and b.uniqueId='%s'",hlstats_prefix,hlstats_prefix,steami
d) 
   //Connect to the database to get clients playerID 
   mysql_query(mysql,query) 
   mysql_error(mysql,merror,31) 
   if (mysql < 1){ 
      server_print("[AMX] MYSQL error: %s",merror) 
      return PLUGIN_HANDLED 
   }else{ 
      server_print("[AMX][HLSTATS] Found skill for %s",client_name) 
   } 
    
   //Set the player's skill if it exists. 
   if(mysql_nextrow(mysql)>0) 
   { 
      mysql_getfield(mysql,1,skill,9) 
   } 
    
   //Format the query    
   format(query,255,"select count(skill) from %sPlayers WHERE skill >= %s and h
ideranking=0",hlstats_prefix,skill) 
   //Connect to the database to get clients rank 
   mysql_query(mysql,query) 
   mysql_error(mysql,merror,31) 
   if (mysql < 1){ 
      server_print("[AMX] MYSQL error: %s",merror) 
      return PLUGIN_HANDLED 
   }else{ 
      server_print("[AMX][HLSTATS] Found rank for %s",client_name) 
   } 
    
   //Set Clients rank 
   if(mysql_nextrow(mysql)>0) 
   { 
      mysql_getfield(mysql,1,rank,15) 
   } 
    
   //Format the query 
   format(query,255,"SELECT count(skill) FROM %sPlayers",hlstats_prefix) 
   //Connect to the database to get total players 
   mysql_query(mysql,query) 
   mysql_error(mysql,merror,31) 
   if (mysql < 1){ 
      server_print("[AMX] MYSQL error: %s",merror) 
      return PLUGIN_HANDLED 
   }else{ 
      server_print("[AMX][HLSTATS] Found total amount of players...") 
   } 
    
   //Set total players 
   if(mysql_nextrow(mysql)>0) 
   { 
      mysql_getfield(mysql,1,totalplayers,15) 
   } 
    
   // Report to player only. 
   client_print(id, print_chat, "[AMX][HLSTATS] you are ranked %s of %s with %s
 points!", rank, totalplayers, skill) 
    
   if (mysql > 0){ 
      mysql_close(mysql) 
   } 
    
   return PLUGIN_HANDLED 
} 
//------------------------------------------------- START FUNCTION SAY /HLSTATS
 ----------------------------------------// 

//------------------------------------------------- START FUNCTION SAY /TOP15 -
---------------------------------------// 
public say_top15(id){ 

   new motd[512] 
   new url[512] 
    
   //Get hlstats url 
   get_cvar_string("amx_hlstats_url",hlstats_url,511) 

   //Format the url's... 
   format(url,511,"%s/top15.php",hlstats_url)    
   format(motd, 511, "Loading...<meta HTTP-EQUIV=^"Refresh^" CONTENT=^"0; URL=%
s^">", url)  
   show_motd(id, motd, "HLSTATS TOP15 BROWSER") 
    
   return PLUGIN_HANDLED 
} 
//------------------------------------------------- END FUNCTION SAY /TOP15 ---
-------------------------------------// 
