Hunting Buddy Plugins - elanthia-online/dr-scripts GitHub Wiki

Hunting-Buddy Plugins

hunting-buddy supports the shared Script Plugin System - read that page first for how plugins are written, loaded, and dispatched. This page lists the hooks hunting-buddy fires.

Plugin file scripts/custom/hunting-buddy-plugin-<name>.rb
Register with HuntingBuddy.register_plugin(MyPlugin.new)
Global handle $HUNTING_BUDDY
Debug flag $debug_mode_hunting

Hook catalog

In the signatures below, buddy is the live HuntingBuddy instance. Kind is either decision (first non-nil return wins) or notify (all plugins called, return ignored).

Hook Kind Fires
after_initialize(buddy) notify Once, when hunting-buddy has finished constructing
find_room(buddy, zones_to_search, waiting_room) decision When hunting-buddy needs to choose a room to hunt in
before_hunt(buddy, hunting_room:) notify Once per hunt, before combat-trainer starts
hunt_tick(buddy, counter:) decision Once per hunt-loop iteration
hunt_status(buddy, counter:, duration:) notify On the periodic status update: ticks 0, 60, 120... (roughly once a minute)
after_hunt(buddy, hunting_room:, counter:) notify Once per hunt, after the hunt loop ends. Always paired with before_hunt: if the hunt is called off right after before_hunt (e.g. a plugin calls buddy.stop_hunting), it fires with counter: 0
cleanup(buddy) notify Once, when hunting-buddy exits (normally or killed)

Decision hooks:

  • find_room - return a non-nil result to take over room selection (this becomes hunting-buddy's find_hunting_room? result); return nil to let hunting-buddy find the room itself. zones_to_search and waiting_room are the context hunting-buddy computed.
  • hunt_tick - return :break to stop the hunt loop. counter is the number of completed ticks: 0 on the first call, then 1, 2, ... (about one per second).

Implement only the hooks you need, and tolerate new ones appearing over time.

State plugins can use

Accessor
buddy.settings Character settings (read-only)
buddy.hunting_info The hunts being run, from every hunting file
buddy.hunting_data, buddy.hunting_zones data/base-hunting.yaml, and its hunting zones
buddy.hunt_stop_reason Why the last hunt ended: :bleeding, :boxes_full, :no_moons, :high_skills, :low_skills, :manual_stop, :too_injured (the room search found you too injured to search), :duration, :burgle_time, :familiar_drag or :encumbrance. Reset at the start of each hunt; nil when your hunt_tick returned :break. Read it in after_hunt.
buddy.stopped_for_bleeding Set when hunting stopped because you were bleeding
buddy.my_room_claim, buddy.need_relocation Free for plugins to use; hunting-buddy itself never reads them
buddy.stop_hunting, buddy.next_hunt End the current hunt and skip the rest / move on to the next

A plugin file that raises (or has a syntax error) when loaded is reported and skipped; the other plugins still load. Likewise a hook that raises -- including NotImplementedError -- is skipped (logged with $debug_mode_hunting) and the other plugins still get the hook.

Example: log the hunt lifecycle

# scripts/custom/hunting-buddy-plugin-lifelog.rb
class LifeLogPlugin
  def after_initialize(_buddy)
    echo '[lifelog] hunting-buddy loaded'
  end

  def before_hunt(_buddy, hunting_room:)
    echo "[lifelog] starting hunt in room #{hunting_room}"
  end

  def after_hunt(_buddy, hunting_room:, counter:)
    echo "[lifelog] hunt ended after #{counter} ticks in room #{hunting_room}"
  end
end

HuntingBuddy.register_plugin(LifeLogPlugin.new)
⚠️ **GitHub.com Fallback** ⚠️