From 3ae1ed1ec85e39bce50fb1cd419bfc83f5d34b6c Mon Sep 17 00:00:00 2001 From: Jymamon Date: Fri, 30 Nov 2018 13:48:58 -0800 Subject: [PATCH 1/2] foreach: Add waitcastrt command --- foreach.lic | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/foreach.lic b/foreach.lic index c13a800..2783c15 100644 --- a/foreach.lic +++ b/foreach.lic @@ -25,9 +25,12 @@ 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 + version 0.7 (2017-07-24) * Add waitmana, waithealth, waitspirit, and waitstamina commands. * Change suggestions for GameObjAdd and GameObjAddMore to use xmlpatch instead. @@ -938,6 +941,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 From 439ffe0cc074a81a56e614865bff127661d31783 Mon Sep 17 00:00:00 2001 From: Jymamon Date: Fri, 30 Nov 2018 13:55:06 -0800 Subject: [PATCH 2/2] foreach: Add unique option. --- foreach.lic | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/foreach.lic b/foreach.lic index 2783c15..b7a3778 100644 --- a/foreach.lic +++ b/foreach.lic @@ -30,6 +30,7 @@ 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. @@ -150,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)}" @@ -540,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 @@ -748,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