Walk, or take the flight?
find_distance measures a walk without sending the route back: about 200 bytes, a few milliseconds on the server.
Ask all your options at once and compare.
-- options: { { name = "walk", from = me, to = goal }, { name = "flight", from = me, to = flight_master }, ... }
local function measure_all(options, on_done)
local client = _G.AXIOM_NAV and _G.AXIOM_NAV.client
if not client then return end
local left = #options
for _, o in ipairs(options) do
client:find_distance(o.from, o.to, function(ok, d)
if ok then
if d.reached then
o.yd = d.distance
elseif d.cut then
o.yd = d.distance + d.left -- longer than one search: an estimate
end -- else: no way on foot, o.yd stays nil
end
left = left - 1
if left == 0 then on_done(options) end
end, { roads = true })
end
end
local me = core.object_manager.get_local_player():get_position()
local goal = { x = -3792.2, y = -783.8, z = 0 } -- z = 0 is fine: the server finds the floor
local flight_master = { x = -8836.0, y = 490.0, z = 109.6 }
measure_all({
{ name = "walk", from = me, to = goal },
{ name = "to flight master", from = me, to = flight_master },
}, function(results)
for _, o in ipairs(results) do
core.log(("%s: %s"):format(o.name, o.yd and ("%.0f yd"):format(o.yd) or "no way on foot"))
end
end)Notes
- 8 go out at a time from each game; the rest wait their turn in the plugin. 50 asks took under a second.
- Answers are remembered on the server for 6 hours, for every player (
d.cached). - Measured the way
move_towould walk it: pass the sameroadsyou will walk with. d.portalis set when the walk goes through one of the game's pads (Darnassus, the Wizard's Sanctum).