Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <sqlx>
#include <colorchat>
new DB_HOST[] = " "
new DB_USER[] = " "
new DB_PASS[] = " "
new DB_NAME[] = " "
new DB_TABLE[] = "xp_mod"
new g_sBuffer[2048]
new g_sTopStyle[] = "<meta charset=UTF-8><style type=^"text/css^">table{color:#fff;}th{color:#7f1;}th,td{text-align:left;width:200px;}.p{text-align:right;width:45px;padding-right:15px;}</style>"
#pragma compress 1
#define MAX_LEVELS 20
#define MAX_CLASSES 20
#define MAX_POINT 52428800
#define MAX_PLAYERS 32
enum dataStruct { sqlModule[6], Handle:sqlTuple, Handle:sqlConnection }
new gData[dataStruct];
new query[512];
new PlayerXP[33],PlayerLevel[33],PlayerClass[33]
//These are for your special kills
new XP_Kill,XP_Knife,XP_Hs,XP_he,XP_suicide,XP_ttwin,XP_ctwin,XP_ttlose,XP_ctlose,XP_perhour,XP_death
new const CLASSES[MAX_CLASSES][] =
{
"None",
"Newbie",
"Begineer",
"Begineer II",
"Marshall",
"Undercover Agent",
"Professional",
"Ninja",
"Shadow Strikers",
"United King",
"King Kong",
"Eternal Alliance",
"United Heros",
"Godfather",
"Avengers",
"Gold Nova",
"Gold Nova II",
"Gold Nova III",
"Master Guardian",
"Master Guardian Elite"
}
new const LEVELS[MAX_LEVELS] =
{
100,
200,
400,
800,
1600,
3200,
6400,
12800,
25600,
51200,
102400,
204800,
409600,
819800,
1638400,
3276800,
6553600,
13107200,
26214400,
52428800
}
public plugin_init()
{
register_plugin("PoInT mOd", "1.0", "Thelius, soumyadip77")
register_event("DeathMsg", "eDeath", "a")
XP_Kill = register_cvar("advance_kill", "1")
XP_Hs = register_cvar("advance_hs", "3")
XP_he = register_cvar("advance_hs", "2")
XP_suicide = register_cvar("advance_hs", "2")
XP_Knife = register_cvar("advance_knife", "2")
XP_perhour = register_cvar("advance_knife", "50")
XP_death = register_cvar("advance_death", "1")
register_event( "SendAudio", "TerroristsWin", "a", "2=%!MRAD_terwin" )
register_event( "SendAudio", "CounterTerroristsWin", "a", "2=%!MRAD_ctwin" )
register_concmd("amx_top", "fwTop")
register_concmd("say /top", "fwTop")
register_concmd("say top15", "fwTop")
register_concmd("say /top15", "fwTop")
register_concmd("say /points", "stats")
register_concmd("say points", "stats")
db_connect();
}
stock db_connect() {
gData[sqlModule]="mysql";
new buffer[128];
if(is_module_loaded(gData[sqlModule])<0)
{
formatex(buffer,charsmax(buffer),"^r^n[SQL] Error: module ^"%s^" not loaded.^r^n", gData[sqlModule]);
log_amx(buffer);
set_fail_state(buffer);
return;
}
SQL_GetAffinity(buffer, charsmax(buffer));
if(!equali(buffer, gData[sqlModule]))
if(!SQL_SetAffinity(gData[sqlModule])) {
formatex(buffer,charsmax(buffer),"%s Failed to set ^"%s^" affinity!", gData[sqlModule]);
log_amx(buffer);
set_fail_state(buffer);
return;
}
new err[256],errNum;
gData[sqlTuple] = _:SQL_MakeDbTuple(DB_HOST, DB_USER, DB_PASS, DB_NAME);
gData[sqlConnection] = _:SQL_Connect(gData[sqlTuple], errNum, err, charsmax(err));
if(gData[sqlTuple]==Empty_Handle || gData[sqlConnection]==Empty_Handle) {
formatex(buffer,charsmax(buffer),"[SQL] MySQL Error #%d - %s..", errNum, err);
log_amx(buffer);
set_fail_state(buffer);
}
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler","SET NAMES utf8","charset",10);
server_print("[SQL] connected to: '%s://%s:****@%s/%s/%s'", gData[sqlModule], DB_USER, DB_HOST, DB_NAME, DB_TABLE);
formatex(query,charsmax(query),"CREATE TABLE IF NOT EXISTS %s (id BIGINT NOT NULL %s PRIMARY KEY, name VARCHAR(64) NOT NULL, authid VARCHAR(32) NOT NULL UNIQUE, ip VARCHAR(20) NOT NULL, level INT NOT NULL DEFAULT 0, xp INT NOT NULL DEFAULT 0 )%s",DB_TABLE,(equali(gData[sqlModule], "mysql"))?"AUTO_INCREMENT":"DEFAULT 0",(equali(gData[sqlModule], "mysql"))?" ENGINE=MyISAM DEFAULT CHARSET=utf8;":"");
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"create",10);
}
public eDeath(id)
{
new headshot,attacker = read_data( 1 )
new iVictim = read_data( 2 );
new weapon = get_user_weapon(attacker,headshot,headshot)
headshot = read_data( 3 )
if(attacker != iVictim && weapon != CSW_HEGRENADE && weapon != CSW_KNIFE && !headshot)
{
PlayerXP[attacker] += get_pcvar_num(XP_Kill)
PlayerXP[iVictim] -= get_pcvar_num(XP_death)
ColorChat(iVictim, GREY, "^4||[G]O[D]|| ^1You Lost ^3(-%d)^1 Point For ^4DEATH", get_pcvar_num(XP_death))
ColorChat(attacker, GREY, "^4||[G]O[D]|| ^1You Get ^3(+%d)^1 Point For ^4KILL", get_pcvar_num(XP_Kill))
}
if(attacker != iVictim && headshot)
{
PlayerXP[attacker] += get_pcvar_num(XP_Hs)
PlayerXP[iVictim] -= get_pcvar_num(XP_death)
ColorChat(iVictim, GREY, "^4||[G]O[D]|| ^1You Lost ^3(-%d)^1 Point For ^4DEATH", get_pcvar_num(XP_death))
ColorChat(attacker, GREY, "^4||[G]O[D]|| ^1You Get ^3(+%d)^1 Point For ^4HEADSHOT", get_pcvar_num(XP_Hs))
}
if(attacker != iVictim && weapon == CSW_KNIFE)
{
PlayerXP[attacker] += get_pcvar_num(XP_Knife)
PlayerXP[iVictim] -= get_pcvar_num(XP_death)
ColorChat(iVictim, GREY, "^4||[G]O[D]|| ^1You Lost ^3(-%d)^1 Point For ^4DEATH", get_pcvar_num(XP_death))
ColorChat(attacker, GREY, "^4||[G]O[D]|| ^1You Get ^3(+%d)^1 Point For Kill With ^4KNIFE", get_pcvar_num(XP_Knife))
}
if(weapon == CSW_HEGRENADE && attacker != iVictim)
{
PlayerXP[attacker] += get_pcvar_num(XP_he)
PlayerXP[iVictim] -= get_pcvar_num(XP_death)
ColorChat(iVictim, GREY, "^4||[G]O[D]|| ^1You Lost ^3(-%d)^1 Point For ^4DEATH", get_pcvar_num(XP_death))
ColorChat(attacker, GREY, "^4||[G]O[D]|| ^1You Get ^3(+%d)^1 Point For Kill With ^4GRENADE", get_pcvar_num(XP_he))
}
if(attacker == iVictim)
{
PlayerXP[attacker] -= get_pcvar_num(XP_suicide)
ColorChat(attacker, GREY, "^4||[G]O[D]|| ^1You Lost ^3(-%d)^1 Point For ^4SUICIDE", get_pcvar_num(XP_suicide))
}
while(PlayerXP[attacker] >= LEVELS[PlayerLevel[attacker]])
{
new lvlup[32]
get_user_name(attacker, lvlup, charsmax(lvlup))
ColorChat(attacker, GREY, "^4*^3Congratulations ^1You Are Now ^3LEVEL^1 [^4 %i ^1] ^3CLASS^1 [^4 %s ^1]", PlayerLevel[attacker], CLASSES[ PlayerLevel[attacker] ]);
ColorChat(0, GREY, "^4||[G]O[D]|| ^1%s ^3LEVEL Up To^1 [^4 %i ^1] ^3CLASS^1 [^4 %s ^1]", lvlup, PlayerLevel[attacker], CLASSES[ PlayerLevel[attacker] ]);
PlayerLevel[attacker] += 1
}
SaveData(attacker)
}
public TerroristsWin( )
{
new Players[ MAX_PLAYERS ]
new iNum
new i
get_players( Players, iNum, "ch" )
for( --iNum; iNum >= 0; iNum-- )
{
i = Players[ iNum ]
switch( cs_get_user_team( i ) )
{
case( CS_TEAM_T ):
{
PlayerXP[ i ] += get_pcvar_num(XP_ttwin)
ColorChat( i,GREY, "^4||[G]O[D]|| ^1Your Team Terrorist Got (+%d) Point For Win This Round", get_pcvar_num(XP_ttwin))
}
case( CS_TEAM_CT ):
{
PlayerXP[ i ] -= get_pcvar_num(XP_ctlose)
ColorChat( i,GREY ,"^4||[G]O[D]|| ^1Your Team Counter-Terrorist Lost (-%d) Point For Losing This Round", get_pcvar_num(XP_ctlose))
}
}
}
return PLUGIN_CONTINUE
}
public CounterTerroristsWin( )
{
new Players[ MAX_PLAYERS ]
new iNum
new i
get_players( Players, iNum, "ch" )
for( --iNum; iNum >= 0; iNum-- )
{
i = Players[ iNum ]
switch( cs_get_user_team( i ) )
{
case( CS_TEAM_T ):
{
PlayerXP[ i ] -= get_pcvar_num(XP_ttlose)
ColorChat( i, GREY,"^4||[G]O[D]|| ^1Your Team Counter-Terrorist Lost (-%d) Point For Losing This Round", get_pcvar_num(XP_ttlose))
}
case( CS_TEAM_CT ):
{
PlayerXP[ i ] += get_pcvar_num(XP_ctwin)
ColorChat( i, GREY,"^4||[G]O[D]|| ^1Your Team Counter-Terrorist Got (+%d) Point For Win This Round", get_pcvar_num(XP_ctwin))
}
}
}
return PLUGIN_CONTINUE
}
public stats(id)
{
ColorChat(id, GREY, "^4||[G]O[D]|| ^1Your Total ^3Experience Point ^1[^4 %i ^1] ^3LEVEL ^1[^4 %i ^1] ^3CLASS ^1[^4 %s ^1]",PlayerXP[id], PlayerLevel[id], CLASSES[ PlayerLevel [id] ])
}
public client_authorized(id)
{
LoadData(id)
set_task( 3600.0, "GiveSkillPointsHour", id, _, _, "b" )
}
public GiveSkillPointsHour( id )
{
PlayerXP[id] += get_pcvar_num(XP_perhour)
ColorChat(id, GREY, "^4||[G]O[D]|| ^1You Got ^3(+%d)^1 Point For Play On Server 1 Hour", get_pcvar_num(XP_perhour))
set_task( 3600.0, "GiveSkillPointsHour", id, _, _, "b" )
}
public client_disconnected(id)
{
SaveData(id)
PlayerXP[id] = 0
PlayerLevel[id] = 0
PlayerClass[id] = 0
}
public SaveData(id)
{
static AuthID[32]
get_user_authid(id,AuthID,31)
SaveSqlData(id,AuthID);
}
public LoadData(id)
{
static AuthID[32]
get_user_authid(id,AuthID,31)
LoadSqlData(id,AuthID);
}
public QueryHandler(failState, Handle:queryH, err[], errNum, data[], data_size) {
if(failState==TQUERY_CONNECT_FAILED || failState==TQUERY_QUERY_FAILED || errNum) {
log_amx("[SQL] MySQL Error #%d - %s", errNum, err);
return;
}
if(equali(data,"update")||equali(data,"insert")||equali(data,"charset")||equali(data,"create"))
return;
new id = data[0];
new rows = SQL_NumResults(queryH);
if(!rows) {
static query[512], name[64], ip[20];
get_user_name(id,name,charsmax(name));
clear(name);
get_user_ip(id,ip,charsmax(ip),1);
formatex(query,charsmax(query),"REPLACE INTO %s (name,authid,ip,xp,level) VALUES('%s','%s','%s','%d','%d')",DB_TABLE,name,data[1],ip,PlayerXP[id],PlayerLevel[id]);
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"insert",10);
return;
}
PlayerXP[id] = SQL_ReadResult(queryH,SQL_FieldNameToNum(queryH, "xp"));
PlayerLevel[id] = SQL_ReadResult(queryH,SQL_FieldNameToNum(queryH, "level"));
}
public plugin_end()
sql_close();
//----- Stocks ------
stock szName( const index )
{
static Name[ 128 ];
get_user_name( index, Name, charsmax( Name ) );
return Name;
}
stock LoadSqlData(id, const AuthID[])
{
static data[32], query[128];
data[0]=id;
copy(data[1],30,AuthID);
formatex(query,charsmax(query),"SELECT * FROM %s WHERE authid = '%s'",DB_TABLE, AuthID);
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,data,sizeof(data));
}
stock clear(src[])
{
new len=strlen(src);
replace_all(src, len, "\", "\\");
replace_all(src, len, "'", "\'");
replace_all(src, len, "^"", "\^"");
replace_all(src, len, "^n", "\^n");
replace_all(src, len, "^r", "\^n");
replace_all(src, len, "^x1A", "\^x1A");
replace_all(src, len, "^x00", "\^x00");
}
stock sql_close()
{
if(gData[sqlTuple] != Empty_Handle)
SQL_FreeHandle(gData[sqlTuple] );
if(gData[sqlConnection] != Empty_Handle)
SQL_FreeHandle(gData[sqlConnection]);
}
stock SaveSqlData(id, const AuthID[])
{
static query[256], name[64];
if(PlayerXP[id] || PlayerLevel[id])
{
get_user_name(id,name,charsmax(name));
formatex(query,charsmax(query),"UPDATE %s SET name='%s', xp='%d', level='%d' WHERE authid='%s'",DB_TABLE,name,PlayerXP[id],PlayerLevel[id],AuthID);
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"update",10);
}
}
public fwTop(id)
{
new szTemp[512]
new Data[1]; Data[0] = id
format( szTemp,charsmax(szTemp),"SELECT * FROM `xp_mod` ORDER BY (xp) DESC LIMIT 0,15" )
SQL_ThreadQuery( gData[sqlTuple], "fwFormatTop", szTemp, Data, 1 )
return PLUGIN_HANDLED
}
public fwFormatTop( FailState, Handle:Query, Error[], Errcode,Data[], DataSize )
{
if(FailState == TQUERY_CONNECT_FAILED)
log_amx("Load - Could not connect to SQL database. [%d] %s", Errcode, Error)
else if(FailState == TQUERY_QUERY_FAILED)
log_amx("Load Query failed. [%d] %s", Errcode, Error)
new id; id = Data[0]
new rows1 = SQL_NumResults(Query)
new iLevel[15], iExperience[15], szName[15][64]
if( SQL_MoreResults(Query) )
{
for(new i = 0 ; i < rows1 ; i++)
{
SQL_ReadResult( Query, 1, szName[i], 63 )
iLevel[i] = SQL_ReadResult(Query, 3)
iExperience[i] = SQL_ReadResult(Query, 5)
SQL_NextRow(Query)
}
}
if(rows1 > 0)
{
new iLen=0;
iLen = format( g_sBuffer[iLen], 2047, g_sTopStyle )
iLen += format( g_sBuffer[iLen], 2047 - iLen, "<body bgcolor=#000000><table border=0 cellspacing=0 cellpadding=3px><tr><th class=p>#<td class=p><th>Player<th>XP<th>Level" )
for(new i = 0 ; i < rows1 ; i++)
{
replace_all( szName[i], 63, "&", "&" )
replace_all( szName[i], 63, "<", "<" )
replace_all( szName[i], 63, ">", ">" )
iLen += format( g_sBuffer[iLen], 2047 - iLen, "<tr><td class=p>%d<td class=p><td>%s<td>%i<td>%i", i + 1, szName[i], iExperience[i], iLevel[i] )
}
show_motd(id, g_sBuffer, "Top15 XP")
}
return PLUGIN_HANDLED
}