The -11 part keeps all of your ::'s aligned, when you expand this code to cover multiple categories. The "%-11s" tells Lua to create a string 11 characters wide, using whitespace as padding.
This is what it will look like without the "%-11s":
Instead, what you want is (based off your original output):
Because I have some to kill, I'm going to turn this into a reusable function. All you'll need to do is pass in "Perception", "Herb", "Elixir", ...
function echoDefenses (defenseCategory)
local categoryHeader = string.format("%-11s::", defenseCategory)
cecho(string.format("<grey>%s", category)
local firstLine = true
local count = 0
-- When iterating through a dictionary like this, the usual variables are
-- k(ey) and v(alue). I named them otherwise to make it clearer.
for defenseName, defense in pairs(system.defenses[string.lower(defenseCategory)]) do
if not firstLine and count == 0 then
echo(string.rep(" ", string.len(categoryHeader)))
end
local color = (dabomb.defenses[defenseName] and "green" or "red")
local output = string.format("<grey>%s%s<grey>", color, defenseName)
cechoLink(output, [[send("]] .. defense.action .. [[")]], "Use Skill", true)
count = count + 1
if count < 4 then
echo(" ")
else
echo("\n")
count = 0
if firstLine then
firstLine = false
end
end
end
-- This may result in double newlines. Can be handled with a little bit of line parsing.
echo("\n")
end
Note the change to system.defenses.perception; assuming that all follow the same naming scheme (Perception => perception), this is easily parameterized.
All you have to do to use this function is:
echoDefenses("Perception")
echoDefenses("Herb")
Even better, make a table with your defenseCategories (this information already exists in system.defenses) and loop through it.
local defenseCategories = {
"Perception",
"Herb",
"Elixir",
...
}
for _, defenseCategory in ipairs(defenseCategories) do
echoDefenses(defenseCategory)
end
Good luck!