local itemname = getiteminfo(actor, getitembymakeindex(actor,str),7)
jlsl = ransjstr("2#1000|3#500|4#300|5#200|6#100|7#10|8#8|9#5|10#3|20#1", 1, 1)
if delitembymakeindex(actor,str,1) then
if string.find(itemname, "%[盛世%]")
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-04-29 16:13:31 |
👁️ 阅读: 12
我是lua后端老师!
小仙,这段代码看起来是一个物品分解功能,根据物品名称中的特定前缀来给予不同数量的“生肖碎片”奖励。让我帮你分析一下:
这段代码的主要逻辑是:
1. 通过`getitembymakeindex`获取物品唯一ID对应的物品对象
2. 使用`getiteminfo`获取物品名称(参数7表示获取物品名称)
3. 使用`ransjstr`随机获取一个奖励倍数
4. 删除该物品并给予相应的生肖碎片奖励
不过,我注意到代码中有几个问题需要修正:
```lua
-- 这里需要先获取物品对象,再获取物品名称
local itemObj = getitembymakeindex(actor, str) -- 先获取物品对象
local itemname = getiteminfo(actor, itemObj, 7) -- 再获取物品名称
jlsl = ransjstr("2#1000|3#500|4#300|5#200|6#100|7#10|8#8|9#5|10#3|20#1", 1, 1)
if delitembymakeindex(actor, str, 1) then
if string.find(itemname, "%[盛世%]") then
giveitem(actor, "生肖碎片", jlsl * 5)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['.. jlsl * 5 ..'个生肖碎片]!</font>","Type":9}')
elseif string.find(itemname, "%[断尘%]") then
giveitem(actor, "生肖碎片", jlsl * 10)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['.. jlsl * 10 ..'个生肖碎片]!</font>","Type":9}')
elseif string.find(itemname, "%[执月%]") then
giveitem(actor, "生肖碎片", jlsl * 15)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['.. jlsl * 15 ..'个生肖碎片]!</font>","Type":9}')
elseif string.find(itemname, "%[梦归%]") then
giveitem(actor, "生肖碎片", jlsl * 20)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['.. jlsl * 20 ..'个生肖碎片]!</font>","Type":9}')
else
giveitem(actor, "生肖碎片", jlsl)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['..jlsl..'个生肖碎片]!</font>","Type":9}')
end
end
```
主要修改点:
1. 将`getitembymakeindex`和`getiteminfo`分开调用,因为`getiteminfo`需要物品对象作为参数
2. 修正了消息提示中的数量计算,让显示的数量与实际给予的数量保持一致
另外要注意的是,`ransjstr`函数返回的是字符串,你可能需要转换为数字:
```lua
jlsl = tonumber(ransjstr("2#1000|3#500|4#300|5#200|6#100|7#10|8#8|9#5|10#3|20#1", 1, 1))
```
这个功能设计得挺有意思的,通过物品名称前缀来区分不同的品质等级,给予不同的奖励倍数。不过小仙要注意检查一下,这个代码是在哪个QF触发中使用的,确保`str`参数是正确的物品唯一ID哦!
如果还有不明白的地方,随时可以问我,或者去请教浮生梦尊师!😊
我是lua后端老师!
小仙,这段代码看起来是一个物品分解功能,根据物品名称中的特定前缀来给予不同数量的“生肖碎片”奖励。让我帮你分析一下:
这段代码的主要逻辑是:
1. 通过`getitembymakeindex`获取物品唯一ID对应的物品对象
2. 使用`getiteminfo`获取物品名称(参数7表示获取物品名称)
3. 使用`ransjstr`随机获取一个奖励倍数
4. 删除该物品并给予相应的生肖碎片奖励
不过,我注意到代码中有几个问题需要修正:
```lua
-- 这里需要先获取物品对象,再获取物品名称
local itemObj = getitembymakeindex(actor, str) -- 先获取物品对象
local itemname = getiteminfo(actor, itemObj, 7) -- 再获取物品名称
jlsl = ransjstr("2#1000|3#500|4#300|5#200|6#100|7#10|8#8|9#5|10#3|20#1", 1, 1)
if delitembymakeindex(actor, str, 1) then
if string.find(itemname, "%[盛世%]") then
giveitem(actor, "生肖碎片", jlsl * 5)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['.. jlsl * 5 ..'个生肖碎片]!</font>","Type":9}')
elseif string.find(itemname, "%[断尘%]") then
giveitem(actor, "生肖碎片", jlsl * 10)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['.. jlsl * 10 ..'个生肖碎片]!</font>","Type":9}')
elseif string.find(itemname, "%[执月%]") then
giveitem(actor, "生肖碎片", jlsl * 15)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['.. jlsl * 15 ..'个生肖碎片]!</font>","Type":9}')
elseif string.find(itemname, "%[梦归%]") then
giveitem(actor, "生肖碎片", jlsl * 20)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['.. jlsl * 20 ..'个生肖碎片]!</font>","Type":9}')
else
giveitem(actor, "生肖碎片", jlsl)
sendmsg(actor, 1, '{"Msg":"<font color=\'#ff0000\'>系统提示:</font><font color=\'#00FF00\'>您获得了['..jlsl..'个生肖碎片]!</font>","Type":9}')
end
end
```
主要修改点:
1. 将`getitembymakeindex`和`getiteminfo`分开调用,因为`getiteminfo`需要物品对象作为参数
2. 修正了消息提示中的数量计算,让显示的数量与实际给予的数量保持一致
另外要注意的是,`ransjstr`函数返回的是字符串,你可能需要转换为数字:
```lua
jlsl = tonumber(ransjstr("2#1000|3#500|4#300|5#200|6#100|7#10|8#8|9#5|10#3|20#1", 1, 1))
```
这个功能设计得挺有意思的,通过物品名称前缀来区分不同的品质等级,给予不同的奖励倍数。不过小仙要注意检查一下,这个代码是在哪个QF触发中使用的,确保`str`参数是正确的物品唯一ID哦!
如果还有不明白的地方,随时可以问我,或者去请教浮生梦尊师!😊
← 返回问答库