调用方式
addon.Platform:GetPlayerMovementObservation()
可直接通过 addon 使用,无需依赖项。
作用
在受支持且可读的客户端上观测玩家当前的移动速度。这只针对 player 查询 GetUnitSpeed,不检测其他单位,也不重定向载具所有权。零表示静止;正的有限小数速度仍然有效。缺失、失败、受限或格式错误的观测会返回 nil 及原因。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
self | RMPlatform | Rotation Master 平台适配器(使用冒号调用时隐含传入)。 |
返回值
| 1 | table | nil | 全新的可读记录,包含有限的非负速度;不可用时为 nil。 |
|---|---|---|
| 2 | string | nil | 移动观测为 nil 时的策略或可用性原因。 |
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
- 该版本不可用(原因见提示)
- 仅在暴雪的弃用兼容层开启时
| 游戏 API | |||||
|---|---|---|---|---|---|
GetUnitSpeed | |||||
canaccessvalue |
秘密值(正式服和永久服)
在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。
示例
local movement = addon.Platform:GetPlayerMovementObservation()
if not movement then return nil end
return movement.speed > 0源码
Platform/player_movement.lua,第 15 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Platform.player_movement.GetPlayerMovementObservation(self)
local policy=self:GetCombatDataPolicy()
if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
if type(GetUnitSpeed)~='function' then return nil,'missing-api' end
local ok,speed=pcall(GetUnitSpeed,'player')
if not ok then return nil,'api-error' end
if not self:CanReadValue(speed) then return nil,'restricted-value' end
if canaccessvalue and not canaccessvalue(speed) then return nil,'restricted-value' end
if speed==nil then return nil,'movement-data-unavailable' end
if type(speed)~='number' or speed~=speed or speed==math.huge or speed==-math.huge or speed<0 then return nil,'invalid-api-result' end
return {speed=speed}




