PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <fakemeta>
#include <cstrike>
#define PLUGIN "Custom Rang Info"
#define VERSION "1.0.3"
#define AUTHOR "Kia"
// ===============================================================================
// Editing begins here
// ===============================================================================
// Add SQL Data here
new Host[] = ""
new User[] = ""
new Pass[] = ""
new Db[] = ""
// ===============================================================================
// and stops here. DO NOT MODIFY BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
// ===============================================================================
// ===============================================================================
// Variables
// ===============================================================================
/* Booleans */
new bool:iStart[33];
new bool:g_authed[33]
new bool:g_sql_ready = false
new bool:g_loaded[33]
new bool:g_bHasRank[33]
/* Handler */
new Handle:g_SqlConnection
new Handle:g_SqlTuple
/* Strings */
new g_Error[512]
new g_szOldName[33][33]
new g_szRank[33][64]
/* Integer */
new maxplayers;
/* Pointer */
new g_pHookSay
// ===============================================================================
// plugin_init
// ===============================================================================
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
/* SQL */
maxplayers = get_maxplayers()
set_task(0.1, "MySql_Init")
/* CVars */
g_pHookSay = register_cvar("cri_hooksay", "1")
/* ClCmds */
register_clcmd("say", "ClCmd_Say")
register_clcmd("say_team", "ClCmd_SayTeam")
}
// ===============================================================================
// client_authorized - Called when a player joins the Server
// ===============================================================================
public client_authorized(id)
{
g_authed[id] = true
g_bHasRank[id] = false
g_szOldName[id][0] = EOS
g_szRank[id][0] = EOS
Load_MySql(id)
}
// ===============================================================================
// client_disconnect - Called when a player leaves the Server
// ===============================================================================
public client_disconnect(id)
{
g_szOldName[id][0] = EOS
g_szRank[id][0] = EOS
iStart[id] = false
g_bHasRank[id] = false
}
// ===============================================================================
// ClCmd_Say - Called when someone types something in the public chat
// ===============================================================================
public ClCmd_Say(id)
{
new iMode = get_pcvar_num(g_pHookSay)
new szMsg[500]
read_args(szMsg, charsmax(szMsg))
remove_quotes(szMsg)
if(!szMsg[0] || iMode <= 0)
return PLUGIN_HANDLED
else if(iMode == 1)
print_color(0, id, 0, "%s^x03%s ^x01: %s", is_user_alive(id) ? "" : "^x01*DEAD* ", g_szOldName[id], szMsg)
else if(iMode == 2)
print_color(0, id, 0, "%s^x04[%s] ^x03%s ^x01: %s", is_user_alive(id) ? "" : "^x01*DEAD* ", g_szRank[id], g_szOldName[id], szMsg)
return PLUGIN_HANDLED
}
// ===============================================================================
// ClCmd_SayTeam - Called when someone types something in the Team Chat
// ===============================================================================
public ClCmd_SayTeam(id)
{
new iMode = get_pcvar_num(g_pHookSay)
new szMsg[500]
read_args(szMsg, charsmax(szMsg))
remove_quotes(szMsg)
if(!szMsg[0] || iMode <= 0)
return PLUGIN_HANDLED
new players[32], pnum, tempid
get_players(players, pnum, "e", cs_get_user_team(id) == CS_TEAM_CT ? "CT" : "TERRORIST")
for( new i; i<pnum; i++ )
{
tempid = players[i]
if(iMode == 1)
print_color(tempid, id, 0, "%s^x03%s ^x01(Team) : %s", is_user_alive(id) ? "" : "^x01*DEAD* ", g_szOldName[id], szMsg)
else if(iMode == 2)
print_color(tempid, id, 0, "%s^x04[%s] ^x03%s ^x01(Team) : %s", is_user_alive(id) ? "" : "^x01*DEAD* ", g_szRank[id], g_szOldName[id], szMsg)
}
return PLUGIN_HANDLED
}
// ===============================================================================
// ColorChat
// ===============================================================================
public print_color(id, cid, color, const message[], any:...)
{
new msg[192]
vformat(msg, charsmax(msg), message, 5)
/* //if you want to use ML, enable
replace_all(msg, charsmax(msg), "!g", "^x04")
replace_all(msg, charsmax(msg), "!n", "^x01")
replace_all(msg, charsmax(msg), "!t", "^x03")*/
new param
if (!cid) return
else param = cid
new team[32]
get_user_team(param, team, 31)
switch (color)
{
case 0: msg_teaminfo(param, team)
case 1: msg_teaminfo(param, "TERRORIST")
case 2: msg_teaminfo(param, "CT")
case 3: msg_teaminfo(param, "SPECTATOR")
}
if (id) msg_saytext(id, param, msg)
else msg_saytext(0, param, msg)
if (color != 0) msg_teaminfo(param, team)
}
msg_saytext(id, cid, msg[])
{
message_begin(id?MSG_ONE:MSG_ALL, get_user_msgid("SayText"), {0,0,0}, id)
write_byte(cid)
write_string(msg)
message_end()
}
msg_teaminfo(id, team[])
{
message_begin(MSG_ONE, get_user_msgid("TeamInfo"), {0,0,0}, id)
write_byte(id)
write_string(team)
message_end()
}
// ===============================================================================
// SetRank
// ===============================================================================
public SetRank(id)
{
get_user_name(id, g_szOldName[id], charsmax(g_szOldName))
new szName[33]
formatex(szName, charsmax(szName), "%s^n%s", g_szOldName[id], g_szRank[id])
set_user_info(id, "name", szName)
}
// ===============================================================================
// SQL
// ===============================================================================
public MySql_Init()
{
// we tell the API that this is the information we want to connect to,
// just not yet. basically it's like storing it in global variables
g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)
// ok, we're ready to connect
new ErrorCode
g_SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
if(g_SqlConnection == Empty_Handle)
{
// stop the plugin with an error message
set_fail_state(g_Error)
}
new Handle:Queries
// we must now prepare some random queries
Queries = SQL_PrepareQuery(g_SqlConnection,"CREATE TABLE IF NOT EXISTS cri_ranks (steamid varchar(32), rank varchar(64))")
if(!SQL_Execute(Queries))
{
// if there were any problems
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
set_fail_state(g_Error)
}
// close the handle
SQL_FreeHandle(Queries)
g_sql_ready = true
for(new i=1; i<=maxplayers; i++)
{
if(g_authed[i])
{
Load_MySql(i)
}
}
}
public Load_MySql(id)
{
if(g_sql_ready)
{
if(g_SqlTuple == Empty_Handle)
{
set_fail_state(g_Error)
}
new szSteamId[32], szTemp[512]
get_user_authid(id, szSteamId, charsmax(szSteamId))
new Data[1]
Data[0] = id
//we will now select from the table `furienmoney` where the steamid match
format(szTemp,charsmax(szTemp),"SELECT `rank` FROM `cri_ranks` WHERE (`cri_ranks`.`steamid` = '%s')", szSteamId)
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}
}
public register_client(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]
if(SQL_NumResults(Query) >= 1)
{
SQL_ReadResult(Query, 0, g_szRank[id], charsmax(g_szRank))
g_bHasRank[id] = true
new szAuthID[33]
get_user_authid(id, szAuthID, charsmax(szAuthID))
log_to_file("CustomRankInfo.txt", "Found Rank : %s for Player with Auth ID : %s", g_szRank[id], szAuthID)
SetRank(id)
}
else
{
g_bHasRank[id] = false
get_user_name(id, g_szOldName[id], charsmax(g_szOldName))
}
g_loaded[id] = true
return PLUGIN_HANDLED
}
public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
SQL_FreeHandle(Query)
return PLUGIN_HANDLED
}
public plugin_end()
{
if(g_SqlConnection != Empty_Handle)
{
SQL_FreeHandle(g_SqlConnection) //free connection handle here
}
}