Danical
04-26-2009, 10: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
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