diff --git a/foreach.lic b/foreach.lic index c13a800..b7a3778 100644 --- a/foreach.lic +++ b/foreach.lic @@ -25,9 +25,13 @@ tags: utility required: Lich >= 4.6.0. - version: 0.7 (2017-07.24) + version: 0.8 (2018-11.30) changelog: + version 0.8 (2018-11.30) + * Add waitcastrt + * Add support for unique option. + version 0.7 (2017-07-24) * Add waitmana, waithealth, waitspirit, and waitstamina commands. * Change suggestions for GameObjAdd and GameObjAddMore to use xmlpatch instead. @@ -147,6 +151,11 @@ module ForeachScript @previous = nil unless defined?(@previous) @previous_names = nil unless defined?(@previous_names) + # When true, only one of each item (by name) will be processed. For example, if there are 10 blue crystals + # ;foreach unique name=blue crystal;get item; + # will only get one of them. + @unique = false + def self.anon_hook(prefix = '') now = Time.now "Foreach::#{prefix}-#{now.tv_sec}.#{now.tv_usec}-#{Random.rand(10000)}" @@ -537,6 +546,12 @@ module ForeachScript resume_scripts } + # If "unique" is present, remove it and set @unique to true. + if @script.vars[0] =~ /\bunique\b/ + @unique = true + @script.vars[0].gsub!(/\bunique\b/, " "); + end + @script.vars[0] =~ /^\s*(.+?)\s*(?:([;\/|])\s*(.*?)\s*)?$/ filter = $1 separator = $2 @@ -745,6 +760,13 @@ module ForeachScript next end items = items.find_all{|item| filter_proc.call(item)} + + # If looking only for unique items, condense the results + # to just one of each item by name. + if @unique + items = items.uniq{|l| l.name} + end + unless items.length > 0 container_names.delete(container) next @@ -938,6 +960,9 @@ module ForeachScript elsif command =~ /^waitrt$/i before_next = nil waitrt + elsif command =~ /^waitcastrt$/i + before_next = nil + waitcastrt elsif command =~ /^waitfor (.*)$/i script.want_downstream = true script.want_downstream_xml = false