PDA

View Full Version : DownstreamHook Help



Haldrik
01-09-2016, 04:16 PM
Heya,

I'm having a weird issue with DownstreamHook that I can't seem to fix. The code works great for boxes but when I add the words "badge or "breastplate" downstreamhook is never removed (or something else is happening) and I have to relogin to clear the issues.

(This is a modified version from Dreaven's tpick script.)

EDIT: See post #2. I narrowed the issue down a bit, the error only occurs when the items are worn versus being in a container. But I still can't find any reason why the items being worn would break the script.



@list_of_box_ids = Array.new

def check_for_boxes
action = proc { |server_string|
if server_string =~ /\s{6}.*(an?|the|some) |\s{2}.*(an?|the|some) |^You are currently wearing and carrying\:/
if server_string =~ /(\s{6}.*(an?|the|some)|\s{2}.*(an?|the|some)).*exi st="(\d+)".*(strongbox|box|chest|trunk|coffer|breastplate)/
@list_of_box_ids << $4
echo server_string
end
nil
elsif server_string =~ /^\(\d+ items? displayed\.\)/
DownstreamHook.remove("check_for_boxes")
@boxes_checked = true
nil
else
server_string
end
}
DownstreamHook.add("check_for_boxes", action)
silence_me
fput 'inv full'
silence_me
wait_until { @boxes_checked }
end

fput "look in kalros disk"
sleep 0.5
disk = GameObj.loot.find { |obj| obj.name =~ /#{Char.name} (disk|coffin)/ }
disk.contents.each{|i| put "_drag ##{i.id} drop"}
sleep 1

check_for_boxes
@list_of_box_ids.each {|i| put "_drag ##{i} drop"}

sleep 1

I managed to get an echo of the badge/breastplate but I can't replicate it again. The regex is matching per RegExr.com

http://regexr.com/3chu4



[(unknown script): an <a exist="73638803" noun="badge">obsidian-bound bronze badge</a>]
[(unknown script): a <a exist="73638882" noun="breastplate">steel-buckled golvern breastplate</a> trimmed with green imflass edges (registered) (marked)]
--- Lich: transcend has exited.

--- Lich: save_boxes active.
[(unknown script): an <a exist="73852400" noun="trunk">enruned iron trunk</a>]
[(unknown script): an <a exist="73852397" noun="trunk">iron-bound monir trunk</a>]
[(unknown script): a <a exist="73852394" noun="strongbox">dented gold strongbox</a>]
[(unknown script): a <a exist="73852407" noun="trunk">badly damaged steel trunk</a>]


Here's a log of what happens after it breaks with badge or breastplate added.


>;save_boxes
--- Lich: save_boxes active.
[save_boxes]>look in kalros disk
There is nothing in there.
>
>sfsf
>l
>fsafs
>asfsaf

This is what happens without badge/breastplate in the variables.


>;save
--- Lich: save_boxes active.
[save_boxes]>look in kalros disk
There is nothing in there.
>
[(unknown script): a <a exist="73852394" noun="strongbox">dented gold strongbox</a>]


>
[save_boxes]>_drag #73852394 drop
You grab a dented gold strongbox from one of the large pouches lining the inside of your leather cloak.
You drop a dented gold strongbox.

>;save_boxes
--- Lich: save_boxes active.
[save_boxes]>look in kalros disk
There is nothing in there.
>


>
--- Lich: save_boxes has exited.



Here's a full XML log of inv full


>inv full
<streamWindow id='inv' title='My Inventory' target='wear' ifClosed='' resident='true'/><clearStream id='inv' ifClosed=''/><pushStream id='inv'/>Your worn items are:
a <a exist="73638882" noun="breastplate">steel-buckled golvern breastplate</a> trimmed with green imflass edges
an <a exist="73638803" noun="badge">obsidian-bound bronze badge</a>
a <a exist="73638796" noun="satchel">pebbled black leather satchel</a> clasped with a crimson scarab
a <a exist="73638800" noun="hand-puppet">red-eyed demon hand-puppet</a>
a <a exist="73638801" noun="tunic">green and purple silk tunic</a> with gold accents
a <a exist="73638802" noun="vest">multipocketed doeskin fishing vest</a>
a knotted pale <a exist="73638822" noun="pack">gold raw silk pack</a> woven with tiny dragon's-tear diamond drops
a <a exist="73638823" noun="cloak">weathered leather cloak</a>
a <a exist="73638872" noun="belt">wide glittering gold belt</a>
a <a exist="73638873" noun="monocle">kelyn-framed clear glass monocle</a>
<a exist="73638874" noun="footwraps">some gold-runed tiger skin footwraps</a>
<a exist="73638875" noun="handwraps">some gold-runed tiger skin handwraps</a>
a <a exist="73638876" noun="sack">suede and leather patchwork sack</a> with a wooden toggle
a <a exist="73638895" noun="toolkit">black vruul-hide toolkit</a>
a <a exist="73638910" noun="emblem">red silk winged wyvern emblem</a>
some <a exist="73638911" noun="pants">vermeil leather pants</a> side-laced with gold cording
a polished <a exist="73638912" noun="case">dark cocobolo case</a> inset with dragon's-tear ruby whorls
<popStream/>
You are currently wearing and carrying:
a <a exist="73638882" noun="breastplate">steel-buckled golvern breastplate</a> trimmed with green imflass edges (registered) (marked)
an <a exist="73638803" noun="badge">obsidian-bound bronze badge</a>
a <a exist="73638796" noun="satchel">pebbled black leather satchel</a> clasped with a crimson scarab (marked)
a <a exist="73638799" noun="knife">rolaren-cored silvery glaes knife</a> (marked)
a <a exist="73638798" noun="wedge">thin wooden wedge</a>
a <a exist="73638797" noun="wedge">thin wooden wedge</a>
a <a exist="73638800" noun="hand-puppet">red-eyed demon hand-puppet</a> (registered)
a <a exist="73638801" noun="tunic">green and purple silk tunic</a> with gold accents
a <a exist="73638802" noun="vest">multipocketed doeskin fishing vest</a> (marked)
a <a exist="73709549" noun="necklace">step-cut alexandrite necklace</a>
a <a exist="73638821" noun="spectacles">pair of black-framed spectacles</a> (registered) (marked)
a <a exist="73638820" noun="stickpin">garnet-set mithril stickpin</a> (marked)
a <a exist="73638819" noun="buckle">pink topaz studded ora buckle</a> (marked)
a <a exist="73638818" noun="lockpick">laje handled bent alum lockpick</a>
a <a exist="73638817" noun="lockpick">ruby-veined black rolaren lockpick</a>
an <a exist="73638816" noun="lockpick">opal-edged grey rolaren lockpick</a>
a <a exist="73638815" noun="sapphire">star sapphire</a> (marked)
a <a exist="73638814" noun="lockpick">ruby-veined black rolaren lockpick</a>
a <a exist="73638813" noun="coin">polished golden coin</a>
an <a exist="73638812" noun="coin">oblong silver coin</a>
an <a exist="73638811" noun="lockpick">opal-edged grey rolaren lockpick</a>
a <a exist="73638810" noun="salve">squat jar of pallid grey salve</a>
a <a exist="73638809" noun="wire">thin kelyn wire</a>
a <a exist="73638808" noun="pendant">sparkling chrysoberyl pendant</a> (marked)
a <a exist="73638807" noun="special">flagon of Guildmaster's special</a>
a <a exist="73638806" noun="assembly">primitive lock assembly</a>
a <a exist="73638805" noun="lockpick">burnished golden alum lockpick</a>
a knotted pale <a exist="73638822" noun="pack">gold raw silk pack</a> woven with tiny dragon's-tear diamond drops (marked)
a <a exist="73638823" noun="cloak">weathered leather cloak</a> (registered) (marked)
a <a exist="73745923" noun="scroll">faded scroll</a>
a <a exist="73638829" noun="earring">fine platinum earring</a>
a <a exist="73638871" noun="lockpick">thin wire green ora lockpick</a>
a <a exist="73638870" noun="lockpick">stained white ivory lockpick</a>
a <a exist="73638869" noun="lockpick">glossy black glaes lockpick</a>
a <a exist="73638868" noun="lockpick">glossy black glaes lockpick</a>
a <a exist="73638867" noun="hatpin">bent and rusted hatpin</a>
a <a exist="73638866" noun="hatpin">bent and rusted hatpin</a>
a <a exist="73638865" noun="hatpin">bent and rusted hatpin</a>
[ubermonk]>punch #73804796
a <a exist="73638864" noun="hatpin">bent and rusted hatpin</a>
a <a exist="73638863" noun="hatpin">bent and rusted hatpin</a>
[ubermonk]>punch #73804796
a <a exist="73638862" noun="hatpin">bent and rusted hatpin</a>
[ubermonk]>punch #73804796
a <a exist="73638861" noun="hatpin">bent and rusted hatpin</a>
[ubermonk]>punch #73804796
a <a exist="73638860" noun="hatpin">bent and rusted hatpin</a>
[ubermonk]>punch #73804796
a <a exist="73638859" noun="hatpin">bent and rusted hatpin</a>
a <a exist="73638858" noun="lockpick">thin wire green ora lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638857" noun="lockpick">stained white ivory lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638856" noun="lockpick">stained white ivory lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638855" noun="lockpick">stained white ivory lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638854" noun="lockpick">blue-swirled mithril lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638853" noun="scroll">torn scroll</a>
[ubermonk]>punch #73804796
a <a exist="73638852" noun="ripper">wood-handled dull seam ripper</a>
a <a exist="73638851" noun="wedge">solid wooden wedge</a>
[ubermonk]>punch #73804796
an <a exist="73638850" noun="scroll">arcane scroll</a>
[ubermonk]>punch #73804796
an <a exist="73638849" noun="scroll">aged scroll</a>
[ubermonk]>punch #73804796
a <a exist="73638848" noun="lockpick">gold-etched pearly vaalin lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638847" noun="papyrus">scrap of aged papyrus</a>
[ubermonk]>punch #73804796
an <a exist="73638846" noun="parchment">arcane parchment</a>
[ubermonk]>punch #73804796
a <a exist="73638845" noun="lockpick">diamond-edged black vaalin lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638844" noun="ripper">wood-handled dull seam ripper</a>
[ubermonk]>punch #73804796
a <a exist="73638843" noun="hatpin">bent and rusted hatpin</a>
[ubermonk]>punch #73804796
a <a exist="73638842" noun="ripper">wood-handled dull seam ripper</a>
[ubermonk]>punch #73804796
a <a exist="73638840" noun="papyrus">scrap of luminous papyrus</a>
[ubermonk]>punch #73804796
a <a exist="73638839" noun="scroll">charred scroll</a>
[ubermonk]>punch #73804796
a <a exist="73638838" noun="lockpick">pearl-etched thin alum lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638837" noun="lockpick">fine-toothed red kelyn lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638836" noun="parchment">scorched parchment</a>
[ubermonk]>punch #73804796
a <a exist="73638835" noun="lockpick">silk-wrapped veniom lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638834" noun="lockpick">glossy black glaes lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638833" noun="paper">sheaf of shimmering paper</a>
[ubermonk]>punch #73804796
a <a exist="73638831" noun="sceptre">garnet-set gold sceptre</a>
[ubermonk]>punch #73804796
a <a exist="73638872" noun="belt">wide glittering gold belt</a>
[ubermonk]>punch #73804796
a <a exist="73638873" noun="monocle">kelyn-framed clear glass monocle</a>
<a exist="73638874" noun="footwraps">some gold-runed tiger skin footwraps</a>
[ubermonk]>punch #73804796
<a exist="73638875" noun="handwraps">some gold-runed tiger skin handwraps</a>
[ubermonk]>punch #73804796
a <a exist="73638876" noun="sack">suede and leather patchwork sack</a> with a wooden toggle (marked)
[ubermonk]>punch #73804796
<a exist="73768388" noun="spine">some prickly cactacae spine</a>
<a exist="73768338" noun="leaf">some sugary ambrominas leaf</a>
[ubermonk]>punch #73804796
<a exist="73638894" noun="leaf">some spicy acantha leaf</a>
[ubermonk]>punch #73804796
a <a exist="73638880" noun="elixir">crystalline rose-marrow elixir</a>
a <a exist="73730287" noun="moss">gooey ball of ephlox moss</a>
[ubermonk]>punch #73804796
a <a exist="73638893" noun="flask">white flask</a>
[ubermonk]>punch #73804796
a <a exist="73638892" noun="elixir">crystalline bolmara elixir</a>
[ubermonk]>punch #73804796
<a exist="73638891" noun="flower">some fragrant woth flower</a>
[ubermonk]>punch #73804796
<a exist="73638890" noun="leaf">some fresh torban leaf</a>
[ubermonk]>punch #73804796
<a exist="73638889" noun="lichen">some wolifrew lichen</a>
[ubermonk]>punch #73804796
<a exist="73638888" noun="leaf">some acantha leaf</a>
a <a exist="73638887" noun="elixir">crystalline talneo elixir</a>
[ubermonk]>punch #73804796
<a exist="73638886" noun="grass">some bright green pothinir grass</a>
<a exist="73638885" noun="stem">some withered aloeas stem</a>
[ubermonk]>punch #73804796
a <a exist="73638884" noun="moss">sticky ball of basal moss</a>
[ubermonk]>punch #73804796
a <a exist="73638883" noun="elixir">crystalline talneo elixir</a>
a <a exist="73638895" noun="toolkit">black vruul-hide toolkit</a> (marked)
[ubermonk]>punch #73804796
a <a exist="73638909" noun="lockpick">golvern lockpick</a>
a <a exist="73638908" noun="ripper">wood-handled dull seam ripper</a>
[ubermonk]>punch #73804796
a <a exist="73638907" noun="lockpick">laje handled bent alum lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638906" noun="lockpick">red-flecked black invar lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638905" noun="lockpick">red-flecked black invar lockpick</a>
a <a exist="73638904" noun="lockpick">red-flecked black invar lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638903" noun="lockpick">fine-toothed red kelyn lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638902" noun="jaws">pair of small steel jaws</a>
[ubermonk]>punch #73804796
a <a exist="73638901" noun="jaws">pair of small steel jaws</a>
[ubermonk]>punch #73804796
a <a exist="73638900" noun="lockpick">glossy black glaes lockpick</a>
[ubermonk]>punch #73804796
a <a exist="73638899" noun="lockpick">golvern lockpick</a>
a <a exist="73638898" noun="ripper">wood-handled dull seam ripper</a>
[ubermonk]>punch #73804796
a <a exist="73638897" noun="lockpick">silk-wrapped veniom lockpick</a>
a <a exist="73638896" noun="calipers">set of professional calipers</a>
[ubermonk]>punch #73804796
a <a exist="73638910" noun="emblem">red silk winged wyvern emblem</a>
[ubermonk]>punch #73804796
some <a exist="73638911" noun="pants">vermeil leather pants</a> side-laced with gold cording (marked)
[ubermonk]>punch #73804796
a polished <a exist="73638912" noun="case">dark cocobolo case</a> inset with dragon's-tear ruby whorls (registered) (marked)
[ubermonk]>punch #73804796
a <a exist="73638927" noun="pearl">large black pearl</a>
[ubermonk]>punch #73804796
a <a exist="73638926" noun="ruby">dragon's-tear ruby</a>
[ubermonk]>punch #73804796
a <a exist="73638925" noun="pearl">medium black pearl</a>
[ubermonk]>punch #73804796
a <a exist="73638924" noun="pearl">large black pearl</a>
[ubermonk]>punch #73804796
a <a exist="73638923" noun="pearl">small black pearl</a>
[ubermonk]>punch #73804796
a <a exist="73638922" noun="pearl">medium black pearl</a>
a <a exist="73638921" noun="pearl">tiny black pearl</a>
[ubermonk]>punch #73804796
a <a exist="73638920" noun="pearl">medium black pearl</a>
a <a exist="73638919" noun="pearl">large black pearl</a>
[ubermonk]>punch #73804796
a <a exist="73638918" noun="pearl">small black pearl</a>
[ubermonk]>punch #73804796
a <a exist="73638917" noun="pearl">medium black pearl</a>
[ubermonk]>punch #73804796

(120 items displayed.)

Haldrik
01-09-2016, 04:41 PM
I went back for a second look after I was looking at the XML dump. It's apparently related to the items being worn. There is TWO spaces when worn and SIX spaces when not worn. I double checked the regex with the TWO spaces and everything appears to be okay.


>;save_boxes
--- Lich: save_boxes active.
[save_boxes]>look in kalros disk
There is nothing in there.
>
[(unknown script): a <a exist="74008093" noun="breastplate">steel-buckled golvern breastplate</a> trimmed with green imflass edges (registered) (marked)]
[(unknown script): an <a exist="74008092" noun="badge">obsidian-bound bronze badge</a>]
[save_boxes]>_drag #74008093 drop


[save_boxes]>_drag #74008092 drop
>
You grab a steel-buckled golvern breastplate trimmed with green imflass edges from one of the large pouches lining the inside of your leather cloak.
You drop a steel-buckled golvern breastplate trimmed with green imflass edges.
>
You grab an obsidian-bound bronze badge from a small pocket inside of your leather cloak.
You drop an obsidian-bound bronze badge.

More stuff


>;save_boxes
--- Lich: save_boxes active.
[save_boxes]>look in kalros disk
There is nothing in there.
>l
[Bank of Vornavis, Solhaven]
Obvious exits: out
>l
>asfsf
>;e DownstreamHook.remove("check_for_boxes")
>test
>;e DownstreamHook.remove("save_boxes_check_for_boxes")
>asfsf
>;e DownstreamHook.remove("save_boxes.lic_check_for_boxes")
>sff

Tillmen
01-10-2016, 08:41 AM
I don't see what might be causing your troubles, but I decided to fix it anyway. You shouldn't pull information from a DownstreamHook, because other scripts may have changed or removed it. I learned my lesson when people started using prettynum which adds commas to numbers, and go2 suddenly stopped being able to figure out how many silvers you have.

In the code below, the hook is much simpler and should not be able to squelch anything except what it's intended to. I didn't test any of this, of course.



def squelched_inv_full
started = false
hook_name = 'squelch-inv-full'
hook_proc = proc { |s|
if started
# "inv full" output already started
if s =~ /<prompt/
# the "inv full" output is followed by a prompt, so remove the hook
# this is also a good fail-safe, since we won't go long without seeing a prompt even if something goes wrong
DownstreamHook.remove(hook_name)
end
# squelch stuff, including the blank line after "(# items displayed.)" and the last prompt
nil
elsif s =~ /^You are currently wearing and carrying:/
# this is the start of the "inv full" output, so start squelching
started = true
nil
else
# "inv full" output hasn't started yet; don't squelch unrelated lines
s
end
}
DownstreamHook.add(hook_name, hook_proc)
# silently put 'inv full', and return the script to non-silent unless it was silent to start with
silence_me unless undo_silence = silence_me
put 'inv full'
silence_me if undo_silence
end

# find the disk
unless disk = GameObj.loot.find { |o| o.name =~ /#{Char.name} (?:disk|coffin)$/ }
# if there is no disk, look back into the buffer to see if a disk was following recently
if reget.any? { |line| line =~ /^Your (?:disk|coffin) arrives, following you dutifully\.\r?$/ }
# if there was a disk, wait for it to arrive
50.times { break if GameObj.loot.any? { |o| o.name =~ /#{Char.name} (?:disk|coffin)$/ }; sleep 0.1 }
# find the disk again
disk = GameObj.loot.find { |o| o.name =~ /#{Char.name} (?:disk|coffin)$/ }
end
end
if disk
# the disk is assumed to be open; fix that here if you want
# look in the disk if needed
if disk.contents.nil?
dothistimeout "look in ##{disk.id}", 5, /^In the|^There is nothing in there\.$/
end
# drop everything from the disk
# since you're not targetting boxes, you could just turn the disk, I suppose
disk.contents.each { |o| fput "_drag ##{o.id} drop" }
end


box_ids = Array.new
clear # clears the buffer so we don't process an "inv full" from the past
squelched_inv_full # does "inv full" with no output in the frontend
waitfor 'You are currently wearing and carrying'
while (line = get)
if line =~ /^\s{6}(?:a|an|the|some|<a)\s.*exist="(\-?\d+)" noun="(?:strongbox|box|chest|trunk|coffer|breastplate)"/
# only looking for lines that start with exactly six spaces, which seems to be items in a container you're wearing and aren't double bagged
# the array name is box_ids, but you're looking for breastplates too. Shenanigans!
box_ids.push($1)
elsif line =~ /^\(\d+ items? displayed\.\)/
break
end
end
# drop the boxes (and breatplate)
box_ids.each { |b| fput "_drag ##{b.id} drop" }

Haldrik
01-12-2016, 03:44 AM
Hey Tillmen,

This is really fantastic. Thank you! I see what you mean about not using downstreamhook for info gathering. Makes a lot of sense! I appreciate the awesome disk code too, I didn't know you could do things like look back in the buffer!

One thing I'm quite not understanding though. How can def squelched_inv_full run at the same time as while (line = get)? I had thought everything ran sequentially unless in a new thread. But here it looks like the proc is running at the same time as the the rest of the thread? I experienced that a bit with the original code but wasn't sure why.


Thanks again!

Tillmen
01-12-2016, 10:09 AM
Your script never actually runs the proc. squelched_inv_full creates the proc and calls DownstreamHook.add. Neither of those things take any time, and the script continues right into the while loop. The part of Lich that reads lines from the game server runs the proc you created each time a line comes in, which is independent of what your script is doing. The script doesn't even have to be running.

Haldrik
01-12-2016, 11:07 AM
Your script never actually runs the proc. squelched_inv_full creates the proc and calls DownstreamHook.add. Neither of those things take any time, and the script continues right into the while loop. The part of Lich that reads lines from the game server runs the proc you created each time a line comes in, which is independent of what your script is doing. The script doesn't even have to be running.


Ahhhh. Okay great. Thank you!