Skip to content

Commit

Permalink
Cleaned up ChaseOn command handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DerpleMQ2 committed Dec 26, 2023
1 parent 1d7a52f commit ee2fb35
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
12 changes: 9 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,15 @@ local script_actor = RGMercUtils.Actors.register(function(message)
end)

-- Binds
mq.bind("/chaseon", function()
RGMercModules:execModule("Chase", "ChaseOn")
end)
local function bindHandler(cmd, ...)
if cmd:lower() == "chaseon" then
RGMercModules:execModule("Chase", "ChaseOn")
else
RGMercsLogger.log("\ayWarning:\ay '\at%s\ay' is not a valid command", cmd)
end
end

mq.bind("/rglua", bindHandler)

while not terminate do
Main()
Expand Down
17 changes: 13 additions & 4 deletions modules/chase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function Module:Render()

ImGui.Text(string.format("Chase Target: %s", self.settings.ChaseTarget))

if chaseSpawn then
if chaseSpawn and chaseSpawn.ID() > 0 then
ImGui.Indent()
ImGui.Text(string.format("Distance: %d", chaseSpawn.Distance()))
ImGui.Text(string.format("ID: %d", chaseSpawn.ID()))
Expand All @@ -75,6 +75,12 @@ function Module:Render()
ImGui.Text(string.format("%s", chaseSpawn.LineOfSight() and ICONS.FA_EYE or ICONS.FA_EYE_SLASH))
ImGui.PopStyleColor(1)
ImGui.Unindent()
else
ImGui.Indent()
ImGui.PushStyleColor(ImGuiCol.Text, 1.0, 0.3, 0.3, 0.8)
ImGui.Text(string.format("Chase Target Invalid!"))
ImGui.PopStyleColor(1)
ImGui.Unindent()
end

self.settings.ChaseOn, pressed = ImGui.Checkbox("Chase On", self.settings.ChaseOn)
Expand All @@ -101,6 +107,9 @@ function Module:GiveTime()
return
end

if mq.TLO.Me.Dead() then return end
if chaseSpawn.Distance() < self.settings.ChaseDistance then return end

local Nav = mq.TLO.Nav

-- Use MQ2Nav with moveto as a failover if we have a mesh. We'll use a nav
Expand Down Expand Up @@ -137,12 +146,12 @@ end

function Module:ChaseOn()
-- Command Binds
if mq.TLO.Target.ID() > 0 then
self.settings.ChaseOn = not self.settings.ChaseOn
if mq.TLO.Target.ID() > 0 and mq.TLO.Target.Type() == "PC" then
self.settings.ChaseOn = true
self.settings.ChaseTarget = mq.TLO.Target.CleanName()
self:SaveSettings()
else
RGMercsLogger.log("\ayWarning:\ax No valid chase target!")
RGMercsLogger.log("\ayWarning:\ax Not a valid chase target!")
end
end

Expand Down

0 comments on commit ee2fb35

Please sign in to comment.