|
发表于 2009-9-29 22:03:49
|
显示全部楼层
|阅读模式
来自 中国–广东–深圳–南山区
本帖最后由 702033080 于 2009-9-29 22:04 编辑
请帮忙修改成兼容(1)[NO-sXe-I] (2)[NO-sXe-I] (3)[NO-sXe-I] (4)[NO-sXe-I] (5)[NO-sXe-I]
我自己也修改过..但是提示错误.太深.看不懂..只能懂浅一点的- new const PLUGINNAME[] = "中文ID"
- new const VERSION[] = "2.1"
- new const AUTHORS[] = "poohoo @ 老友记"
- #include <amxmodx>
- #include <amxmisc>
- #include <fakemeta>
- new g_RetryOnce[33]
- new g_SetName[33][32]
- new g_SetAllow[33]
- new FILE[256]
- public plugin_init()
- {
- register_plugin(PLUGINNAME, VERSION, AUTHORS)
- new configsdir[128]
- get_configsdir(configsdir, sizeof(configsdir)-1)
- formatex(FILE, sizeof(FILE)-1, "%s/chinese_id.ini", configsdir)
- if (!file_exists(FILE))
- set_fail_state("File (configs/chinese_id.ini) open error.")
- }
- // 名字更改消息
- public client_infochanged(id)
- {
- if (!is_user_connected(id))
- return PLUGIN_CONTINUE
- // 更换限制标记
- if (!g_SetAllow[id])
- {
- new oldname[32], newname[32]
- get_user_name(id, oldname, 31)
- get_user_info(id, "name", newname, 31)
- if (strcmp(newname, oldname)==0)
- return PLUGIN_CONTINUE
- // 兼容 sXe 改名
- if (equal(newname, "[NO-sXe-I]", 10))
- {
- replace(oldname, 31, "[NO-sXe-I] ", "")
- formatex(newname, 31, "[NO-sXe-I] %s", oldname)
- ig_setname(id, newname)
- }
- else
- ig_setname(id, oldname)
- return PLUGIN_CONTINUE
- }
- g_SetAllow[id] = 0
- ig_setname(id, g_SetName[id])
- return PLUGIN_CONTINUE
- }
- // 重名检查
- one_name(id, name[], len)
- {
- new sample[32], s
- copy(sample, 31, name)
- for (new i=0; i<33; i++)
- {
- if (s>0)
- formatex(sample, 31, "(%d)%s", s, name)
- if (!is_name_inuse(id, sample))
- break
- s++
- }
- copy(name, len, sample)
- }
- is_name_inuse(id, const sample[])
- {
- new name[32]
- for (new i=1; i<=get_maxplayers(); i++)
- {
- if (!is_user_connected(i)) continue
- if (id==i) continue
- get_user_name(i, name, 31)
- if (strcmp(name, sample)==0)
- return 1
- }
- return 0
- }
- // 设置 id 需要的名字
- public set_name(id, const newname[])
- {
- if (strlen(newname)<1)
- return
- g_SetAllow[id] = 1
- copy(g_SetName[id], 31, newname)
- one_name(id, g_SetName[id], 31)
- set_user_info(id, "name", g_SetName[id])
- }
- public client_connect(id)
- {
- remove_task(id)
- g_SetAllow[id] = 0
- // 强制重新连接一次,以解决因为换中文ID后,换图会出现权限认证问题
- if (!g_RetryOnce[id])
- {
- g_RetryOnce[id] = 1
- client_cmd(id, "retry")
- }
- }
- public client_putinserver(id)
- {
- // 延时足够的时间,等待 admin 权限认证插件完成权限设置后,再执行更换名字
- set_task(random_float(5.0,15.0), "get_name_from_file", id)
- }
- // 从文件里检查是否有对应的中文ID
- public get_name_from_file(id)
- {
- if (!is_user_connected(id))
- return
-
- new name[32]
- get_user_name(id, name, 31)
- new set = 0
- new hFile = fopen(FILE, "r")
- if (hFile)
- {
- new line[128], tmpName[64], tmpNameCN[64]
- while (fgets(hFile, line, sizeof(line)-1))
- {
- tmpName = ""
- tmpNameCN = ""
- trim(line)
- if (line[0]==';' || line[0]=='/') continue
- parse(line, tmpName,sizeof(tmpName)-1, tmpNameCN,sizeof(tmpNameCN)-1)
- trim(tmpName)
- trim(tmpNameCN)
- if (strcmp(name, tmpName)==0)
- {
- copy(name, 31, tmpNameCN)
- set = 1
- break
- }
- }
- }
- fclose(hFile)
- // 完成后,设置新的名字
- if (set)
- set_name(id, name)
- }
复制代码 请帮忙修改成兼容(1)[NO-sXe-I] (2)[NO-sXe-I] (3)[NO-sXe-I] (4)[NO-sXe-I] (5)[NO-sXe-I]
谢谢Rulzy帮忙 |
|