属性获取函数
GetQuality
获取物品的品质等级
item:GetQuality()
-- 根据物品品质给予不同奖励
local quality = item:GetQuality()
local qualityNames = {
[0] = "灰色",
[1] = "白色",
[2] = "绿色",
[3] = "蓝色",
[4] = "紫色",
[5] = "橙色"
}
if quality >= 4 then -- 紫色及以上
player:SendBroadcastMessage("恭喜获得" .. qualityNames[quality] .. "品质物品!")
end
GetItemLink
获取物品的聊天链接格式
item:GetItemLink()
-- 在聊天中显示物品链接
local itemLink = item:GetItemLink()
player:SendBroadcastMessage("你获得了:" .. itemLink)
物品状态检查函数
IsSoulBound
检查物品是否已绑定
item:IsSoulBound()
-- 检查物品绑定状态
if item:IsSoulBound() then
player:SendBroadcastMessage("这个物品已经绑定,无法交易")
else
player:SendBroadcastMessage("这个物品可以自由交易")
end
HasEnchantment
检查物品是否有附魔
item:HasEnchantment(enchantId)
-- 检查武器附魔
if item:HasEnchantment(1894) then -- 十字军附魔
player:SendBroadcastMessage("武器拥有十字军附魔效果")
end
GetOwner
获取物品的拥有者
item:GetOwner()
-- 获取物品拥有者
local owner = item:GetOwner()
if owner and owner:IsPlayer() then
local player = owner:ToPlayer()
print("物品拥有者: " .. player:GetName())
end
物品使用和效果函数
GetSpellId
获取物品使用时触发的法术ID
item:GetSpellId(index)
-- 获取物品法术效果
local spellId = item:GetSpellId(0) -- 获取第一个法术效果
if spellId and spellId > 0 then
player:SendBroadcastMessage("物品使用效果: 法术ID " .. spellId)
end
GetItemLevel
获取物品等级
item:GetItemLevel()
-- 检查物品等级
local itemLevel = item:GetItemLevel()
local playerLevel = player:GetLevel()
if itemLevel > playerLevel + 10 then
player:SendBroadcastMessage("这个物品等级太高,你暂时无法有效使用")
else
player:SendBroadcastMessage("物品等级: " .. itemLevel .. ",适合你使用")
end
GetRequiredLevel
获取物品需求等级
item:GetRequiredLevel()
-- 检查物品需求等级
local requiredLevel = item:GetRequiredLevel()
local playerLevel = player:GetLevel()
if playerLevel < requiredLevel then
player:SendBroadcastMessage("需要等级 " .. requiredLevel .. " 才能使用此物品")
else
player:SendBroadcastMessage("你可以使用这个物品")
end
物品增强和附魔函数
AddEnchantment
为物品添加附魔效果
item:AddEnchantment(enchantId, duration)
-- 为武器添加附魔
local weapon = player:GetItemByPos(255, 15) -- 获取主手武器
if weapon then
weapon:AddEnchantment(1894, 3600) -- 添加十字军附魔,持续1小时
player:SendBroadcastMessage("武器附魔成功!")
end
-- 根据物品类型添加不同附魔
local itemClass = item:GetClass()
if itemClass == 2 then -- 武器
item:AddEnchantment(1894, 7200) -- 武器附魔
elseif itemClass == 4 then -- 护甲
item:AddEnchantment(2564, 7200) -- 护甲附魔
end
ClearEnchantment
清除物品的附魔效果
item:ClearEnchantment(enchantSlot)
-- 清除所有附魔
item:ClearEnchantment(0) -- 清除临时附魔
item:ClearEnchantment(1) -- 清除永久附魔
player:SendBroadcastMessage("物品附魔已清除")
SetDurability
设置物品的耐久度
item:SetDurability(durability)
-- 修复物品耐久度
local maxDurability = item:GetMaxDurability()
item:SetDurability(maxDurability)
player:SendBroadcastMessage("物品已完全修复!")
-- 根据条件设置耐久度
local currentDurability = item:GetDurability()
if currentDurability < maxDurability * 0.5 then
item:SetDurability(maxDurability)
player:SendBroadcastMessage("低耐久物品已自动修复")
end
物品创建和修改函数
SetText
设置物品的自定义文本(如书籍内容)
item:SetText(text)
-- 创建自定义书籍
local book = player:AddItem(6245, 1) -- 添加书籍物品
if book then
local content = "这是一本记录冒险经历的日记。\\n\\n" ..
"今天我在暴风城遇到了一位神秘的法师...\\n" ..
"他告诉我关于远古魔法的秘密..."
book:SetText(content)
player:SendBroadcastMessage("获得了一本神秘的日记!")
end
SetFlag
设置物品的特殊标志
item:SetFlag(flag)
-- 设置物品为任务物品
item:SetFlag(1) -- ITEM_FLAG_QUEST_ITEM
-- 设置物品为唯一物品
item:SetFlag(524288) -- ITEM_FLAG_UNIQUE
-- 设置物品不可交易
item:SetFlag(2) -- ITEM_FLAG_CONJURED
player:SendBroadcastMessage("物品属性已更新")
SaveToDB
将物品数据保存到数据库
item:SaveToDB()
-- 修改物品后保存到数据库
item:SetCount(10)
item:SetDurability(item:GetMaxDurability())
item:SaveToDB()
print("物品数据已保存到数据库")
GetClass
获取物品的类型
item:GetClass()
-- 根据物品类型执行不同逻辑
local itemClass = item:GetClass()
local classNames = {
[0] = "消耗品", [1] = "容器", [2] = "武器", [3] = "宝石",
[4] = "护甲", [5] = "试剂", [6] = "射击武器", [7] = "商品",
[8] = "通用", [9] = "配方", [10] = "钱币", [11] = "箭袋",
[12] = "任务物品", [13] = "钥匙", [14] = "永久", [15] = "杂项"
}
local className = classNames[itemClass] or "未知"
player:SendBroadcastMessage("物品类型: " .. className)
-- 根据类型给予不同处理
if itemClass == 2 then -- 武器
player:SendBroadcastMessage("这是一件武器,小心使用!")
elseif itemClass == 4 then -- 护甲
player:SendBroadcastMessage("这件护甲能保护你的安全")
end
GetSubClass
获取物品的子类型
item:GetSubClass()
-- 检查武器子类型
local itemClass = item:GetClass()
local itemSubClass = item:GetSubClass()
if itemClass == 2 then -- 武器类
local weaponTypes = {
[0] = "斧", [1] = "斧", [2] = "弓", [3] = "枪",
[4] = "锤", [5] = "锤", [6] = "长柄武器", [7] = "剑",
[8] = "剑", [9] = "废弃", [10] = "法杖", [11] = "奇异",
[12] = "奇异", [13] = "拳套", [14] = "杂项", [15] = "匕首",
[16] = "投掷武器", [17] = "矛", [18] = "弩", [19] = "魔杖",
[20] = "渔竿"
}
local weaponType = weaponTypes[itemSubClass] or "未知武器"
player:SendBroadcastMessage("武器类型: " .. weaponType)
end
GetMaxDurability
获取物品的最大耐久度
item:GetMaxDurability()
-- 检查物品耐久度状态
local currentDurability = item:GetDurability()
local maxDurability = item:GetMaxDurability()
if maxDurability > 0 then
local durabilityPercent = (currentDurability / maxDurability) * 100
if durabilityPercent < 25 then
player:SendBroadcastMessage("警告:物品耐久度严重不足!")
player:SendBroadcastMessage("当前耐久度: " .. currentDurability .. "/" .. maxDurability)
elseif durabilityPercent < 50 then
player:SendBroadcastMessage("提示:物品需要修理")
end
else
player:SendBroadcastMessage("此物品没有耐久度")
end
GetDurability
获取物品的当前耐久度
item:GetDurability()
-- 自动修理系统
local function AutoRepairItem(item, player)
local currentDurability = item:GetDurability()
local maxDurability = item:GetMaxDurability()
if maxDurability > 0 and currentDurability < maxDurability then
local repairCost = (maxDurability - currentDurability) * 10 -- 每点耐久10铜币
if player:GetCoinage() >= repairCost then
player:ModifyMoney(-repairCost)
item:SetDurability(maxDurability)
player:SendBroadcastMessage("物品已修理,花费: " .. repairCost .. " 铜币")
else
player:SendBroadcastMessage("金币不足,无法修理物品")
end
end
end
物品属性和统计函数
GetStatType
获取物品的属性类型
item:GetStatType(index)
-- 分析物品属性
local function AnalyzeItemStats(item)
local statNames = {
[0] = "法力", [1] = "生命", [2] = "敏捷", [3] = "力量",
[4] = "智力", [5] = "精神", [6] = "耐力", [7] = "武器技能",
[12] = "防御等级", [13] = "闪避等级", [14] = "格挡等级",
[15] = "命中等级", [16] = "爆击等级", [17] = "命中回避等级",
[18] = "爆击回避等级", [19] = "韧性等级", [20] = "急速等级"
}
player:SendBroadcastMessage("=== 物品属性分析 ===")
for i = 0, 9 do -- 检查前10个属性槽
local statType = item:GetStatType(i)
local statValue = item:GetStatValue(i)
if statType and statValue and statValue > 0 then
local statName = statNames[statType] or ("未知属性" .. statType)
player:SendBroadcastMessage(statName .. ": +" .. statValue)
end
end
end
GetStatValue
获取物品指定属性的数值
item:GetStatValue(index)
-- 计算物品总属性加成
local function CalculateItemBonus(item)
local totalStats = {
strength = 0, agility = 0, intellect = 0,
spirit = 0, stamina = 0
}
for i = 0, 9 do
local statType = item:GetStatType(i)
local statValue = item:GetStatValue(i)
if statType and statValue and statValue > 0 then
if statType == 3 then -- 力量
totalStats.strength = totalStats.strength + statValue
elseif statType == 2 then -- 敏捷
totalStats.agility = totalStats.agility + statValue
elseif statType == 4 then -- 智力
totalStats.intellect = totalStats.intellect + statValue
elseif statType == 5 then -- 精神
totalStats.spirit = totalStats.spirit + statValue
elseif statType == 6 then -- 耐力
totalStats.stamina = totalStats.stamina + statValue
end
end
end
return totalStats
end
GetBagSlot
获取物品所在的背包槽位
item:GetBagSlot()
-- 物品位置管理
local function GetItemLocation(item)
local bagSlot = item:GetBagSlot()
local slot = item:GetSlot()
local locationNames = {
[255] = "装备栏",
[0] = "主背包",
[1] = "背包1",
[2] = "背包2",
[3] = "背包3",
[4] = "背包4"
}
local locationName = locationNames[bagSlot] or ("背包" .. bagSlot)
player:SendBroadcastMessage("物品位置: " .. locationName .. " 第" .. slot .. "格")
-- 特殊位置处理
if bagSlot == 255 then
local equipSlotNames = {
[0] = "头部", [1] = "颈部", [2] = "肩部", [3] = "衬衣",
[4] = "胸部", [5] = "腰带", [6] = "腿部", [7] = "脚部",
[8] = "手腕", [9] = "手套", [10] = "戒指1", [11] = "戒指2",
[12] = "饰品1", [13] = "饰品2", [14] = "斗篷", [15] = "主手",
[16] = "副手", [17] = "远程", [18] = "外袍"
}
local equipSlotName = equipSlotNames[slot] or ("装备槽" .. slot)
player:SendBroadcastMessage("装备部位: " .. equipSlotName)
end
end
GetSlot
获取物品在背包中的具体槽位
item:GetSlot()
-- 背包整理功能
local function OrganizeBag(player, bagSlot)
local items = {}
-- 收集背包中的所有物品
for slot = 0, 35 do -- 假设背包有36个槽位
local item = player:GetItemByPos(bagSlot, slot)
if item then
table.insert(items, {
item = item,
entry = item:GetEntry(),
quality = item:GetQuality(),
slot = slot
})
end
end
-- 按品质和ID排序
table.sort(items, function(a, b)
if a.quality ~= b.quality then
return a.quality > b.quality -- 高品质在前
else
return a.entry < b.entry -- 相同品质按ID排序
end
end)
player:SendBroadcastMessage("背包已整理完成!")
end