PDA

View Full Version : Help: Checkloot & Checknpcs



Danical
10-06-2008, 08:17 PM
Alright, so I'm trying to learn how to deal with all this XML stuff.

First, if anyone has any good resources that would be swell because I'd rather just learn it myself instead of having to keep asking like a n00blet.

Second, I'm trying to construct a variable that tracks the "room data" for creatures "that appears dead".

Here's a clip of the XML data:

<component id='room objs'> You also see<b> <pushBold/>a <a exist="155399057" noun="magus">triton magus</a><popBold/></b>that appears dead,<b> <pushBold/>a <a exist="155414465" noun="combatant">triton combatant</a><popBold/></b> that appears dead,<b> <pushBold/>an <a exist="155395937" noun="sentry">ethereal triton sentry</a><popBold/></b>,<b> <pushBold/>a <a exist="155396102" noun="defender">spectral triton defender</a><popBold/></b> and <a exist="156024" noun="muck">some muck</a>.</component>


I've got the following to track creatures in the room:

before_dying{ untrace_var(:$_SERVERSTRING_) }
trace_var(:$_SERVERSTRING_, proc { |data|
if data =~ /<pushStream id=['"]room['"]\/>.+<compDef id=['"]room objs['"]>.*<\/compDef>|<component id=['"]room objs['"]>.*<\/component>/
$npcs2 = data.scan(/<pushBold\/>[^<]*<a exist=['"]\d+['"] noun=['"][^'"]+['"]>/).collect { |val| /noun=['"]([^'"]+)['"]/.match(val).captures[0].dup }
end
})

How can I modify for my purposes above?

Also, the current iteration of checkloot forces a "look" action which I assume is for the wizard. How can I create a variable that analyzes the room data similar to above but with respect to objects.

Shaelun
10-11-2008, 09:35 AM
As an aside, code is really ugly and hard to follow when not enclosed in '[ code ] (stuff goes here) [ / code ]' brackets (strip out the spaces and the code would be in a "code" box without having indentation and stuff lost).

At a glance, I'd say the easiest way is to just slice out any dead critters before you even evaluate the line using the code you've got. How could you do that? As a rule, it's a horrible practice to give example code without testing it (the last thing somebody trying to learn needs is an example that isn't even correct), but despite my feeling lazy I still want to help you, so my untested example:


data = data.gsub(/<a exist=['"]\d+['"] noun=['"][^'"]+that appears dead[\.,]?['"]/, '')
Stick that in right before your "$npcs2 = data.scan..." line and it should just delete any dead critters before you even scan for what critters are in the room.

I've heard programmers with 4 year degrees bitch and moan about Regular Expressions and how fucked up and hard they are... if you find it really tricky to understand why some of this stuff matches what it does, don't feel discouraged about it.