Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions doc/pandas_events.txt
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,47 @@
@unfavorite_amount 即将移出的道具数量
@unfavorite_idx 即将移出的道具序号 (背包序号)

--------------------------------------------------------------

*OnPCUseCommandFilter:

当玩家使用 GM 指令时触发过滤器 [聽風]

事件关联:
不关联到任何玩家

中断说明:
中断后服务端会无视本次的 GM 指令执行请求
指令不会被发往聊天窗口

携带参数:
$@cmd_from 指令的使用来源

0 - 调用 atcommand 脚本指令执行的 GM 指令
1 - 游戏中的玩家通过聊天窗口执行
2 - 通过地图服务器终端控制台调用的指令
3 - 调用 useatcmd 脚本指令执行的 GM 指令

$@cmd_src_aid 使用 GM 指令的玩家账号编号
当 @cmd_from 为 2 时, 此处固定值为 0

$@cmd_target_aid 指令所作用的目标玩家账号编号
当使用 # 开头的角色指令时此变量比较有用,
它会返回被执行角色的账号编号

$@cmd_name$ 使用的指令名称
$@cmd_params$ 指令附带的参数

注意事项:
由于此事件不关联到任何玩家,
因此携带参数的变量都变成了 $@ 开头的地图服务器临时变量,
而不是用 @ 开头的角色临时变量, 使用时要注意区分

此选项只有当执行指令的条件成立的时候才会被触发,
如当你执行 # 角色指令的时候, 目标角色必须处于在线状态等.
若条件不成立那么此过滤器将不会被触发.

当打断了此事件之后, OnPCTalkExpress 事件不会被触发.

//============================================================
// 熊猫模拟器 - 实时事件
Expand Down
5 changes: 5 additions & 0 deletions src/config/pandas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,11 @@
// 事件类型: Filter / 事件名称: OnPCFavoriteDelFilter
// 常量名称: NPCF_FAVORITE_DEL / 变量名称: favorite_del_filter_name
#define Pandas_NpcFilter_FAVORITE_DEL

// 当玩家使用 GM 指令时触发过滤器 [聽風]
// 事件类型: Filter / 事件名称: OnPCUseCommandFilter
// 常量名称: NPCF_USECOMMAND / 变量名称: usecommand_filter_name
#define Pandas_NpcFilter_USECOMMAND
// PYHELP - NPCEVENT - INSERT POINT - <Section 1>
#endif // Pandas_Struct_Map_Session_Data_EventHalt

Expand Down
35 changes: 35 additions & 0 deletions src/map/atcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11889,6 +11889,11 @@ bool is_atcommand(const int fd, map_session_data* sd, const char* message, int t

bool is_atcommand = true; // false if it's a charcommand

#ifdef Pandas_NpcFilter_USECOMMAND
int src_player_aid = 0; // 使用 GM 指令的玩家账号编号
int target_player_aid = 0; // 指令所作用的目标玩家账号编号
#endif // Pandas_NpcFilter_USECOMMAND

nullpo_retr(false, sd);

//Shouldn't happen
Expand Down Expand Up @@ -11920,12 +11925,22 @@ bool is_atcommand(const int fd, map_session_data* sd, const char* message, int t
}
}

#ifdef Pandas_NpcFilter_USECOMMAND
// 记录一下使用 GM 指令的玩家的账号编号
src_player_aid = sd->bl.id;
#endif // Pandas_NpcFilter_USECOMMAND

if (*message == charcommand_symbol)
is_atcommand = false;

if (is_atcommand) { // @command
sprintf(atcmd_msg, "%s", message);
ssd = sd;

#ifdef Pandas_NpcFilter_USECOMMAND
// 若使用的是 @ 开头的指令, 则目标玩家为自己 (此处记录的是玩家自己的账号编号)
target_player_aid = sd->bl.id;
#endif // Pandas_NpcFilter_USECOMMAND
} else { // #command
char charname[NAME_LENGTH];
int n;
Expand Down Expand Up @@ -11964,6 +11979,11 @@ bool is_atcommand(const int fd, map_session_data* sd, const char* message, int t
return true;
}

#ifdef Pandas_NpcFilter_USECOMMAND
// 若使用的是 # 开头的指令, 则目标玩家为指定的玩家 (此处记录的是目标玩家的账号编号)
target_player_aid = ssd->bl.id;
#endif // Pandas_NpcFilter_USECOMMAND

if (n > 2)
sprintf(atcmd_msg, "%s %s", command, params);
else
Expand Down Expand Up @@ -12044,7 +12064,22 @@ bool is_atcommand(const int fd, map_session_data* sd, const char* message, int t
return true;
}
}
#ifdef Pandas_NpcFilter_USECOMMAND
mapreg_setreg(add_str("$@cmd_from"), type);
mapreg_setreg(add_str("$@cmd_src_aid"), src_player_aid);
mapreg_setreg(add_str("$@cmd_target_aid"), target_player_aid);
mapreg_setregstr(add_str("$@cmd_name$"), command);
mapreg_setregstr(add_str("$@cmd_params$"), params);

// 兼容其他模拟器的参数
mapreg_setreg(add_str("$@cmd_type"), type);
mapreg_setreg(add_str("$@cmd_aid"), src_player_aid);

if (npc_script_filter(sd, NPCF_USECOMMAND)) {
// 告诉外部视为 GM 指令执行成功, 不要发送任何东西到聊天窗口
return true;
}
#endif // Pandas_NpcFilter_USECOMMAND
//Attempt to use the command
if ( (info->func(fd, ssd, command, params) != 0) )
{
Expand Down
6 changes: 6 additions & 0 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4367,6 +4367,12 @@ int parse_console(const char* buf){

strcpy(sd.status.name, "console");

#ifdef Pandas_NpcFilter_USECOMMAND
// 顺便初始化一下 sd 的游戏单位编号,
// 避免在调用 OnPCUseCommandFilter 的时候 $@cmd_src_aid 的值出现意外
sd.bl.id = 0;
#endif // Pandas_NpcFilter_USECOMMAND

if( ( n = sscanf(buf, "%63[^:]:%63[^:]:%11s %6hd %6hd[^\n]", type, command, mapname, &x, &y) ) < 5 ){
if( ( n = sscanf(buf, "%63[^:]:%63[^\n]", type, command) ) < 2 ) {
if((n = sscanf(buf, "%63[^\n]", type))<1) return -1; //nothing to do no arg
Expand Down
9 changes: 9 additions & 0 deletions src/map/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6586,6 +6586,10 @@ bool npc_event_is_filter(enum npce_event eventtype) {
#ifdef Pandas_NpcFilter_FAVORITE_DEL
NPCF_FAVORITE_DEL, // favorite_del_filter_name // OnPCFavoriteDelFilter // 当玩家准备将道具从收藏栏位移出时触发过滤器 [香草]
#endif // Pandas_NpcFilter_FAVORITE_DEL

#ifdef Pandas_NpcFilter_USECOMMAND
NPCF_USECOMMAND, // usecommand_filter_name // OnPCUseCommandFilter // 当玩家使用 GM 指令时触发过滤器 [聽風]
#endif // Pandas_NpcFilter_USECOMMAND
// PYHELP - NPCEVENT - INSERT POINT - <Section 20>
};

Expand Down Expand Up @@ -6971,6 +6975,11 @@ const char *npc_get_script_event_name(int npce_index)
case NPCF_FAVORITE_DEL:
return script_config.favorite_del_filter_name; // OnPCFavoriteDelFilter // 当玩家准备将道具从收藏栏位移出时触发过滤器 [香草]
#endif // Pandas_NpcFilter_FAVORITE_DEL

#ifdef Pandas_NpcFilter_USECOMMAND
case NPCF_USECOMMAND:
return script_config.usecommand_filter_name; // OnPCUseCommandFilter // 当玩家使用 GM 指令时触发过滤器 [聽風]
#endif // Pandas_NpcFilter_USECOMMAND
// PYHELP - NPCEVENT - INSERT POINT - <Section 3>

/************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions src/map/npc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,10 @@ enum npce_event : uint8 {
#ifdef Pandas_NpcFilter_FAVORITE_DEL
NPCF_FAVORITE_DEL, // favorite_del_filter_name // OnPCFavoriteDelFilter // 当玩家准备将道具从收藏栏位移出时触发过滤器 [香草]
#endif // Pandas_NpcFilter_FAVORITE_DEL

#ifdef Pandas_NpcFilter_USECOMMAND
NPCF_USECOMMAND, // usecommand_filter_name // OnPCUseCommandFilter // 当玩家使用 GM 指令时触发过滤器 [聽風]
#endif // Pandas_NpcFilter_USECOMMAND
// PYHELP - NPCEVENT - INSERT POINT - <Section 2>

/************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions src/map/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ struct Script_Config script_config = {
#ifdef Pandas_NpcFilter_FAVORITE_DEL
"OnPCFavoriteDelFilter", // NPCF_FAVORITE_DEL // favorite_del_filter_name // 当玩家准备将道具从收藏栏位移出时触发过滤器 [香草]
#endif // Pandas_NpcFilter_FAVORITE_DEL

#ifdef Pandas_NpcFilter_USECOMMAND
"OnPCUseCommandFilter", // NPCF_USECOMMAND // usecommand_filter_name // 当玩家使用 GM 指令时触发过滤器 [聽風]
#endif // Pandas_NpcFilter_USECOMMAND
// PYHELP - NPCEVENT - INSERT POINT - <Section 5>

/************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions src/map/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ struct Script_Config {
#ifdef Pandas_NpcFilter_FAVORITE_DEL
const char* favorite_del_filter_name; // NPCF_FAVORITE_DEL // OnPCFavoriteDelFilter // 当玩家准备将道具从收藏栏位移出时触发过滤器 [香草]
#endif // Pandas_NpcFilter_FAVORITE_DEL

#ifdef Pandas_NpcFilter_USECOMMAND
const char* usecommand_filter_name; // NPCF_USECOMMAND // OnPCUseCommandFilter // 当玩家使用 GM 指令时触发过滤器 [聽風]
#endif // Pandas_NpcFilter_USECOMMAND
// PYHELP - NPCEVENT - INSERT POINT - <Section 4>

/************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions src/map/script_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
#ifdef Pandas_NpcFilter_FAVORITE_DEL
export_constant(NPCF_FAVORITE_DEL); // favorite_del_filter_name // OnPCFavoriteDelFilter // 当玩家准备将道具从收藏栏位移出时触发过滤器 [香草]
#endif // Pandas_NpcFilter_FAVORITE_DEL

#ifdef Pandas_NpcFilter_USECOMMAND
export_constant(NPCF_USECOMMAND); // usecommand_filter_name // OnPCUseCommandFilter // 当玩家使用 GM 指令时触发过滤器 [聽風]
#endif // Pandas_NpcFilter_USECOMMAND
// PYHELP - NPCEVENT - INSERT POINT - <Section 6>

/************************************************************************/
Expand Down