formations.line = function(dist, debug)
-- set defaults
dist = dist or 10
if debug == 'on' then debug = true else debug = false end
-- check inputs / print formation usage
if tonumber(dist) == nil then
Output('Usage: /formation line [dist = 10] [debug on|off]')
return
end
-- calc the things
for i = 1, mq.TLO.Group.Members() do
local y = mq.TLO.Me.Y() + (i * dist)
local x = mq.TLO.Me.X()
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.trapezoid = function(base_dist, height_dist, debug)
-- set defaults
base_dist = base_dist or 20
height_dist = height_dist or 10
if debug == 'on' then debug = true else debug = false end
-- check inputs / print formation usage
if tonumber(base_dist) == nil or tonumber(height_dist) == nil then
Output('Usage: /formation trapezoid [base_dist = 20] [height_dist = 10] [debug on|off]')
return
end
local i = 1
local first_half = (mq.TLO.Group.Members() + 1) / 2
for y_offset = 0, height_dist, height_dist do
for x_offset = -(base_dist / 2), base_dist / 2, base_dist do
if i <= mq.TLO.Group.Members() then
local y = mq.TLO.Me.Y() + y_offset
local x = mq.TLO.Me.X() + x_offset
if i <= first_half then
x = x - (base_dist / 4)
else
x = x + (base_dist / 4)
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)
i = i + 1
end
end
end
end
formations.x = function(dist, debug)
dist = dist or 10
if debug == 'on' then debug = true else debug = false end
if tonumber(dist) == nil then
Output('Usage: /formation x [dist = 10] [debug on|off]')
return
end
local num_members = mq.TLO.Group.Members()
local x_center = mq.TLO.Me.X()
local y_center = mq.TLO.Me.Y()
local degree_inc = 360 / num_members
for i = 1, num_members do
local x = x_center + dist * math.cos((i * degree_inc - 90) * (math.pi / 180))
local y = y_center + dist * math.sin((i * degree_inc - 90) * (math.pi / 180))
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.hammer = function(dist, debug)
-- set defaults
dist = dist or 10
if debug == 'on' then debug = true else debug = false end
-- check inputs / print formation usage
if tonumber(dist) == nil then
Output('Usage: /formation hammer [dist = 10] [debug on|off]')
return
end
-- calculate positions for the front two members
local y1 = mq.TLO.Me.Y() + dist
local x1 = mq.TLO.Me.X() - (dist / 2)
local y2 = mq.TLO.Me.Y() + dist
local x2 = mq.TLO.Me.X() + (dist / 2)
-- calculate positions for the back three members
local y3 = mq.TLO.Me.Y() - (dist * 2)
local x3 = mq.TLO.Me.X() - dist
local y4 = mq.TLO.Me.Y() - (dist * 2)
local x4 = mq.TLO.Me.X()
local y5 = mq.TLO.Me.Y() - (dist * 2)
local x5 = mq.TLO.Me.X() + dist
-- move the front two members
local cmd1 = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(1).Name(), y1, x1)
mq.cmd[cmd1]()
if debug then Debug('/'..cmd1) end
local cmd2 = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(2).Name(), y2, x2)
mq.cmd[cmd2]()
if debug then Debug('/'..cmd2) end
-- move the back three members
local cmd3 = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(3).Name(), y3, x3)
mq.cmd[cmd3]()
if debug then Debug('/'..cmd3) end
local cmd4 = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(4).Name(), y4, x4)
mq.cmd[cmd4]()
if debug then Debug('/'..cmd4) end
local cmd5 = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(5).Name(), y5, x5)
mq.cmd[cmd5]()
if debug then Debug('/'..cmd5) end
mq.delay(100)
end
formations.star = function(dist, debug)
-- set defaults
dist = dist or 10
if debug == 'on' then debug = true else debug = false end
-- check inputs / print formation usage
if tonumber(dist) == nil then
Output('Usage: /formation star [dist = 10] [debug on|off]')
return
end
-- calc the things
for i = 1, mq.TLO.Group.Members() do
local angle = (i - 1) * 360 / mq.TLO.Group.Members() + (mq.TLO.Me.Heading.Degrees() - 180)
local y = mq.TLO.Me.Y() + dist * math.sin(angle / (180 / math.pi))
local x = mq.TLO.Me.X() + dist * math.cos(angle / (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.arrow = function(dist, debug)
dist = dist or 10
if debug == 'on' then debug = true else debug = false end
if tonumber(dist) == nil then
Output('Usage: /formation arrow [dist = 10] [debug on|off]')
return
end
-- position the first member behind you
local x = mq.TLO.Me.X() - dist
local y = mq.TLO.Me.Y()
local cmd = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(1).Name(), x, y)
mq.cmd[cmd]()
if debug then Debug('/'..cmd) end
mq.delay(100)
-- position the second member to your left
x = mq.TLO.Me.X() - (dist / 2)
y = mq.TLO.Me.Y() + (dist / 2)
cmd = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(2).Name(), x, y)
mq.cmd[cmd]()
if debug then Debug('/'..cmd) end
mq.delay(100)
-- position the third member to your right
x = mq.TLO.Me.X() + (dist / 2)
y = mq.TLO.Me.Y() + (dist / 2)
cmd = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(3).Name(), x, y)
mq.cmd[cmd]()
if debug then Debug('/'..cmd) end
mq.delay(100)
-- position the fourth member ahead of you
x = mq.TLO.Me.X() + dist
y = mq.TLO.Me.Y()
cmd = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(4).Name(), x, y)
mq.cmd[cmd]()
if debug then Debug('/'..cmd) end
mq.delay(100)
end
formations.diamond = function(dist, debug)
-- set defaults
dist = dist or 10
if debug == 'on' then debug = true else debug = false end
-- check inputs / print formation usage
if tonumber(dist) == nil then
Output('Usage: /formation diamond [dist = 10] [debug on|off]')
return
end
-- calc the things
for i = 1, mq.TLO.Group.Members() do
local angle = (i - 1) * 360 / mq.TLO.Group.Members() + mq.TLO.Me.Heading.Degrees() - 90
local y = mq.TLO.Me.Y() + (dist * math.sin(angle / (180 / math.pi)))
local x = mq.TLO.Me.X() + (dist * math.cos(angle / (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.triangle = function(dist, debug)
dist = dist or 10
if debug == 'on' then debug = true else debug = false end
if tonumber(dist) == nil then
Output('Usage: /formation triangle [dist = 10] [debug on|off]')
return
end
local x = mq.TLO.Me.X()
local y = mq.TLO.Me.Y()
local angle = 60
for i = 1, mq.TLO.Group.Members() do
local new_x = x + (dist * math.cos((angle * (i - 1)) / (180 / math.pi)))
local new_y = y + (dist * math.sin((angle * (i - 1)) / (180 / math.pi)))
local cmd = string.format('dex %s /moveto loc %.2f %.2f', mq.TLO.Group.Member(i).Name(), new_x, new_y)
mq.cmd[cmd]()
if debug then Debug('/'..cmd) end
mq.delay(100)
end
end