本页介绍读取 / 创建 / 修改物品的函数共用的物品表格式,以及 Item 表中创建物品的函数。物品类型的信息(名称、尺寸、分组)见页面物品:类型信息(物品:物品类型信息);将物品原样传给网站的函数见页面物品:网站记录(物品:网站记录)。
物品表(item table)
读取函数(Player.GetItem、Warehouse.GetItem、EventInventory.GetItem、MuunInventory.GetItem、Item.GetGroundItem)返回包含下列字段的表。创建 / 修改函数(Item.Give、Item.Drop、Item.GremoryAdd、Inventory.SetItem)接收字段名相同的表。
| 字段 | 类型 | 读取时 | 创建 / 修改时 |
|---|---|---|---|
Index | integer | 物品代码(分组 * 512 + 序号) | 创建时必填;必须是 ItemList 中存在的代码。无法通过 Inventory.SetItem 修改 |
Serial | number | 序列号 | 不使用 |
Level | integer | 强化等级 + | 限制在 0 到该物品的最大等级之间 |
Durability | number | 耐久度 / 堆叠数量 | 0 到 255。0 或 255 = 默认耐久度 |
Skill | integer | 是否带技能(0 / 1) | 限制在 0 到 1 |
Luck | integer | 是否带幸运(0 / 1) | 限制在 0 到 1 |
Option | integer | 附加选项 | 0 到 255 |
Exc | integer | Excellent 属性(位掩码) | 0 到 255 |
Ancient | integer | 套装 / Ancient 物品属性 | 0 到 255 |
Harmony | integer | Harmony 选项(Jewel of Harmony) | 0 到 255 |
Option380 | integer | 380 选项 | 0 到 255 |
SocketBonus | integer | 镶嵌奖励(socket bonus) | 0 到 255,默认 255 |
ExpireDate | number | 到期时间点(时间戳);0 = 无期限 | 不使用(创建时请使用 Duration) |
Sockets | table | 5 个元素的表(索引 1 到 5) | 5 个元素的表 |
Duration | integer | (读取时不存在) | 物品自创建起算的有效期,单位为秒,最长 10 年。0 = 不设期限 |
Count | integer | (读取时不存在) | 要创建的数量(见各函数) |
Sockets 的每个元素:-1 = 没有孔位,254 = 空孔位,其他值 = 已镶嵌到该孔位中的 socket 代码。创建时缺少的字段使用上表中的默认值。
Skill 和 Luck 字段还有旧式名称 Option1 和 Option2;Option = Option3;Exc = NewOption;Ancient = SetOption;Harmony = JoHOption;Option380 = ["380Option"];Sockets = SocketOption1 到 SocketOption5;SocketBonus = SocketOptionBonus;ExpireDate = DurationTime。旧名称只存在于由简称函数返回的表中(InventoryGetItemTable、EventInventoryGetItemTable、MuunInventoryGetItemTable、MapGetItemTable),并且在传给 InventorySetItemTable 的表中也会被接受。给角色发放物品
Item.Give
创建物品并放入角色的背包。创建过程是异步的(GameServer 先向数据库申请序列号,然后才添加到背包),因此函数会先检查空位,并按剩余空间限制数量。
Item.Give(aIndex, item) -> integer
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 角色索引 |
item | table | 物品表(见上文)。Count 为 1 到 50(默认 1) |
返回:已请求创建的物品数量;如果空间不足、表有误(代码不存在)、角色正在交易 / 打开着窗口或条件不满足,则返回 0。按类型区分的规则:
- 活动背包物品:需要活动背包中有空位,始终只创建 1 个。
- Muun 物品:需要 Muun 背包中有空格,始终只创建 1 个。
- 普通物品:至少需要能放下 1 个的空间;
Count受空格数除以物品面积(宽 x 高)的限制。
简称:ItemGiveEx(aIndex, item, level, dur, skill, luck, option, exc, ancient, harmony, opt380, s1, s2, s3, s4, s5, socketBonus, duration),以及 CreateItem(useType = 1, aIndex, ...)。建议先调用 Player.CheckItemAction。
local given = Item.Give(aIndex, { Index = 7181, Count = 5 })
if given == 0 then
Message.Send(aIndex, 1, "背包已满")
end
-- 带属性的物品,有效期 7 天
Item.Give(aIndex, { Index = 3 * 512 + 5, Level = 9, Luck = 1, Option = 4, Exc = 1, Duration = 7 * 86400 })
Item.GiveBag
打开一个随机物品包(ItemBag),并在角色所站的位置将物品放入角色背包。
Item.GiveBag(aIndex, bag) -> boolean
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 角色索引 |
bag | integer 或 string | ItemBag 的编号(GUID)或名称 |
返回:已执行该物品包时返回 true;如果未找到物品包、角色正在交易或条件不满足,则返回 false。简称:ItemGive。
Item.GiveBag 不会检查背包是否有空位。任何无法加入背包的物品(背包已满)都不会被创建:既不会掉落在地上,也不会转入 Gremory 箱。如果需要确保完整收到奖励,请先检查空位,或使用 Item.GremoryAdd 发放奖励。Item.GiveBag(aIndex, "DailyReward")
Item.DropBag
打开一个随机物品包,并让物品掉落在地上。该角色是这些物品的所有者。
Item.DropBag(aIndex, bag [, map, x, y]) -> boolean
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 角色索引 |
bag | integer 或 string | ItemBag 的编号(GUID)或名称 |
map | integer | 掉落的地图;默认是角色所在的地图 |
x, y | integer | 掉落坐标(限制在 0 到 255 之间);默认是角色的坐标 |
返回:已执行时返回 true;如果未找到物品包、地图不存在或条件不满足,则返回 false。简称:ItemDrop(aIndex, map, x, y, bag)。
Item.DropBag(aIndex, "BossReward", Object.GetMap(aIndex), Object.GetX(aIndex), Object.GetY(aIndex))
掉落在地上的物品
Item.Drop
让一件物品掉落在地上。
Item.Drop(map, x, y, item [, ownerIndex]) -> boolean
| 参数 | 类型 | 说明 |
|---|---|---|
map | integer | 地图编号(必须存在于此 GameServer 上) |
x, y | integer | 掉落坐标(限制在 0 到 255 之间) |
item | table | 物品表(见上文)。Count 字段不使用:每次调用掉落 1 件物品 |
ownerIndex | integer | 物品所有者的角色 / 怪物索引(只有该所有者可以拾取)。-1 或省略 = 任何人都可以拾取 |
返回:已请求掉落时返回 true;如果地图不存在、表有误或脚本处于受限模式,则返回 false。简称:ItemDropEx(aIndex, map, x, y, item, level, dur, skill, luck, option, exc, ancient, harmony, opt380, s1, s2, s3, s4, s5, socketBonus, duration)(aIndex 为所有者),以及 CreateItem(useType = 0, ...)。
当存在有效的 ownerIndex 时,只有所有者可以拾取该物品,并且这项权限不会过期(物品会一直留在原地,直到被拾取,或按物品在地面上的存在时间消失);其他玩家无法拾取,即使在同一队伍中也不行。管理员账号不受此限制。
Item.Drop(MAP_LORENCIA, 130, 130, { Index = 14 * 512 + 13 }) -- 一个 Jewel of Bless 掉落在 Lorencia 中央
Item.GetGroundItem
读取地面上某件物品的信息。
Item.GetGroundItem(map, itemIndex) -> table | nil
| 参数 | 类型 | 说明 |
|---|---|---|
map | integer | 地图编号 |
itemIndex | integer | 物品在地图上的索引(从 0 到 Object.GetMaxItem() - 1) |
返回:物品表,另外多出 X 和 Y 两个字段(位置);如果该位置没有物品或参数有误,则返回 nil。简称:MapGetItemTable(map, index)(表中还带有旧式字段名)。
local it = Item.GetGroundItem(MAP_LORENCIA, 0)
if it then Log.Add("Item " .. it.Index .. " 位于 " .. it.X .. "," .. it.Y) end
Gremory 箱
Item.GremoryAdd
将物品添加到角色的 Gremory 箱中(用于发放奖励时不需要背包有空位的场合)。
Item.GremoryAdd(aIndex, item) -> boolean
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 角色索引 |
item | table | 物品表(见上文),外加下面两个专用字段。Count 为 1 到 100(默认 1) |
此函数的两个专用字段:
| 字段 | 值 | 含义 |
|---|---|---|
Storage | 1(默认)、2、3 | 存放位置:1 = 角色的箱子,2 = 账号的箱子,3 = Personal Store 标签页(150 格,用于挂售的物品)。2 和 3 以外的值按 1 处理 |
Reward | integer 0 到 255 | 箱子中显示的奖励来源。默认为“GM 奖励”来源(当 Storage = 3 时默认为活动来源) |
返回:已请求添加时返回 true;如果角色不满足条件、item 不是表或物品代码不存在,则返回 false。该函数不检查箱子是否还有空位:如有需要,请先使用 Item.GremoryFreeSlots。
简称:InsertItem_GremoryCaseEx(aIndex, storage, reward, index, level, dur, skill, luck, option, ancient, opt380, harmony, exc, unused, s1, s2, s3, s4, s5, socketBonus, duration, count) 和 InsertItem_GremoryCase(aIndex, storage, reward, index, level, dur, skill, luck, option, ancient, isSocket, isElemental, muunEvo, exc, masteryExe, s1, s2, s3, s4, s5, socketBonus, receiptDuration, duration, count)。对于第二个简称,receiptDuration 的值会被用作 Duration,而 duration 被忽略;isSocket、isElemental、muunEvo、masteryExe 这几个参数被忽略。
当 Duration 字段(秒)大于 0 时,它设置的是物品的使用期限(从添加到箱子的那一刻起计算,玩家把它取出到背包时保持不变);0 = 物品没有使用期限。Duration 不是物品在箱子中保存的时间。
Item.GremoryAdd(aIndex, { Index = 14 * 512 + 13, Count = 10, Storage = 2 })
Item.GremoryFreeSlots
返回 Gremory 箱剩余的空格数。
Item.GremoryFreeSlots(aIndex [, storage]) -> integer
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 角色索引 |
storage | integer | 1 = 角色箱(默认),2 = 账号箱,3 = Personal Store 标签页 |
返回:空格数;无效时返回 0。简称:GCTotalFreeSlotCount(aIndex, storage)。
if Item.GremoryFreeSlots(aIndex, 1) >= 3 then
Item.GremoryAdd(aIndex, { Index = 14 * 512 + 13, Count = 3 })
end
Item.RandomLevel
返回一个位于 minLevel 到 maxLevel 范围内(含两端)的随机物品等级(+)。在自行构造带随机等级的奖励时使用。
Item.RandomLevel(minLevel, maxLevel) -> integer
| 参数 | 类型 | 说明 |
|---|---|---|
minLevel | integer | 最低等级(限制在 0 到物品最大等级 15 之间) |
maxLevel | integer | 最高等级(限制在 0 到 15 之间) |
返回:从 minLevel 到 maxLevel 的整数。如果 minLevel 大于 maxLevel,则两个数会自动交换;缺少参数时按 0 处理。简称:GetBagItemLevel(min, max)。
-- 赠送 1 把剑(分组 0,编号 0),等级随机为 +7 到 +9
local level = Item.RandomLevel(7, 9)
Item.Give(aIndex, { Index = 0 * 512 + 0, Level = level })