/* Formatright © 2009, ConnorMcLeod
Info Rank is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Info Rank; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* Added Skill letter and vallue from seerfreeman`s plugin aes_statsx_cstrike */
/* Configuration */
#define ENABLED_BY_DEFAULT 1
#define NVAULT_MAX_DAYS_SAVE 10
/* DON'T CHANGE ANYTHING BELOW */
#include <amxmodx>
#include <nvault>
#include <csstatsx_sql>
// User stats parms id
#define STATS_KILLS 0
#define STATS_DEATHS 1
#define STATS_HS 2
#define STATS_TKS 3
#define STATS_SHOTS 4
#define STATS_HITS 5
#define STATS_DAMAGE 6
#if AMXX_VERSION_NUM < 183
#include <colorchat>
#define print_team_default DontChange
#define print_team_grey Grey
#define print_team_red Red
#define print_team_blue Blue
#endif
#define VERSION "0.4.5"
#define MAX_PLAYERS 32
#define A_DAY_IN_SECONDS 86400 // 60 * 60 * 24
#define CHECK_DELAY 0.5
new g_iOldRank[MAX_PLAYERS+1]
new playerbitStatsEnabled
#define EnablePlayerStats(%0) playerbitStatsEnabled |= 1<<(%0&31)
#define DisablePlayerStats(%0) playerbitStatsEnabled &= ~(1<<(%0&31))
#define ArePlayerStatsEnabled(%0) playerbitStatsEnabled & 1<<(%0&31)
#define TogglePlayerStats(%0) playerbitStatsEnabled ^= 1<<(%0&31)
new playerbitDisplayStats
//#define DisplayStatsOnNextResetHUDEvent(%0) playerbitDisplayStats |= 1<<(%0&31)
#define DontDisplayStatsOnNextResetHUDEvent(%0) playerbitDisplayStats &= ~(1<<(%0&31))
#define ShouldDisplayStatsOnNextResetHUDEvent(%0) playerbitDisplayStats & 1<<(%0&31)
new g_iEnabledByDefault = ENABLED_BY_DEFAULT
new g_iNvault
new g_pCvarInfoRank
new const g_skill_letters[][] = {
"L-",
"L",
"L+",
"M-",
"M",
"M+",
"H-",
"H",
"H+",
"P-",
"P",
"P+",
"G"
}
new Float:g_skill_opt[sizeof g_skill_letters]
public plugin_init()
{
register_plugin("Info Rank", VERSION, "ConnorMcLeod")
register_dictionary("inforank.txt")
g_pCvarInfoRank = register_cvar("amx_inforank", "1")
register_event("HLTV", "Event_HLTV_New_Round", "a", "1=0", "2=0")
register_event("ResetHUD", "Event_ResetHUD", "b")
register_clcmd("say /inforank", "ClientCommand_InfoRank", 0, "- enable/disable info rank messages")
register_clcmd("say_team /inforank", "ClientCommand_InfoRank", 0, "- enable/disable info rank messages")
g_iNvault = nvault_open("inforank")
nvault_prune(g_iNvault, 0, get_systime(-(A_DAY_IN_SECONDS * NVAULT_MAX_DAYS_SAVE)) )
}
public plugin_cfg()
{
new levelString[512],stPos,ePos,rawPoint[20],cnt
new g_pCvarSkill = get_cvar_pointer("aes_statsx_skill")
get_pcvar_string(g_pCvarSkill,levelString,charsmax(levelString))
// парсер значений для скилла
do {
ePos = strfind(levelString[stPos]," ")
formatex(rawPoint,ePos,levelString[stPos])
g_skill_opt[cnt] = str_to_float(rawPoint)
stPos += ePos + 1
cnt++
if(cnt > sizeof g_skill_letters - 1)
break
} while (ePos != -1)
}
public client_putinserver(id) {
set_task( CHECK_DELAY, "CheckStats", id ) // we need to use delay otherwise we will get rank = 0
}
public CheckStats(id)
{
if( is_user_connected(id) )
{
new szSteamId[32]
get_user_authid(id, szSteamId, charsmax(szSteamId))
if( szSteamId[0] == 'S' ) // skip bots
{
new mOsef[8]
g_iOldRank[id] = get_user_stats_sql(id, mOsef, mOsef)
new szPlayerSettings[2]
nvault_get(g_iNvault,szSteamId, szPlayerSettings, charsmax(szPlayerSettings))
switch( szPlayerSettings[0] )
{
case '0': DisablePlayerStats(id)
case '1': EnablePlayerStats(id)
default: g_iEnabledByDefault ? (EnablePlayerStats(id)) : (DisablePlayerStats(id))
}
}
else
{
DisablePlayerStats(id)
}
}
}
public plugin_end()
{
nvault_close(g_iNvault)
}
public Event_HLTV_New_Round()
{
if( get_pcvar_num(g_pCvarInfoRank) )
{
playerbitDisplayStats = 0xFFFFFFFF // set everyone enabled
}
}
public Event_ResetHUD(id)
{
if( ShouldDisplayStatsOnNextResetHUDEvent(id) && ArePlayerStatsEnabled(id) )
{
DontDisplayStatsOnNextResetHUDEvent(id)
set_task(0.3, "DisplayStats", id)
}
}
public DisplayStats(id)
{
if( is_user_connected(id) )
{
new Stats[8], BodyHits[8], iRank, iOldRank
new Float:skill, skill_id
iRank = get_user_stats_sql(id, Stats, BodyHits)
get_user_skill(id, skill)
skill_id = aes_statsx_get_skill_id(skill)
iOldRank = g_iOldRank[id]
if( iOldRank && iOldRank != iRank )
{
g_iOldRank[id] = iRank
iOldRank - iRank > 0 ? client_print_color(id, print_team_blue, "%L", id, "IR_GOOD", iRank, get_statsnum_sql(), Stats[STATS_KILLS], Stats[STATS_DEATHS], g_skill_letters[skill_id], skill)
: client_print_color(id, print_team_red, "%L", id, "IR_BAD", iRank, get_statsnum_sql(), Stats[STATS_KILLS], Stats[STATS_DEATHS], g_skill_letters[skill_id], skill);
}
else
client_print_color(id, print_team_blue, "%L", id, "IR_RANK", iRank, get_statsnum_sql(), Stats[STATS_KILLS], Stats[STATS_DEATHS], g_skill_letters[skill_id], skill)
}
}
aes_statsx_get_skill_id(Float:skill)
{
for(new i ; i < sizeof g_skill_opt ; i++)
{
if(skill < g_skill_opt[i])
{
return i
}
}
return (sizeof g_skill_opt - 1)
}
public ClientCommand_InfoRank(id)
{
if( get_pcvar_num(g_pCvarInfoRank) )
{
new szSteamId[32]
get_user_authid(id, szSteamId, charsmax(szSteamId))
TogglePlayerStats(id)
if( ArePlayerStatsEnabled(id) )
{
nvault_set(g_iNvault, szSteamId, "1")
client_print_color(id, id, "^4%L", id, "IR_ENABLE")
}
else
{
nvault_set(g_iNvault, szSteamId, "0")
client_print_color(id, print_team_red, "^3%L", id, "IR_DISABLE")
}
}
return PLUGIN_CONTINUE
}