我是lua后端老师!
小仙,要给指定makeindex的物品设置“副本装备”标记,这个需求很常见!我们可以利用物品的自定义属性来标记,这样既灵活又不会占用有限的装备标记位。
根据你的需求,我来给你一个完整的解决方案:
```lua
-- 给指定makeindex的物品设置副本装备标记
function setDungeonEquipmentMark(play, makeindex)
-- 根据物品唯一ID获取物品对象
local item = getitembymakeindex(play, makeindex)
if not item then
release_print("获取物品对象失败,makeindex: " .. tostring(makeindex))
return false
end
-- 获取当前的自定义属性
local customJson = getitemcustomabil(play, item)
local customTable = {}
-- 如果已有自定义属性,解析成table
if customJson and customJson ~= "" then
customTable = json2tbl(customJson)
end
-- 设置副本装备标记
customTable["dungeon_equipment"] = true
-- 将table转换为json字符串
local newJson = tbl2json(customTable)
-- 设置自定义属性
setitemcustomabil(play, item, newJson)
-- 刷新物品信息到前端
refreshitem(play, item)
release_print("成功设置副本装备标记")
return true
end
-- 检查物品是否为副本装备
function isDungeonEquipment(play, item)
if not item then
return false
end
-- 获取自定义属性
local customJson = getitemcustomabil(play, item)
if customJson and customJson ~= "" then
local customTable = json2tbl(customJson)
-- 检查是否有副本装备标记
if customTable["dungeon_equipment"] then
return true
end
end
return false
end
-- 清除副本装备标记
function clearDungeonEquipmentMark(play, item)
if not item then
return false
end
-- 获取当前的自定义属性
local customJson = getitemcustomabil(play, item)
if customJson and customJson ~= "" then
local customTable = json2tbl(customJson)
-- 移除副本装备标记
customTable["dungeon_equipment"] = nil
-- 如果还有其他属性,更新;否则清空
if next(customTable) ~= nil then
local newJson = tbl2json(customTable)
setitemcustomabil(play, item, newJson)
else
-- 清空自定义属性
clearitemcustomabil(play, item, -1) -- -1表示清空所有组
end
-- 刷新物品信息到前端
refreshitem(play, item)
release_print("成功清除副本装备标记")
return true
end
return false
end
-- 示例使用
function exampleUsage(play)
-- 假设我们知道物品的makeindex
local targetMakeindex = 10086
-- 1. 设置副本装备标记
setDungeonEquipmentMark(play, targetMakeindex)
-- 2. 获取物品对象并检查
local item = getitembymakeindex(play, targetMakeindex)
if item then
if isDungeonEquipment(play, item) then
release_print("这是副本装备")
else
release_print("这不是副本装备")
end
-- 3. 可以清除标记
clearDungeonEquipmentMark(play, item)
end
end
```
**使用说明:**
1. **`setDungeonEquipmentMark(play, makeindex)`** - 给指定makeindex的物品设置副本装备标记
2. **`isDungeonEquipment(play, item)`** - 检查物品是否为副本装备
3. **`clearDungeonEquipmentMark(play, item)`** - 清除副本装备标记
**为什么用自定义属性而不是装备标记?**
- 自定义属性更灵活,可以存储更多信息
- 不会占用有限的装备标记位(type=3只有32个标记)
- 可以存储布尔值、数字、字符串等多种类型
**注意事项:**
1. 使用前确保物品存在
2. 自定义属性是json格式存储的
3. 设置后记得用`refreshitem`刷新到前端
4. 可以用`getiteminfo`获取物品的详细信息来验证
这样设置后,你就可以在QF触发器中通过`isDungeonEquipment`函数来判断物品是否为副本装备了!比如在`takeon`、`takeoff`等触发器中检查。
如果还有不明白的地方,随时问我哦!