/* 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.
*/
#include <amxmodx>
#include <csx>
#include <hamsandwich>
#include <nvault>
#include <chatcolor>
#define VERSION "0.3.0"
#define ENABLED_BY_DEFAULT 1
#define NVAULT_MAX_DAYS_SAVE 30
#define MAX_PLAYERS 32
#define AUTHID_LENGTH 22
#define A_DAY_IN_SECONDS 86400 // 60 * 60 * 24
new g_szSteamId[MAX_PLAYERS+1][AUTHID_LENGTH]
new g_iOldRank[MAX_PLAYERS+1]
new g_bEnabled[MAX_PLAYERS+1]
new g_iNvault
new g_pCvarInfoRank
public plugin_init()
{
register_plugin("Info Rank", VERSION, "ConnorMcLeod")
register_dictionary("inforank.txt")
g_pCvarInfoRank = register_cvar("amx_inforank", "1")
RegisterHam(Ham_Spawn, "player", "Player_Spawn_Post", 1)
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 client_authorized(id)
{
get_user_authid(id, g_szSteamId[id], charsmax(g_szSteamId[]))
if( g_szSteamId[id][0] == 'S' )
{
new mOsef[8]
g_iOldRank[id] = get_user_stats(id, mOsef, mOsef)
new szEnable[2]
nvault_get(g_iNvault, g_szSteamId[id], szEnable, charsmax(szEnable))
if(!szEnable[0])
{
g_bEnabled[id] = ENABLED_BY_DEFAULT
}
else
{
g_bEnabled[id] = str_to_num(szEnable)
}
}
}
public plugin_end()
{
nvault_close(g_iNvault)
}
public Player_Spawn_Post(id)
{
if( g_bEnabled[id]
&& is_user_alive(id)
&& get_pcvar_num(g_pCvarInfoRank) )
{
new mOsef[8], iRank, iOldRank
iRank = get_user_stats(id, mOsef, mOsef)
iOldRank = g_iOldRank[id]
if(iOldRank == 0)
{
iOldRank = iRank
}
g_iOldRank[id] = iRank
new iDiff = iOldRank - iRank
if(iDiff > 0)
{
client_print_color(id, DontChange, "%L", id, "IR_GOOD", iDiff)
}
else if(iDiff < 0)
{
client_print_color(id, Red, "%L", id, "IR_BAD", iDiff)
}
client_print_color(id, Grey, "%L", id, "IR_RANK", iRank, get_statsnum())
}
}
public ClientCommand_InfoRank(id)
{
if( get_pcvar_num(g_pCvarInfoRank) )
{
if( (g_bEnabled[id] = !g_bEnabled[id]) )
{
nvault_set(g_iNvault, g_szSteamId[id], "1")
client_print_color(id, DontChange, "%L", id, "IR_ENABLE")
}
else
{
nvault_set(g_iNvault, g_szSteamId[id], "0")
client_print_color(id, Red, "%L", id, "IR_DISABLE")
}
}
return PLUGIN_CONTINUE
}