local mq = require('mq')
local ImGui = require('ImGui')
local RUNNING = false
local doBeep = false
local lastZone = mq.TLO.Zone.ShortName() or ''
local guildName = ''
local list = {}
local alerted = {}
local function GuildSearchPC(guild_name)
local tmp = {} -- holds results
-- local search = string.format('pc guildname %s', guild_name)
local search = string.format('pc ')
local cnt = mq.TLO.SpawnCount(search)()
if cnt ~= nil or cnt > 0 then
for i = 1, cnt do
local pc = mq.TLO.NearestSpawn(i, search)
if pc ~= nil and pc.DisplayName() ~= nil then
local name = pc.DisplayName()
local guild = pc.Guild() or 'No Guild'
-- check guild name matches
if guild:lower() == guild_name:lower() or string.find(guild:lower(), guild_name:lower()) then
tmp[name] = {
name = name,
guild = string.format("<%s>", guild),
distance = math.floor(pc.Distance() or 0),
time = os.time(),
}
end
end
end
end
return tmp
end
local function RenderGUI()
ImGui.SetNextWindowSize(400, 300, ImGuiCond.FirstUseEver)
local open, show = ImGui.Begin('Guild Search', true)
if show then
ImGui.Text('Search for players in a guild:')
guildName = ImGui.InputText('Guild Name', guildName)
ImGui.SameLine()
if ImGui.Button('Clear') then
guildName = ''
list = {}
end
doBeep = ImGui.Checkbox('Do Beep', doBeep)
ImGui.Separator()
if ImGui.BeginTable('Results', 3) then
ImGui.TableSetupColumn('Name')
ImGui.TableSetupColumn('Guild')
ImGui.TableSetupColumn('Distance')
ImGui.TableHeadersRow()
ImGui.TableNextRow()
for _, v in pairs(list) do
ImGui.TableNextColumn()
ImGui.Text(v.name)
ImGui.TableNextColumn()
ImGui.Text(v.guild)
ImGui.TableNextColumn()
ImGui.Text(tostring(v.distance))
end
ImGui.EndTable()
end
end
if not open then
RUNNING = false
end
ImGui.End()
end
local function init()
mq.imgui.init('Guild Search', RenderGUI)
RUNNING = true
end
local function MainLoop()
while RUNNING do
local zone = mq.TLO.Zone.ShortName() or ''
if zone ~= lastZone then
alerted = {}
list = {}
printf('\ayZone changed from \ax\at%s \ax\ayto \ax\at%s\ax', lastZone, zone)
lastZone = zone
end
if guildName ~= '' then
list = GuildSearchPC(guildName)
else
list = {}
alerted = {}
end
local didAlert = false
for _, v in pairs(list) do
if alerted[v.name] == nil then
didAlert = true
printf("\arWARNING!!! \ax\at %s \ax\ay%s \axis in the Zone and is\ag %s\ax away!", v.name, v.guild, v.distance)
alerted[v.name] = true
end
end
if doBeep and didAlert then mq.cmdf('/beep') end
mq.delay(1000)
end
end
init()
MainLoop()