--[[
Created by Special.Ed
halfmoon formation - ported from kaens macro
Shout out to the homies:
Lads
Dannuic (my on again off again thing)
Knightly (no, i won't take that bet) (he knows math too)
Modded by Toadwart - 210906
Added the ranscatter formation, and a print function when first run
--]]
local mq = require('mq')
local formations = {}
local Output = function(msg) print('\aw[\atFormations :: Bind\aw] \a-t' .. msg) end
local Debug = function(msg) Output('[Debug] '..msg) end
local print_usage = function()
local vals = ''
Output('Usage: /formation <name>')
for k, v in pairs(formations) do vals = vals .. k .. ', ' end
Output('Available formations: ' .. vals:gsub(', $', ''))
end
-- add your formation code like this
-- note: they can take whatever arguments you want to pass in
-- formations.example = function(dist, someRandomizeValue, debug, etc...)
-- -- do the things
-- end
formations.halfmoon = function(dist, debug)
-- set defaults
dist = dist or 10
if debug == 'on' then
Debug('Debugging On')
debug = true
else
Debug('Debugging Off')
debug = false
end
-- check inputs / print formation usage
if tonumber(dist) == nil then
Output('Usage: /formation halfmoon [dist = #] [debug = on|off]')
return
end
-- calc the things
for i = 1, mq.TLO.Group.Members() do
local y = mq.TLO.Me.Y() + (dist * math.sin(((i * 36) + (mq.TLO.Me.Heading.Degrees() - 198)) / (180 / math.pi)))
local x = mq.TLO.Me.X() + (dist * math.cos(((i * 36) + (mq.TLO.Me.Heading.Degrees() - 198)) / (180 / math.pi)))
local cmd = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(i).Name(), y, x)
mq.cmd[cmd]()
if debug then Debug('/'..cmd) end
mq.delay(100)
end
end
formations.ranscatter = function(dist, debug)
-- set defaults
if debug == 'on' then
Debug('Debugging On')
debug = true
else
Debug('Debugging Off')
debug = false
end
-- check inputs / print formation usage
if tonumber(dist) == nil then
Output('Usage: /formation ranscatter [dist = #] [debug = on|off]')
return
end
-- calc the things
if mq.TLO.Raid.Members() > 0 then
for i = 1, mq.TLO.Raid.Members() do
local dist = math.random(1,dist)
local dir = math.random(0,360)
local y = mq.TLO.Me.Y() + (dist * math.sin(dir))
local x = mq.TLO.Me.X() + (dist * math.cos(dir))
if debug then print("Dist: ",dist," Dir: ",dir," X: ",x," Y: ",y) end
local cmd = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Raid.Member(i).Name(), y, x)
mq.cmd[cmd]()
if debug then Debug('/'..cmd) end
mq.delay(100)
end
else
for i = 1, mq.TLO.Group.Members() do
local dist = math.random(1,dist)
local dir = math.random(0,360)
local y = mq.TLO.Me.Y() + (dist * math.sin(dir))
local x = mq.TLO.Me.X() + (dist * math.cos(dir))
if debug then print("Dist: ",dist," Dir: ",dir," X: ",x," Y: ",y) end
local cmd = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(i).Name(), y, x)
mq.cmd[cmd]()
if debug then Debug('/'..cmd) end
mq.delay(100)
end
end
end
--call usage when lua first run for a default message to user
print('\arAssumes that you are in a safe location to use a formation where doing so will not send\ax')
print('\arone of the toons over a cliff due to a large distance. The onus is on you to verify spread!\ax')
print_usage()
local bind_formation = function(name, ...)
local args = {...}
if formations[name] ~= nil then
formations[name](unpack(args))
else
print_usage()
end
end
mq.bind('/formation', bind_formation)
while true do mq.delay(100) end