Skip to content

Exports

导出函数 (Exports)

BUPA AnimPos 提供了三个客户端导出函数,以便其他资源可以通过代码驱动该工具。所有函数均在资源名称 bupa-animpos 下运行。

Open

打开该工具。这会运行完整的检查流程——包括使用中状态、冷却时间、权限、状态限制以及 Config.CanUse 钩子——其效果与玩家使用指令或按键完全相同。如果工具成功打开,则返回 true,否则返回 false

client
local opened = exports['bupa-animpos']:Open()
if opened then
    print('Positioning mode started')
end

Close

如果工具当前处于活动状态,则请求将其关闭。这类似于按下取消键——角色将被恢复到其初始位置和朝向。

client
exports['bupa-animpos']:Close()

IsActive

返回一个布尔值,指示本地玩家的定位模式当前是否处于打开状态。

client
if exports['bupa-animpos']:IsActive() then
    -- e.g. block another interaction while the tool is open
end

示例 — 与动作菜单配合使用

client
-- After playing an emote, let the player nudge it into place
RegisterCommand('fixpos', function()
    if not exports['bupa-animpos']:IsActive() then
        exports['bupa-animpos']:Open()
    end
end)

相关 — CanUse 配置钩子

除了导出函数之外,Config.CanUse 是一个客户端钩子,会在每次尝试打开时运行(包括通过 Open() 调用)。返回 false 可阻止打开,并可选择返回一个消息字符串以显示给玩家。这是用于服务器特定限制逻辑(如战斗、伤害、自定义状态)的理想位置。

config.lua
Config.CanUse = function()
    -- return false, 'You cannot do this right now!'
    return true
end