问题位置:
服务端:
\ubuntu\tlbb\services\scripts\event\jvqing\yipin_01.lua
对应剧情:
一品堂剧情任务:一笑人间万事
死亡 NPC:
- 一品死亡童姥 -> 天山童姥
- 一品死亡李秋水 -> 李秋水
问题原因
死亡模型是通过怪物模板创建的,模板本身名字是“一品死亡童姥 / 一品死亡李秋水”。
正确做法是在服务端脚本创建 NPC 后,调用:
self:SetCharacterName(newMonst, "天山童姥")
self:SetCharacterName(newMonst, "李秋水")
进行运行时改名。
正确写法
创建死亡模型后,立即设置名字:
local newMonst = self:LuaFnCreateMonster(491, 20, 25, 1, 0, -1)
local obj = self.scene:get_obj_by_id(newMonst)
if obj then
self:SetUnitReputationID(selfId, newMonst, 0)
self:SetMonsterFightWithNpcFlag(newMonst, 0)
self:SetNPCAIType(newMonst, 3)
self:SetCharacterName(newMonst, "天山童姥")
self:SetHp(newMonst, 1)
self:LuaFnSendSpecificImpactToUnit(selfId, newMonst, newMonst, 44, 2)
end
李秋水同理:
local newMonst = self:LuaFnCreateMonster(492, 22, 27, 1, 0, -1)
local obj = self.scene:get_obj_by_id(newMonst)
if obj then
self:SetUnitReputationID(selfId, newMonst, 0)
self:SetMonsterFightWithNpcFlag(newMonst, 0)
self:SetNPCAIType(newMonst, 3)
self:SetCharacterName(newMonst, "李秋水")
self:SetHp(newMonst, 1)
self:LuaFnSendSpecificImpactToUnit(selfId, newMonst, newMonst, 44, 2)
end
避免闪烁的关键
不要在遍历怪物列表时边删边创建同名 NPC。
错误风险写法:
for ii = 1, nMonsterNum do
local nMonsterId = self:GetMonsterObjID(ii)
if self:GetName(nMonsterId) == "天山童姥" then
self:LuaFnDeleteMonster(nMonsterId)
local newMonst = self:LuaFnCreateMonster(...)
self:SetCharacterName(newMonst, "天山童姥")
end
end
因为新创建的 NPC 也叫“天山童姥”,可能被同一轮逻辑再次匹配,导致反复删除/创建,表现为 NPC 一闪一闪。
正确写法是先记录旧对象 ID:
local oldTonglao
local oldLiqiushui
local nMonsterNum = self:GetMonsterCount()
for ii = 1, nMonsterNum do
local nMonsterId = self:GetMonsterObjID(ii)
if self:GetName(nMonsterId) == "天山童姥" then
oldTonglao = nMonsterId
elseif self:GetName(nMonsterId) == "李秋水" then
oldLiqiushui = nMonsterId
end
end
然后在循环外删除并重建:
if oldTonglao then
self:LuaFnDeleteMonster(oldTonglao)
local newMonst = self:LuaFnCreateMonster(491, 20, 25, 1, 0, -1)
self:SetCharacterName(newMonst, "天山童姥")
end