Stratagem for Harvest (or more than 10 in queue)

What's a cleaner way to set up more than 10 actions to execute in a stratagem? I have a timer here. Can I replace with a tempTrigger that works either on the regain eq/bal message?
-- harvest plant `key` groups `value` times
local plants = {
  ["arnica"] = 5,
  ["kafe"] = 5,
  ["juniper"] = 5
}
local delayCount = 0
send("stratagem add water plants; stratagem add free plants; stratagem add nature growth")

for plant, iterTotal in pairs(plants) do
  local harvestCommand = "stratagem add harvest "..plant.." group"
for i = 2,iterTotal do
    harvestCommand = harvestCommand.."; stratagem add harvest "..plant.." group"
  end
  tempTimer(delayCount * iterTotal * 2.25, [[send("]]..harvestCommand..[[")]])
  delayCount = delayCount + 1
end


Active: Monday, Thursday, Friday, Saturday EST

Avatar made through Picrew

Comments

  • AeldraAeldra , using cake powered flight
    edited October 2020
    What I would do here, is would have a global cmd_queue variable and something that fires everytime gmcp.Char.Vitals.balance switches from 0 to 1 (or gmcp.Char.Vitals.equilibrium) or triggering on either text to call this code.

    It would then remove  the first item from cmd_queue if it was there and then execute it. I have no mudlet at hand at the moment, but basically something like this:

    that in a script

    
    cmd_queue = cmd_queue or {}
    function run_cmd()
      if #cmd_queue == 0 then return end
         local cmd = table.pop(cmd_queue)
        send(local_cmd, false)
      end
    

    and then  your original code:

    <div>local plants = {
      ["arnica"] = 5,
      ["kafe"] = 5,
      ["juniper"] = 5
    }
    send("stratagem add water plants; stratagem add free plants; stratagem add nature growth")
    
    for plant, iterTotal in pairs(plants) do
      local harvestCommand = "harvest "..plant.." group"
    for i = 2,iterTotal do
        harvestCommand = harvestCommand.."; stratagem add harvest "..plant.." group"
      end
      table.insert(cmd_queue, harvestCommand)
    end</pre></div>

    as said, untested, but like that, it should work
    Avatar / Picture done by the lovely Gurashi.
Sign In or Register to comment.