|
发表于 2007-11-23 05:21:12
|
显示全部楼层
|阅读模式
来自 中国–北京–北京
附上源码 另外这个插件和wwcl有什么区别 wwcl也可以接触f1-12的按键绑定吧 考虑给服务器上这个 所以想先了解一下细节
请熟悉的朋友指出 非常感谢!
最后一个函数is_user_loopback没看明白 不知道是怎么判断某人是reconnect而不是刚加入游戏的 loopback是什么? 为什么可以用ips 和他进行equal判断- /* Client Exec */
- /*
- * Client exec some commands when connect, putin the server or player spawn.
- *
- * The config files are "client_exec_on_connect.cfg" , "client_exec_on_putinserv.cfg"
- * and "client_exec_on_resethud.cfg" in the AMX Mod X configs dir.
- *
- * [Change Log]
- *
- * v1.2 divide "on_resethud" from "putinserv"
- * v1.1 [L65] Fix config line number
- *
- */
-
- #include <amxmodx>
- #include <amxmisc>
- // don't exec commands on loopback
- #define LOOPBACK_NOT_EXEC 1
- new const PLUGIN_NAME[] = "Client Exec"
- new const PLUGIN_VERSION[] = "1.2"
- new const PLUGIN_AUTHOR[] = "KinSprite"
- new const cfg_file_connect[] = "client_exec_on_connect.cfg"
- new const cfg_file_putinserv[] = "client_exec_on_putinserv.cfg"
- new const cfg_file_resethud[] = "client_exec_on_resethud.cfg"
- #define MAX_EXEC_CHARS 128
- #define MAX_EXEC_LINES_CONNECT 128
- #define MAX_EXEC_LINES_PUTINSERV 128
- #define MAX_EXEC_LINES_RESETHUD 128
- new const cl_exec_connect[MAX_EXEC_LINES_CONNECT][MAX_EXEC_CHARS]
- new const cl_exec_putinserv[MAX_EXEC_LINES_PUTINSERV][MAX_EXEC_CHARS]
- new const cl_exec_resethud[MAX_EXEC_LINES_RESETHUD][MAX_EXEC_CHARS]
- new g_execNum_connect
- new g_execNum_putinserv
- new g_execNum_resethud
- enum {
- read_connect_cfg = 0,
- read_putinserv_cfg,
- read_resethud_cfg
- };
- new g_client_exec
- public plugin_init() {
- register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
- register_event("ResetHUD", "player_spawn", "b")
- g_client_exec = register_cvar("amx_client_exec", "1")
- }
- public plugin_cfg() {
- set_task(2.0, "read_exec_cfg")
- }
- public read_exec_cfg() {
- new cfg_dir[128], cfg_path[192], max_lines, max_chars
- get_configsdir(cfg_dir, 127)
-
- max_chars = MAX_EXEC_CHARS
-
- format(cfg_path, 191, "%s/%s", cfg_dir, cfg_file_connect) // connect to server
- max_lines = MAX_EXEC_LINES_CONNECT
- g_execNum_connect = read_lines(cfg_path, read_connect_cfg, max_lines, max_chars)
-
- format(cfg_path, 191, "%s/%s", cfg_dir, cfg_file_putinserv) // put in server
- max_lines = MAX_EXEC_LINES_PUTINSERV
- g_execNum_putinserv = read_lines(cfg_path, read_putinserv_cfg, max_lines, max_chars)
-
- format(cfg_path, 191, "%s/%s", cfg_dir, cfg_file_resethud) // reset HUD
- max_lines = MAX_EXEC_LINES_RESETHUD
- g_execNum_resethud = read_lines(cfg_path, read_resethud_cfg, max_lines, max_chars)
- }
- stock read_lines(filepath[], readcfg, read_max_lines, max_chars) {
- if (!file_exists(filepath))
- return 0
-
- new line, curline, txtlen
- new max_line = file_size(filepath, 1)
- new no_end = 1
-
- while (no_end) {
- curline = line
-
- if (readcfg == read_connect_cfg)
- line = read_file(filepath, line, cl_exec_connect[curline], max_chars, txtlen)
- else if (readcfg == read_putinserv_cfg)
- line = read_file(filepath, line, cl_exec_putinserv[curline], max_chars, txtlen)
- else
- line = read_file(filepath, line, cl_exec_resethud[curline], max_chars, txtlen)
-
- if (line==0 || line==max_line || max_line == read_max_lines)
- no_end = 0
- }
-
- return curline + 1
- }
- public client_connect(id) {
- if (!get_pcvar_num(g_client_exec) || is_user_bot(id))
- return PLUGIN_CONTINUE
-
- #if LOOPBACK_NOT_EXEC == 1
- if (is_user_loopback(id))
- return PLUGIN_CONTINUE
- #endif
-
- for (new i = 0; i < g_execNum_connect; ++i)
- client_cmd(id, cl_exec_connect[i])
-
- return PLUGIN_CONTINUE
- }
- public client_putinserver(id) {
- if (!get_pcvar_num(g_client_exec) || is_user_bot(id))
- return PLUGIN_CONTINUE
-
- #if LOOPBACK_NOT_EXEC == 1
- if (is_user_loopback(id))
- return PLUGIN_CONTINUE
- #endif
-
- set_task(0.1, "client_putinserver_exec", id)
-
- return PLUGIN_CONTINUE
- }
- public client_putinserver_exec(id){
- if (!is_user_connected(id) || is_user_bot(id))
- return
-
- for (new i = 0; i < g_execNum_putinserv; ++i)
- client_cmd(id, cl_exec_putinserv[i])
- }
- public player_spawn(id) {
- if (!get_pcvar_num(g_client_exec) || is_user_bot(id))
- return PLUGIN_CONTINUE
-
- #if LOOPBACK_NOT_EXEC == 1
- if (is_user_loopback(id))
- return PLUGIN_CONTINUE
- #endif
-
- for (new i = 0; i < g_execNum_resethud; ++i)
- client_cmd(id, cl_exec_resethud[i])
-
- return PLUGIN_CONTINUE
- }
- #if LOOPBACK_NOT_EXEC == 1
- stock is_user_loopback(id)
- {
- new ips[32]
- get_user_ip(id, ips, 31, 1)
-
- return equal(ips, "loopback")
- }
- #endif
复制代码 |
|