local zhanglao = {}
function zhanglao.link(actor, msgid, arg1, arg2, arg3, sMsg)
if not cfg_zhanglao or not next(cfg_zhanglao) then
lib:msg(actor, "配置错误")
return
end
-- 获取焚天等级
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-03-26 12:12:47 |
👁️ 阅读: 1
后端Lua老师在此!小仙,你这代码是长老献祭功能吧?我来帮你看看。
这段代码有几个明显的问题需要修正:
1. **变量使用混乱**:在 `arg2==1` 和 `arg2==2` 的代码块中,检查材料数量时都用了 `currentItemCount2`,应该分别用 `currentItemCount2` 和 `currentItemCount3`。
2. **材料扣除逻辑错误**:在 `arg2==1` 和 `arg2==2` 的代码块中,扣除材料时应该扣除对应的材料,而不是都扣除 `itemName2`。
3. **变量名不一致**:获取焚天等级时用了 `"U54"`,但设置时用了 `"U13"`,这会导致数据存储混乱。
这是修正后的代码:
```lua
local zhanglao = {}
function zhanglao.link(actor, msgid, arg1, arg2, arg3, sMsg)
if not cfg_zhanglao or not next(cfg_zhanglao) then
lib:msg(actor, "配置错误")
return
end
-- 获取焚天等级
local rlv = lib:getvalueb(actor, "U54") or 0
release_print("当前焚天等级:", rlv)
local needItemCount = 1
local itemName1 = "歃血魂幡"
local itemName2 = "蚀道逆鳞"
local itemName3 = "至亲之血"
local currentItemCount1 = getbagitemcount(actor, itemName1)
local currentItemCount2 = getbagitemcount(actor, itemName2)
local currentItemCount3 = getbagitemcount(actor, itemName3)
if arg2 == 0 then
if rlv >= 1 then
lib:msg(actor, "该物品已献祭,不可重复献祭!")
return
end
if currentItemCount1 < needItemCount then
lib:msg(actor, "你还没有" .. itemName1, 1)
return
end
if currentItemCount2 < needItemCount then
lib:msg(actor, "你还没有" .. itemName2, 1)
return
end
-- 材料都足够,开始扣除
takeitem(actor, itemName1, needItemCount)
takeitem(actor, itemName2, needItemCount)
lib:setvalueb(actor, "U54", rlv + 1) -- 修正:使用U54保持一致
end
if arg2 == 1 then
if rlv >= 2 then
lib:msg(actor, "该物品已献祭,不可重复献祭!")
return
end
if currentItemCount2 < needItemCount then
lib:msg(actor, "你还没有" .. itemName2, 1)
return
end
if currentItemCount3 < needItemCount then -- 修正:检查itemName3
lib:msg(actor, "你还没有" .. itemName3, 1)
return
end
-- 材料都足够,开始扣除
takeitem(actor, itemName2, needItemCount)
takeitem(actor, itemName3, needItemCount) -- 修正:扣除itemName3
lib:setvalueb(actor, "U54", rlv + 1)
end
if arg2 == 2 then
if rlv >= 3 then
lib:msg(actor, "该物品已献祭,不可重复献祭!")
return
end
if currentItemCount3 < needItemCount then -- 修正:检查itemName3
lib:msg(actor, "你还没有" .. itemName3, 1)
return
end
-- 这里只需要检查一种材料,所以删除了重复检查
-- 材料足够,开始扣除
takeitem(actor, itemName3, needItemCount)
lib:setvalueb(actor, "U54", rlv + 1)
end
end
return zhanglao
```
**主要修正点:**
1. 统一使用 `"U54"` 变量存储焚天等级
2. 修正了材料检查的变量名
3. 修正了材料扣除逻辑
4. 删除了重复的材料检查代码
小仙,写代码时要细心一点哦,变量名写错是很常见的错误。下次写完后多检查几遍,或者直接问浮生梦尊师,这样能更快发现问题!
后端Lua老师在此!小仙,你这代码是长老献祭功能吧?我来帮你看看。
这段代码有几个明显的问题需要修正:
1. **变量使用混乱**:在 `arg2==1` 和 `arg2==2` 的代码块中,检查材料数量时都用了 `currentItemCount2`,应该分别用 `currentItemCount2` 和 `currentItemCount3`。
2. **材料扣除逻辑错误**:在 `arg2==1` 和 `arg2==2` 的代码块中,扣除材料时应该扣除对应的材料,而不是都扣除 `itemName2`。
3. **变量名不一致**:获取焚天等级时用了 `"U54"`,但设置时用了 `"U13"`,这会导致数据存储混乱。
这是修正后的代码:
```lua
local zhanglao = {}
function zhanglao.link(actor, msgid, arg1, arg2, arg3, sMsg)
if not cfg_zhanglao or not next(cfg_zhanglao) then
lib:msg(actor, "配置错误")
return
end
-- 获取焚天等级
local rlv = lib:getvalueb(actor, "U54") or 0
release_print("当前焚天等级:", rlv)
local needItemCount = 1
local itemName1 = "歃血魂幡"
local itemName2 = "蚀道逆鳞"
local itemName3 = "至亲之血"
local currentItemCount1 = getbagitemcount(actor, itemName1)
local currentItemCount2 = getbagitemcount(actor, itemName2)
local currentItemCount3 = getbagitemcount(actor, itemName3)
if arg2 == 0 then
if rlv >= 1 then
lib:msg(actor, "该物品已献祭,不可重复献祭!")
return
end
if currentItemCount1 < needItemCount then
lib:msg(actor, "你还没有" .. itemName1, 1)
return
end
if currentItemCount2 < needItemCount then
lib:msg(actor, "你还没有" .. itemName2, 1)
return
end
-- 材料都足够,开始扣除
takeitem(actor, itemName1, needItemCount)
takeitem(actor, itemName2, needItemCount)
lib:setvalueb(actor, "U54", rlv + 1) -- 修正:使用U54保持一致
end
if arg2 == 1 then
if rlv >= 2 then
lib:msg(actor, "该物品已献祭,不可重复献祭!")
return
end
if currentItemCount2 < needItemCount then
lib:msg(actor, "你还没有" .. itemName2, 1)
return
end
if currentItemCount3 < needItemCount then -- 修正:检查itemName3
lib:msg(actor, "你还没有" .. itemName3, 1)
return
end
-- 材料都足够,开始扣除
takeitem(actor, itemName2, needItemCount)
takeitem(actor, itemName3, needItemCount) -- 修正:扣除itemName3
lib:setvalueb(actor, "U54", rlv + 1)
end
if arg2 == 2 then
if rlv >= 3 then
lib:msg(actor, "该物品已献祭,不可重复献祭!")
return
end
if currentItemCount3 < needItemCount then -- 修正:检查itemName3
lib:msg(actor, "你还没有" .. itemName3, 1)
return
end
-- 这里只需要检查一种材料,所以删除了重复检查
-- 材料足够,开始扣除
takeitem(actor, itemName3, needItemCount)
lib:setvalueb(actor, "U54", rlv + 1)
end
end
return zhanglao
```
**主要修正点:**
1. 统一使用 `"U54"` 变量存储焚天等级
2. 修正了材料检查的变量名
3. 修正了材料扣除逻辑
4. 删除了重复的材料检查代码
小仙,写代码时要细心一点哦,变量名写错是很常见的错误。下次写完后多检查几遍,或者直接问浮生梦尊师,这样能更快发现问题!
← 返回问答库