The middle trigger does:
if stats == nil then
stats = {}
end
stats["%1"] = %2
It first checks whether the stats object is "nil", and if yes - assigns a table to it (stats = {}). Nil is Lua's value for "nothing". When the trigger first fires, there is no "stats" object in your script space, so we need to create it explicitely. Once it is created, it'll stay and will remain a table, so we only need to do this once.
Next we assign the contents of the second wildcard to the named index in the stats table. The name of the index is retrieved from the first wildcard. %1 (first wildcard) is quoted to make it a string, and %2 (second wildcard) is not - since it contains a number, that'll be substituted for %2 and Lua will store a numeric value in the table.
The last trigger does:
EnableTriggerGroup("CountRoll", false)
res = true
for k,v in pairs(stats) do
if v < tonumber(GetVariable("Z" .. k)) then
Note(k .. " not good.")
res = false
end
end
if res == false then
Send("reroll")
EnableTrigger("start_roll", true)
end
The first line disables this trigger and the middle one. Then we define a "res" object, which is a boolean type, assigned a true value.
Next if "for". This iterates over every key-value pair in the "stats" table that we created and assigned to in the middle trigger. Each stat["%1"] = %2 that we did there will result in a pair of "k" and "v" values, of which "k" will hold the corresponding "%1" and "v" - %2. So "k" will be repeatedly set to "Strength", "Wisdom", "Luck", etc. And "v" will take on numeric values of those stats.
For each pair we check whether the stat value (v) is less than the value stored in a Mushclient variable with name "Z"+k (so when parsing a Strength index the corresponding Mushclient variable's name will be "ZStrength"). Note that we use tonumber() to convert the variable's value to a number, since it is returned as a string.
If what we want (the Z value) is greater than what we have (the v value) then we set the "res" object, defined earlier outside the for loop to be true, to false and Note that this stat is subpar.
Once the for loop completes, we perform a check on the "res" object. If no stats were below target values then the "res = false" line was never called, thus "res" will remain true as we exit the loop. If it isn't true, then some stats were unsatisfactory, so we re-enable the first trigger and send the "reroll" command, starting over again.
Hope that helps. |