求助此插件中的中文名字提取方法!
我安装了simen提供的中文ID插件以后,由于同时安装有PS3排行榜,因此想在游戏当中输入/rank和/top15来显示排名,在AMXMODX论坛当中找到了相应的插件,按照simen提供的方法修改了get_user_name为get_name,但在游戏当中使用的时候,发现英文名字能够显示排名,但中文名字则始终提示没有排名,能帮我看看是哪里出了问题吗?源码如下:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#define PLUGIN "PS3 - stats rank top15"
#define VERSION "1.0"
#define AUTHOR "GeroiN"
#define SAYRANK1
#define SAYTOP15 2
#define GETUNIQUEID 3
//#define PSDEBUG
#define MAX_BUFFER_LENGTH 2047
// Global vars
new Handle:g_DbInfo
new g_psprefix
new g_QueryNum
new g_Type
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("ps3stats.txt")
register_cvar("amx_sql_pshost", "127.0.0.1")
register_cvar("amx_sql_psuser", "psychostats")
register_cvar("amx_sql_pspass", "hidden")
register_cvar("amx_sql_psdb", "ps3")
register_cvar("amx_sql_psprefix", "ps_")
register_clcmd("say /rank", "handle_rank", 0, "- display your rank from Psychostats")
register_clcmd("say_team /rank", "handle_rank", 0, "- display your rank from Psychostats")
register_clcmd("say /top15", "handle_top15", 0, "- display top 15 players from Psychostats")
register_clcmd("say_team /top15", "handle_top15", 0, "- display top 15 players from Psychostats")
new configsDir
get_configsdir(configsDir, 63)
server_cmd("exec %s/sql.cfg", configsDir)
server_exec()// helps to load sql.cfg if mapchange only
}
public plugin_cfg()
{
new pshost
new psuser
new pspass
new psdb
new query
new data
get_cvar_string("amx_sql_pshost", pshost, 63)
get_cvar_string("amx_sql_psuser", psuser, 63)
get_cvar_string("amx_sql_pspass", pspass, 63)
get_cvar_string("amx_sql_psdb", psdb, 63)
get_cvar_string("amx_sql_psprefix", g_psprefix, 63)
g_DbInfo = SQL_MakeDbTuple(pshost, psuser, pspass, psdb)
format(query, 1024, "SELECT value FROM %sconfig WHERE var = 'uniqueid' LIMIT 1",
g_psprefix)
#if defined PSDEBUG
log_amx("Adding to %d queue at: %f", g_QueryNum, get_gametime())
#endif
data = g_QueryNum
data = GETUNIQUEID
data = 0
SQL_ThreadQuery(g_DbInfo, "GetMyStuff", query, data, 3)
g_QueryNum++
}
public debug_sql_thread(Handle:query)
{
#if defined PSDEBUG
new columns = SQL_NumColumns(query)
new rows = SQL_NumResults(query)
static querystring
SQL_GetQueryString(query, querystring, 2047)
log_amx("Original query string: %s", querystring)
log_amx("Query columns: %d rows: %d", columns, rows)
#endif
}
public SaveUniqueId(Handle:query)
{
debug_sql_thread(query)
if (SQL_MoreResults(query))
SQL_ReadResult(query, 0, g_Type, 31)
else
log_amx("Error in Psychostats DB. Can't get uniqueid type.")
}
public PrintRankData(Handle:query, id)
{
new iRank, iRanked
new iKills, iDeaths, iHits
new Float:fSkill, Float:fAccuracy
debug_sql_thread(query)
if (SQL_MoreResults(query))
{
iRank = SQL_ReadResult(query, 0)
iRanked = SQL_ReadResult(query, 1)
iKills = SQL_ReadResult(query, 2)
iDeaths = SQL_ReadResult(query, 3)
iHits = SQL_ReadResult(query, 4)
SQL_ReadResult(query, 5, fSkill)
SQL_ReadResult(query, 6, fAccuracy)
client_print(id, print_chat, "* %L", id, "YOUR_PS_RANK_IS", iRank, iRanked, iKills, iDeaths, iHits, fSkill, fAccuracy)
#if defined PSDEBUG
log_amx("* %L", id, "YOUR_PS_RANK_IS", iRank, iRanked, iKills, iDeaths, iHits, fSkill, fAccuracy)
#endif
}
else
{
client_print(id, print_chat, "* %L", id, "YOU_RE_NOT_RANKED")
#if defined PSDEBUG
log_amx("* %L", id, "YOU_RE_NOT_RANKED")
#endif
}
}
public PrintTop15Data(Handle:query, id)
{
new iRank
new sName
new iKills, iDeaths, iHits, iShots, iHeadshotkills
new Float:fSkill, Float:fAccuracy, Float:fOnlinetime
new iLen = 0
new sBuffer
new lKills, lDeaths, lHits, lShots, lSkill, lAcc, lOnline
debug_sql_thread(query)
format(lKills, 15, "%L", LANG_SERVER, "PSKILLS")
format(lDeaths, 15, "%L", LANG_SERVER, "PSDEATHS")
format(lHits, 15, "%L", LANG_SERVER, "PSHITS")
format(lShots, 15, "%L", LANG_SERVER, "PSSHOTS")
format(lSkill, 15, "%L", LANG_SERVER, "PSSKILL")
format(lAcc, 15, "%L", LANG_SERVER, "PSACC")
format(lOnline, 15, "%L", LANG_SERVER, "PSONLINE")
iLen = format(sBuffer, MAX_BUFFER_LENGTH, "<body bgcolor=#000000><font color=#FFB000><pre>")
iLen += format(sBuffer, MAX_BUFFER_LENGTH - iLen, "%2s %-22.22s %6s %6s %6s %6s %4s %4s %4s %4s^n", "#", "Nick", lKills, lDeaths, lHits, lShots, "HS", lSkill, lAcc, lOnline)
while ((SQL_MoreResults(query)) && (MAX_BUFFER_LENGTH - iLen > 0))
{
iRank = SQL_ReadResult(query, 0)
SQL_ReadResult(query, 1, sName, 31)
iKills = SQL_ReadResult(query, 2)
iDeaths = SQL_ReadResult(query, 3)
iHits = SQL_ReadResult(query, 4)
iShots = SQL_ReadResult(query, 5)
iHeadshotkills = SQL_ReadResult(query, 6)
SQL_ReadResult(query, 7, fSkill)
SQL_ReadResult(query, 8, fAccuracy)
SQL_ReadResult(query, 9, fOnlinetime)
iLen += format(sBuffer, MAX_BUFFER_LENGTH - iLen, "%2d %-22.22s %6d %6d %6d %6d %4d %3.0f% %3.0f%% %3.0fh^n", iRank, sName, iKills,
iDeaths, iHits, iShots, iHeadshotkills, fSkill, fAccuracy, fOnlinetime)
SQL_NextRow(query)
}
show_motd(id, sBuffer, "Top 15")
#if defined PSDEBUG
log_amx(sBuffer)
#endif
}
/**
* Handler for when a threaded query is resolved.
*/
public GetMyStuff(failstate, Handle:query, error[], errnum, data[], size, Float:queuetime)
{
log_amx(" --> Resolved query %d %d %d, took %f seconds", data, data, data, queuetime)
if (failstate)
{
if (failstate == TQUERY_CONNECT_FAILED)
{
log_amx(" --> Connection failed!")
} else if (failstate == TQUERY_QUERY_FAILED) {
log_amx(" --> Query failed!")
}
log_amx(" --> Error code: %d (Message: ^"%s^")", errnum, error)
new querystring
SQL_GetQueryString(query, querystring, 1023)
log_amx(" --> Original query: %s", querystring)
} else {
if (data == SAYRANK) {
PrintRankData(query, data)
}
else if (data == SAYTOP15) {
PrintTop15Data(query, data)
}
else if (data == GETUNIQUEID) {
SaveUniqueId(query)
}
}
}
public get_user_unique_id(id, type[], uniqueid[], len)
{
if (equal(type, "name"))
get_user_name(id, uniqueid, len)
else if (equal(type, "steamid") || equal(type, "worldid"))
get_user_authid(id, uniqueid, len)
else if (equal(type, "ipaddr"))
get_user_ip(id, uniqueid, len)
else
log_amx(" --> Error at get_user_unique_id; 'type' = '%s'", type)
}
/**
* Handles "say /rank"
*/
public handle_rank(id)
{
new query
new data
new uniqueid
data = g_QueryNum
data = SAYRANK
data = id
get_user_unique_id(id, g_Type, uniqueid, 31)
quote_sql(uniqueid, 31);
format(query, 1024, "SELECT plr.rank, (SELECT COUNT( * ) FROM %splr plr WHERE plr.allowrank = 1) AS ranked, d.kills, d.deaths, d.hits, plr.skill, d.accuracy FROM %sc_plr_data as d, %splr as plr, %splr_profile as pp WHERE plr.plrid=d.plrid AND plr.uniqueid=pp.uniqueid AND pp.uniqueid='%s' AND plr.rank > 0 AND plr.allowrank = 1 ORDER BY plr.rank ASC LIMIT 1",
g_psprefix, g_psprefix, g_psprefix, g_psprefix, uniqueid)
#if defined PSDEBUG
log_amx("Adding to %d queue at: %f", g_QueryNum, get_gametime())
#endif
SQL_ThreadQuery(g_DbInfo, "GetMyStuff", query, data, 3)
g_QueryNum++
return PLUGIN_CONTINUE
}
/**
* Handles "say /top15"
*/
public handle_top15(id)
{
new query
new data
data = g_QueryNum
data = SAYTOP15
data = id
format(query, 1024, "SELECT plr.rank, REPLACE(REPLACE(pp.name, '<', '['), '>', ']') as name, d.kills, d.deaths, d.hits, d.shots, d.headshotkills, plr.skill, d.accuracy, ROUND(d.onlinetime / 3600, 1) as onlinetime FROM %sc_plr_data as d, %splr as plr, %splr_profile as pp WHERE plr.plrid=d.plrid AND plr.uniqueid=pp.uniqueid AND plr.rank > 0 AND plr.allowrank = 1 ORDER BY plr.rank ASC LIMIT 15",
g_psprefix, g_psprefix, g_psprefix)
#if defined PSDEBUG
log_amx("Adding to %d queue at: %f", g_QueryNum, get_gametime())
#endif
SQL_ThreadQuery(g_DbInfo, "GetMyStuff", query, data, 3)
g_QueryNum++
return PLUGIN_CONTINUE
}
// quotes the string given to be used safely in a mysql_query() call
public quote_sql(string[],len) {
new charnum = 0;
while ( replace( string ,len,"'","\'") != 0)
{
charnum += contain(string,"\'") + 2;
}
charnum = 0;
while ( replace( string ,len,"`","\`") != 0)
{
charnum += contain(string,"\`") + 2;
}
}
public plugin_end()
{
SQL_FreeHandle(g_DbInfo)
}
原插件地址:http://forums.alliedmods.net/showthread.php?t=61665
回复: 求助此插件中的中文名字提取方法!
用美化版的 排名可以显示啊!
回复: 求助此插件中的中文名字提取方法!
好厉害:sweat: :sweat:回复: 求助此插件中的中文名字提取方法!
Post by qqoo用美化版的 排名
可以显示啊!
我指的是在服务器里面使用/rank和/top15来显示PS3排名,而不是AMXX自带的TOP排行!
页:
[1]