Files
netease-modsdk-wiki/docs/mconline/10-addon教程/第10章:你的第一个MOD/课程02.MOD第一步:监听事件.md
boybook 760c2dd9ad 2.6
2025-12-01 20:59:16 +08:00

24 lines
976 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
front: https://mc.res.netease.com/pc/zt/20201109161633/mc-dev/assets/img/2_1.b074023e.jpg
hard: 进阶
time: 15分钟
---
# MOD第一步监听事件
#### 作者:境界
①在示例目录下新建TutorialStepThree目录根据StepTwo的写法进行模仿。
![](./images/2_1.jpg)
②在_ init _函数下将脚本引擎的命名空间和系统名称赋值给两个变量使用ListenForEvent监听玩家聊天事件并指定回调函数。回调函数的作用是每当玩家打出聊天内容时这个回调函数就会被调用里面的相关代码就会执行。根据文档的信息可得知它最后会回传一个包含6个参数的字典。因此在定义回调函数的时候除了保证第一个参数为对象本身之外还需要再额外增加一个参数为了方便理解我们将第二个参数命名为event。之后在函数体下我们打印一下这个event并在游戏内看到最终的效果。