有装备的唯一ID,后端这么判断装备是否存在 要区分背包内还是身上的装备吗
🤖 回答引擎: 热血江湖Lua |
🕒 时间: 2026-03-04 10:14:37 |
👁️ 阅读: 11
可以使用 `hasitem` 接口来判断。该接口通过物品唯一ID进行判断,返回值可以明确区分装备是在背包内、装备在身上还是不存在。
具体语法为:
```lua
hasitem(actor, makeIndex)
```
- **参数**:
- `actor`:玩家对象。
- `makeIndex`:物品唯一ID。
- **返回值**:
- 返回 `1`:表示物品存在于背包。
- 返回 `0`:表示物品装备在身上。
- 返回 `-1`:表示物品不存在。
示例代码:
```lua
local result = hasitem(actor, makeIndex)
if result == 0 then
print("物品装备在身上")
elseif result == 1 then
print("物品存在于背包")
elseif result == -1 then
print("物品不存在")
end
```
← 返回问答库