public Action:CMD_Rank(client,args){
if(!g_bEnabled || client == 0 || !IsClientInGame(client))
return Plugin_Handled;
//LogToFile("rankme.debug.log","\"sm_rank\" command called by client %d.",client);
if(g_aStats[client][KILLS] < g_MinimalKills){
CPrintToChat(client,"%s %t",MSG,"NotRanked",g_aStats[client][KILLS],g_MinimalKills);
return Plugin_Handled;
}
new String:query[500];
MakeSelectQuery(query,sizeof(query));
if(g_RankMode == 1)
Format(query,sizeof(query),"%s ORDER BY score DESC",query);
else if(g_RankMode == 2){
if(g_bMysql)
Format(query,sizeof(query),"%s ORDER BY CAST(kills as DECIMAL)/CAST(Case when deaths=0 then 1 ELSE deaths END as DECIMAL) DESC, score DESC",query);
else
Format(query,sizeof(query),"%s ORDER BY CAST(kills as float)/CAST(Case when deaths=0 then 1 ELSE deaths END as float) DESC, score DESC",query);
}
SQL_TQuery(g_hStatsDb,SQL_RankCallback,query,client);
return Plugin_Handled;
}
public SQL_RankCallback(Handle:owner, Handle:hndl, const String:error[], any:client){
if(hndl == INVALID_HANDLE)
{
LogError("[RankMe] Query Fail: %s", error);
return;
}
if(client == 0 || !IsClientInGame(client))
return;
//LogToFile("rankme.debug.log","Rank SQL callback called by client %d.",client);
new i;
g_TotalPlayers =SQL_GetRowCount(hndl);
new String:Name_receive[MAX_NAME_LENGTH];
new String:Auth_receive[64];
new String:Ip_receive[64];
new Float:kdr;
new deaths;
while(SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
{
i++;
SQL_FetchString(hndl,2,Name_receive,MAX_NAME_LENGTH*2+1);
SQL_FetchString(hndl,1,Auth_receive,64);
SQL_FetchString(hndl,3,Ip_receive,64);
// PrintToServer("%d %s %s",i, Name_receive, Auth_receive);
if((g_RankBy == 1 && StrEqual(Name_receive,g_aClientName[client],false)) || (g_RankBy == 0 && StrEqual(Auth_receive,g_aClientSteam[client],false)) || (g_RankBy == 2 && StrEqual(Ip_receive,g_aClientIp[client],false))){
deaths=SQL_FetchInt(hndl,6);
if(deaths == 0)
deaths = 1;
kdr = SQL_FetchFloat(hndl,5)/deaths;
if(g_bShowRankAll){
for(new j = 1; j <= MaxClients;j++)
if(IsClientInGame(j))
CPrintToChat(j,"%s %t",MSG,"IsRankedAt", g_aClientName[client],i,g_TotalPlayers,g_aStats[client][SCORE],g_aStats[client][KILLS],g_aStats[client][DEATHS],kdr);
} else {
CPrintToChat(client,"%s %t",MSG,"IsRankedAt", g_aClientName[client],i,g_TotalPlayers,g_aStats[client][SCORE],g_aStats[client][KILLS],g_aStats[client][DEATHS],kdr);
}
break;
}
}
}