搜索
查看: 2864|回复: 3

求助此插件中的中文名字提取方法!

[复制链接]
发表于 2008-4-11 22:56:04 | 显示全部楼层 |阅读模式 来自 中国–四川–成都
我安装了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 SAYRANK  1
#define SAYTOP15 2
#define GETUNIQUEID 3
//#define PSDEBUG   
#define MAX_BUFFER_LENGTH 2047
// Global vars
new Handle:g_DbInfo
new g_psprefix[64]
new g_QueryNum
new g_Type[32]
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[64]
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[64]
new psuser[64]
new pspass[64]
new psdb[64]
new query[1024]
new data[3]

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[0] = g_QueryNum
data[1] = GETUNIQUEID
data[2] = 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[2048]

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[32]
new iKills, iDeaths, iHits, iShots, iHeadshotkills
new Float:fSkill, Float:fAccuracy, Float:fOnlinetime

new iLen = 0
new sBuffer[MAX_BUFFER_LENGTH + 1]
        new lKills[16], lDeaths[16], lHits[16], lShots[16], lSkill[16], lAcc[16], lOnline[16]
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[iLen], 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[iLen], 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[0], data[1], data[2], 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[1024]
  SQL_GetQueryString(query, querystring, 1023)
  log_amx(" --> Original query: %s", querystring)
} else {
  if (data[1] == SAYRANK) {
      PrintRankData(query, data[2])
  }
  else if (data[1] == SAYTOP15) {
      PrintTop15Data(query, data[2])
  }
  else if (data[1] == 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[1024]
new data[3]
new uniqueid[32]

data[0] = g_QueryNum
data[1] = SAYRANK
data[2] = 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[1024]
new data[3]
data[0] = g_QueryNum
data[1] = SAYTOP15
data[2] = 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[charnum] ,len,"'","\'") != 0)
    {
charnum += contain(string[charnum],"\'") + 2;
    }
     
    charnum = 0;
    while ( replace( string[charnum] ,len,"`","\`") != 0)
    {
charnum += contain(string[charnum],"\`") + 2;
    }
}
     
public plugin_end()
{
SQL_FreeHandle(g_DbInfo)
}

原插件地址:http://forums.alliedmods.net/showthread.php?t=61665
发表于 2008-4-15 13:15:47 | 显示全部楼层 来自 中国–广西–南宁

回复: 求助此插件中的中文名字提取方法!

用美化版的 排名
可以显示啊!
回复

使用道具 举报

发表于 2008-4-15 13:26:17 | 显示全部楼层 来自 中国–黑龙江–哈尔滨

回复: 求助此插件中的中文名字提取方法!

好厉害:sweat: :sweat:
回复

使用道具 举报

 楼主| 发表于 2008-4-15 18:32:23 | 显示全部楼层 来自 中国–四川–宜宾

回复: 求助此插件中的中文名字提取方法!

Post by qqoo
用美化版的 排名
可以显示啊!
我指的是在服务器里面使用/rank和/top15来显示PS3排名,而不是AMXX自带的TOP排行!
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表