改写网上的超级炉石功能的时候想改造下随身商人,自己建立一个商人NPC。
新增NPC
首先,也是最复杂的,新增creature_template 生物模板。
1 | INSERT INTO acore_world.creature_template (entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, modelid1, modelid2, modelid3, modelid4, name, subname, IconName, gossip_menu_id, minlevel, maxlevel, `exp`, faction, npcflag, speed_walk, speed_run, speed_swim, speed_flight, detection_range, `scale`, `rank`, dmgschool, DamageModifier, BaseAttackTime, RangeAttackTime, BaseVariance, RangeVariance, unit_class, unit_flags, unit_flags2, dynamicflags, family, trainer_type, trainer_spell, trainer_class, trainer_race, `type`, type_flags, lootid, pickpocketloot, skinloot, PetSpellDataId, VehicleId, mingold, maxgold, AIName, MovementType, HoverHeight, HealthModifier, ManaModifier, ArmorModifier, ExperienceModifier, RacialLeader, movementId, RegenHealth, mechanic_immune_mask, spell_school_immune_mask, flags_extra, ScriptName, VerifiedBuild) VALUES(90000, 0, 0, 0, 0, 0, 18629, 17268, 15527, 18145, '卖花花的小女孩', '商人', NULL, 0, 1, 1, 0, 35, 4224, 1.0, 1.1, 1.0, 1.0, 20.0, 0.9, 4, 0, 1.0, 1500, 1500, 1.0, 1.0, 8, 2147483650, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 1.0, 1.0, 1.0, 1.0, 1.0, 0, 0, 1, 0, 0, 0, '', 12340); |
creature_template 表结构非常复杂,需要参考官网说明, 这里说下着重需要注意的字段
- entry 生物模板的唯一标识
- modelid1~4 生物展示的模型,多个都填会随机选一个,如果只需要一个模型其他的填0
- name 显示名称
- subname 名称下显示的子名称,可以不填
- gossip_menu_id 对话菜单ID 以后用到菜单在详细说明
- faction 派别,这里需要填友善类
35具体参考官网factiontemplate - npcflag 这里我想要买卖(128)和修理(4096) 所以填 128+4096=
4224 - rank 参考文档,我这里选择稀有类型
4 - detection_range 看见玩家的距离
- unit_class 类别,这里选法师(有蓝条)
8 - unit_flags 一堆标志位,直接 不可攻击
0x00000002 - type 人型生物
7 - VerifiedBuild 验证的客户端版本
既然是卖花的小女孩,手里需要在拿两束花。从物品模板里面取两个小花
1 | select * from acore_world.item_template it where entry in (2706,2707) |
分别放到主手和副手上
1 | INSERT INTO acore_world.creature_equip_template (CreatureID, ID, ItemID1, ItemID2, ItemID3, VerifiedBuild) VALUES(90000, 1, 2706, 2707, 0, 12340); |
itemID3是远程,这里忽略。
添加售卖品
NPC已经建立好了,需要增加NPC的售卖品了(_这里注意npcflag必须包含128_)。
1 | INSERT INTO acore_world.npc_vendor (entry, slot, item, maxcount, incrtime, ExtendedCost, VerifiedBuild) VALUES(90000, 0, 2706, 9, 3600, 0, 0); |
- slot 代表物品位置,从左到右从上到下。这里都填0的话会自动排序。
- item 物品模板ID
- maxcount 最大数量不限就填0 如果大于0,下面的incrtime必填
- incrtime 物品刷新时间,单位秒
召唤商人
这里因为是超级炉石的功能,是使用Eluna来实现召唤商人的:
1 | function ST.SummonNPC(player, entry) |
关键是使用SpawnCreature方法来刷新一个NPC,注意因为是有时间限制的,
第六个参数spawnType需要填3 - despawns after a specified time ,despawnTimer 就是消失的时间,单位是毫秒。
召唤一下试试

成功!