Skip to content

PlayerState

APHONIC edited this page Sep 15, 2026 · 2 revisions

Player State

PlayerState.lua: busy-state checks and movement/teleport trackers, for an addon that needs to delay an action until the player is free.

LibAPH.IsPlayerCrafting() / LibAPH.IsPlayerInteracting() / LibAPH.IsPlayerInMenu()

Individual busy-state checks: crafting interaction active, interacting with an object/NPC, or the HUD/HUD-UI scene isn't showing (i.e. a menu is open).

LibAPH.CheckBusyReason(checks)

Runs a list of checks in order and returns the first one that applies, letting an addon combine several independent busy conditions into one decision.

Signature: checks is { { enabled, check, reasonKey, delayMs }, ... }. Returns the first entry whose enabled isn't false and whose check() returns true: isBusy, reasonKey, delayMs.

function MyAddon.is_busy()
    return LibAPH.CheckBusyReason({
        { enabled = MyAddon.settings.busy_check_crafting, check = LibAPH.IsPlayerCrafting,
          reasonKey = MyAddon.L("LABEL_CRAFTING"), delayMs = (MyAddon.settings.delay_crafting or 2) * 1000 },
        { enabled = MyAddon.settings.busy_check_interacting, check = LibAPH.IsPlayerInteracting,
          reasonKey = MyAddon.L("LABEL_INTERACTING"), delayMs = (MyAddon.settings.delay_in_menu or 5) * 1000 },
        { enabled = MyAddon.settings.busy_check_menu, check = LibAPH.IsPlayerInMenu,
          reasonKey = MyAddon.L("LABEL_MENU"), delayMs = (MyAddon.settings.delay_in_menu or 5) * 1000 },
    })
end

LibAPH.CreateMovementTracker(opts)

Returns a tracker with :Update() (call every frame/tick) and :IsMoving(). Compares the player's world position against the last sample.

opts: throttleMs (default 100), threshold (default 0.5, the minimum distance to count as moved).

MyAddon.movement_tracker = LibAPH.CreateMovementTracker()
-- on your update tick:
MyAddon.movement_tracker:Update()
local is_moving = MyAddon.movement_tracker:IsMoving()

LibAPH.CreateTeleportTracker(opts)

Returns a tracker with :IsTeleporting() - true for opts.staleMs (default 3000) after any wayshrine travel, keep recall/travel, housing jump, friend jump, or accepted LFG ready-check.

Hooks the relevant game functions once, globally, the first time any tracker is created - a second CreateTeleportTracker() call doesn't hook again.

MyAddon.teleport_tracker = LibAPH.CreateTeleportTracker()
if MyAddon.teleport_tracker:IsTeleporting() then return end

Home · Getting Started

Clone this wiki locally