mythkina 发表于 2007-11-23 05:21:12

请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区别

附上源码 另外这个插件和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.
*
*
*
*   v1.2divide "on_resethud" from "putinserv"
*   v1.1 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
new const cl_exec_putinserv
new const cl_exec_resethud
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, cfg_path, 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, max_chars, txtlen)
else if (readcfg == read_putinserv_cfg)
   line = read_file(filepath, line, cl_exec_putinserv, max_chars, txtlen)
else
   line = read_file(filepath, line, cl_exec_resethud, 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)

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)
}
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)

return PLUGIN_CONTINUE
}
#if LOOPBACK_NOT_EXEC == 1
stock is_user_loopback(id)
{
new ips
get_user_ip(id, ips, 31, 1)

return equal(ips, "loopback")
}
#endif

AE86 发表于 2007-11-24 04:40:56

回复: 请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区

KinSprite的经典啊~~~~
大概是WWCL没这个好用吧

mythkina 发表于 2007-11-24 20:51:57

回复: 请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区

感谢 AE86兄的回复 其实我想把这个用在自己的服上 但是因为以后要改代码 所以有一段没看懂确实麻烦 最近kinsprite都没见到了

mythkina 发表于 2007-12-2 18:56:51

回复: 请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区

kinsprite是不是很久不来了 有懂这段代码的帮忙解释一下呀
页: [1]
查看完整版本: 请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区别