参考 › 函数参考 › Platform

Platform.groups.GetUnitGroupMembership

公共

调用方式

addon.Platform:GetUnitGroupMembership(unit, raidOnly)

可直接通过 addon 使用,无需依赖项。

作用

读取指定单位是否属于玩家的小队或团队。raidOnly 为 true 时只查询 UnitInRaid;否则 UnitInParty 结果为 true 时直接返回,为 false 时继续查询 UnitInRaid,未知时保持为不可用。可读的 nil 团队索引表示 false;整数团队索引 1..40 表示 true。名称会原样传给原生 API;原生 API 是否接受名称查询需视客户端而定。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。
unitstring可读的非空单位标识或原生可识别的名称,原样传递。
raidOnlyboolean | nil为 true 时只检查团队成员身份;为 false 或 nil 时先检查小队再检查团队。

返回值

1boolean | nil观测到的成员身份;不可用时为 nil。
2string | nil结果为 nil 时的验证或可用性原因。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
UnitInParty经典旧世TBC 周年版经典进阶服永久服正式服
UnitInRaid经典旧世TBC 周年版经典进阶服永久服正式服
canaccessvalue经典旧世TBC 周年版经典进阶服永久服正式服

秘密值(正式服和永久服)

在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。

示例

local member = addon.Platform:GetUnitGroupMembership("focus", false)
if member == nil then return nil end
return member

源码

Platform/groups.lua,第 45 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Platform.groups.GetUnitGroupMembership(self, unit, raidOnly)
    if not self:CanReadValue(unit) or not self:CanReadValue(raidOnly) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' or #unit>512 or unit:find('[%z\1-\31\127]') then return nil,'invalid-unit' end
    if raidOnly~=nil and type(raidOnly)~='boolean' then return nil,'invalid-group-query' end
    if self:GetClientFamily()=='unknown' then return nil,'unsupported-client' end
    if not raidOnly then
        if type(UnitInParty)~='function' then return nil,'missing-api' end
        local ok,member=pcall(UnitInParty,unit)
        if not ok then return nil,'api-error' end
        if not self:CanReadValue(member) then return nil,'restricted-value' end
        if member==nil then return nil,'group-data-unavailable' end
        if type(member)~='boolean' then return nil,'invalid-api-result' end
        if member then return true end
    end
    if type(UnitInRaid)~='function' then return nil,'missing-api' end
    local ok,index=pcall(UnitInRaid,unit)
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(index) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(index) then return nil,'restricted-value' end
    -- The pinned native API returns an optional raid index: nil is nonmember.
    if index==nil then return false end
    if type(index)~='number' or index<1 or index>40 or index%1~=0 then return nil,'invalid-api-result' end
    return true

返回函数参考