smart_scripts 表
smart_scripts 表是 AzerothCore 中 SmartAI 系统的核心表格,定义了生物、游戏对象和区域触发器的智能行为脚本。通过事件-动作-目标(Event-Action-Target)的三要素模型,可以为 NPC 配置复杂的 AI 行为,包括战斗逻辑、对话、施法、移动等。
表概述
smart_scripts 使用 EntryOrGUID + source_type 定位脚本所属的实体,每个脚本条目包含事件(event)、动作(action)和目标(target)三大部分。当 Event(事件)被触发时,系统会执行对应的 Action(动作),作用在 Target(目标)上。
脚本之间可以通过 link 字段链接形成事件链,实现复杂的多步骤行为。配合 conditions 表可以实现更精细的条件控制。
entryorguid
int, 主键
实体 ID 或 GUID
int, 主键
实体 ID 或 GUID
source_type
tinyint unsigned, 主键
脚本来源类型
tinyint unsigned, 主键
脚本来源类型
event_type
tinyint unsigned
触发事件类型
tinyint unsigned
触发事件类型
action_type
tinyint unsigned
执行的动作类型
tinyint unsigned
执行的动作类型
target_type
tinyint unsigned
动作目标类型
tinyint unsigned
动作目标类型
表结构
| 字段名 | 数据类型 | 默认值 | 说明 |
|---|---|---|---|
| entryorguid | int | 非空 | 目标实体的 ID(如 creature_template.entry)或 GUID |
| source_type | tinyint UNSIGNED | 0 | 脚本来源类型(0=生物, 1=游戏对象, 2=区域触发器, 9=定时事件) |
| id | smallint UNSIGNED | 0 | 脚本唯一 ID,同一实体内唯一 |
| link | smallint UNSIGNED | 0 | 链接到另一个脚本 ID(形成事件链) |
| event_type | tinyint UNSIGNED | 0 | 触发脚本的事件类型 |
| event_phase_mask | smallint UNSIGNED | 0 | 事件阶段掩码 |
| event_chance | tinyint UNSIGNED | 100 | 事件触发概率(0-100) |
| event_flags | smallint UNSIGNED | 0 | 事件标志位 |
| event_param1 | int UNSIGNED | 0 | 事件参数1 |
| event_param2 | int UNSIGNED | 0 | 事件参数2 |
| event_param3 | int UNSIGNED | 0 | 事件参数3 |
| event_param4 | int UNSIGNED | 0 | 事件参数4 |
| event_param5 | int UNSIGNED | 0 | 事件参数5 |
| event_param6 | int UNSIGNED | 0 | 事件参数6 |
| action_type | tinyint UNSIGNED | 0 | 执行的动作类型 |
| action_param1 | int UNSIGNED | 0 | 动作参数1 |
| action_param2 | int UNSIGNED | 0 | 动作参数2 |
| action_param3 | int UNSIGNED | 0 | 动作参数3 |
| action_param4 | int UNSIGNED | 0 | 动作参数4 |
| action_param5 | int UNSIGNED | 0 | 动作参数5 |
| action_param6 | int UNSIGNED | 0 | 动作参数6 |
| target_type | tinyint UNSIGNED | 0 | 动作的目标类型 |
| target_param1 | int UNSIGNED | 0 | 目标参数1 |
| target_param2 | int UNSIGNED | 0 | 目标参数2 |
| target_param3 | int UNSIGNED | 0 | 目标参数3 |
| target_param4 | int UNSIGNED | 0 | 目标参数4 |
| target_x | float | 0 | 目标的 X 坐标 |
| target_y | float | 0 | 目标的 Y 坐标 |
| target_z | float | 0 | 目标的 Z 坐标 |
| target_o | float | 0 | 目标的朝向角度 |
| comment | text | 非空 | 脚本注释说明,便于理解和维护 |
主键: (entryorguid, source_type, id, link) | 引擎: InnoDB | 字符集: utf8mb4
重要字段详解
entryorguid (实体 ID/GUID)
根据 source_type 的不同,含义不同:
- source_type = 0(生物):creature_template.entry
- source_type = 1(游戏对象):gameobject_template.entry
- source_type = 2(区域触发器):areatrigger_template.id
- source_type = 9(定时事件):自定义事件 ID
source_type (来源类型)
- 0 SMART_SCRIPT_TYPE_CREATURE - 生物脚本
- 1 SMART_SCRIPT_TYPE_GAMEOBJECT - 游戏对象脚本
- 2 SMART_SCRIPT_TYPE_AREATRIGGER - 区域触发器脚本
- 9 SMART_SCRIPT_TYPE_TIMED_ACTIONLIST - 定时动作列表
event_type (事件类型) - 常用值
- 0 UPDATE_IC - 战斗中更新
- 1 UPDATE_OOC - 非战斗更新
- 2 HEALTH_PCT - 生命值百分比
- 4 AGGRO - 进入战斗
- 5 KILL - 击杀目标
- 6 DEATH - 死亡
- 7 EVADE - 脱离战斗
- 8 SPELLHIT - 被法术击中
- 9 RANGE - 距离范围
- 11 RESPAWN - 重生
- 19 ACCEPTED_QUEST - 接受任务
- 20 REWARD_QUEST - 完成任务
- 37 DATA_SET - 数据设置事件
- 38 WAYPOINT_START - 路径开始
action_type (动作类型) - 常用值
- 1 TALK - 说话/聊天
- 2 SET_FACTION - 设置阵营
- 5 PLAY_EMOTE - 播放表情
- 11 CAST - 施放法术
- 12 SUMMON_CREATURE - 召唤生物
- 18 REMOVE_UNIT_FLAG - 移除单位标志
- 28 TELEPORT - 传送
- 33 SET_DATA - 设置数据
- 34 SET_VISIBILITY - 设置可见性
- 53 CROSS_CAST - 跨目标施法
target_type (目标类型) - 常用值
- 0 NONE - 无目标
- 1 SELF - 自己
- 2 VICTIM - 当前攻击目标
- 5 HOSTILE_RANDOM - 随机敌对目标
- 8 POSITION - 指定位置
- 10 CREATURE_GUID - 指定 GUID 生物
- 12 STORED - 存储的目标
实战案例
案例1:生物进入战斗时说话
INSERT INTO smart_scripts (entryorguid, source_type, id, link,
event_type, event_chance, event_flags,
action_type, action_param1,
target_type, target_param1,
comment)
VALUES (12345, 0, 0, 0,
4, 100, 0, -- AGGRO 事件
1, 50001, -- TALK 动作,文本ID=50001
1, 0, -- 目标=自己
'进入战斗时说话');
案例2:生命值低于30%时施放治疗法术
INSERT INTO smart_scripts (entryorguid, source_type, id, link,
event_type, event_param1, event_chance, event_flags,
action_type, action_param1,
target_type,
comment)
VALUES (12345, 0, 1, 0,
2, 30, 100, 1, -- HEALTH_PCT 事件,低于30%
11, 2061, -- CAST 动作,法术ID=2061(治疗)
1, -- 目标=自己
'生命值低于30%时自疗');
案例3:死亡时召唤生物并说话
-- 脚本0:死亡时说话并链接到脚本1
INSERT INTO smart_scripts (entryorguid, source_type, id, link,
event_type, action_type, action_param1, target_type, comment)
VALUES (12345, 0, 0, 1, 6, 1, 60001, 1, '死亡时说话并触发召唤');
-- 脚本1:被链接触发,召唤生物
INSERT INTO smart_scripts (entryorguid, source_type, id, link,
event_type, event_param1, event_param2,
action_type, action_param1, action_param2, action_param3, target_type,
target_x, target_y, target_z, target_o, comment)
VALUES (12345, 0, 1, 0,
61, 0, 0, -- LINK 事件
12, 54321, 1, 60000, 8, -- SUMMON_CREATURE,持续60秒
0, 0, 0, 0, -- 在自身位置召唤
'召唤仆从');
常见问题
Q: SmartAI 脚本不生效怎么办?
- 检查 creature_template 的 AIName 是否设为 'SmartAI'
- 确认 entryorguid 和 source_type 匹配正确的实体
- 检查 event_chance 是否设置正确(0-100)
- 配合 conditions 表检查是否有条件限制
Q: 如何让脚本循环执行?
在 action 后设置 link 回到脚本本身即可形成循环。但需要注意性能,避免过于频繁的更新事件。
Q: 重载命令是什么?
.reload smart_scripts
相关表格
- conditions - SmartAI 条件控制
- creature_template - 生物模板(需设 AIName='SmartAI')
- gameobject_template - 游戏对象模板
- waypoint_data - 路径点数据
- waypoint_scripts - 路径点脚本