PDA

View Full Version : Container Monitor



Danical
04-26-2009, 09:10 PM
So, I was trying to throw together a script that monitors my container and I was piggybacking on Tillmen's code but I'm stuck. The problem is that I can't seem to pick up the objects and then assign them to the proper container using the bolded part below.

This is the log from the game:

<clearContainer id="14207043"/><inv id='14207043'>In the <a exist="14207043" noun="backpack">backpack</a>:</inv><inv id='14207043'> a <a exist="14207048" noun="rod">sturdy rod</a></inv><inv id='14207043'> a <a exist="14207049" noun="scroll">yellowed scroll</a></inv><inv id='14207043'> an <a exist="14207044" noun="lute">ugly pine lute</a></inv><inv id='14207043'> a <a exist="14207047" noun="rod">long rod</a></inv><inv id='14207043'> a <a exist="14207046" noun="rod">cracked rod</a></inv><inv id='14207043'> a <a exist="14207045" noun="scroll">burnt scroll</a></inv>You put a <a exist="14207048" noun="rod">sturdy rod</a> in your <a exist="14207043" noun="backpack">scarred backpack</a>.

This is the code I have so far:



module SFMetadata
def container_objs(hash={})
ContainerObj.setstring($_SERVERSTRING_)
end
end

class ContainerObj
attr_reader :id, :noun, :name
def initialize(id, noun, name)
@id, @noun, @name = id, noun, name
@@container_obj_list.push(self)
end
def ContainerObj.setstring(string)
@@container_obj_list = nil
@@container_obj_string = string
end
def ContainerObj.populate_list
temp_container_list = @@container_obj_string.slice(/<clearContainer id=['"][0-9]+['"].*?:.*?<a.*?<\/\1>/).sub(/^.*?<a/, '').split(/<a/)
@@container_obj_list = Array.new
for obj in temp_container_list
if obj =~ /^\s*exist="(^"+)" noun="([^"]+)">([^<]+)</
id, noun, name = $1, $2, $3
end
ContainerObj.new(id, noun, name)
end
end
def ContainerObj.list
populate_list unless @@container_obj_list
return nil if @@container_obj_list.empty?
return @@container_obj_list.dup
end
end

Danical
04-27-2009, 06:11 PM
I solved my problem using some old code but I'd really appreciate it if someone could help me work through the above code.

Tillmen's code is so clean compared to mine. I'll post my mess when I get home.

Basically, now I have all the contents of every single container of mine accounted for including my disk; I can keep these separate or throw them into a super array for hot action. w00t!

LMingrone
04-27-2009, 07:20 PM
Maybe I'm not right about what you're trying to do, and don't feel like coding right now. But, couldn't you use "inv all" and then use that to parse everything? Seems much simpler. I'm pretty sure I'm wrong with your goal though, as it wouldn't keep a live update. But I've used, open new log, open everything on me and my locker, "look in locker", "inv all" and then parse that info. I'm guessing you want it to be live though. That's going to take some time to get perfect.

Danical
04-27-2009, 07:44 PM
Right, I want it live and constantly updating.

Danical
04-27-2009, 07:45 PM
This works fine, but it's not clean.



before_dying{ untrace_var(:$_SERVERSTRING_) }
trace_var(:$_SERVERSTRING_, proc { |data|
if data =~ /<clearContainer id=['"]([^"]+)['"]\/>.*?scarred backpack/
backpack_id = $1
end
if data =~ /<clearContainer id=['"]([^"]+)['"]\/>.*?leather coat/
coat_id = $1
end
if data =~ /<clearContainer id=['"]([^"]+)['"]\/>.*?Gnimble disk/
disk_id = $1
end
if data =~ /<clearContainer id=['"]#{backpack_id}['"]\/>/
$backpackobjs = data.scan(/<inv id=['"][0-9]+['"]>[^<]*<a exist=['"][^'"]+['"] noun=['"][^'"]+['"]>[^<]*<\/a><\/inv>/).collect { |val| /noun=['"][^'"]+['"]>([^<]+)<\/a>/.match(val).captures[0].dup }
elsif data =~ /<clearContainer id=['"]#{coat_id}['"]\/>/
$coatobjs = data.scan(/<inv id=['"][0-9]+['"]>[^<]*<a exist=['"][^'"]+['"] noun=['"][^'"]+['"]>[^<]*<\/a><\/inv>/).collect { |val| /noun=['"][^'"]+['"]>([^<]+)<\/a>/.match(val).captures[0].dup }
elsif data =~ /<clearContainer id=['"]#{disk_id}['"]\/>/
$diskobjs = data.scan(/<inv id=['"][0-9]+['"]>[^<]*<a exist=['"][^'"]+['"] noun=['"][^'"]+['"]>[^<]*<\/a><\/inv>/).collect { |val| /noun=['"][^'"]+['"]>([^<]+)<\/a>/.match(val).captures[0].dup }
elsif data =~ /<clearContainer id=['"]stow['"]\/>/
$cloakobjs = data.scan(/<inv id=['"]stow['"]>[^<]*<a exist=['"][^'"]+['"] noun=['"][^'"]+['"]>[^<]*<\/a><\/inv>/).collect { |val| /noun=['"][^'"]+['"]>([^<]+)<\/a>/.match(val).captures[0].dup }
elsif data =~ /<dialogData id=['"]encum["']>/
$encum = data.collect { |val| /text=['"]([^'"]+)['"]/.match(val).captures[0].dup }
elsif data =~ /<dialogData id=['"]expr["']>/
$mind = data.collect { |val| /text=['"]([^'"]+)['"]/.match(val).captures[0].dup }
end
})