PF statblock importer

Discussion concerning lmarkus' campaign framework for D&D3.x and Pathfinder.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice, lmarkus001

Forum rules
Discussion regarding lmarkus001's framework only. Other posts deleted without notice! :)
User avatar
Azhrei
Site Admin
Posts: 12058
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: PF statblock importer

Post by Azhrei »

Nope, we want the parens because they create a regex group that can be extracted from the string as a match.

User avatar
Full Bleed
Demigod
Posts: 4547
Joined: Sun Feb 25, 2007 11:53 am
Location: MD
Contact:

Re: PF statblock importer

Post by Full Bleed »

Full Bleed wrote:I couldn't get any of the suggestions made to work, so after some gnashing of teeth, I figured out something that works for me:

Code: Select all

[H: id = strfind(statblock, "hp ([0-9]+).(\\((.+)\\))?.?Fort")]
[H, IF(0<getFindCount(id)),CODE:
   {
      [HP=getGroup(id, 1, 1)]
      [MaxHP=HP]
      [HD=getGroup(id, 1, 2)]
   }
]



I ran into a problem with the above.

It works for most situations because they look like this:

hp 92 (8d10+48)
Fort +12, Ref +5, Will +10


But some look like this:

hp 92 (8d10+48); regeneration 5 (fire or acid)
Fort +12, Ref +5, Will +10


So, how do I get it to stop at the semi-colon OR "Fort"?
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
Azhrei
Site Admin
Posts: 12058
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: PF statblock importer

Post by Azhrei »

Full Bleed wrote:So, how do I get it to stop at the semi-colon OR "Fort"?

Remove the trailing .?Fort and that should do it.

User avatar
biodude
Dragon
Posts: 444
Joined: Sun Jun 15, 2008 2:40 pm
Location: Montréal, QC

Re: PF statblock importer

Post by biodude »

Full Bleed wrote:I've been customizing the statblock2token macro for my framework and I was wondering if someone knew a way to grab the HP values inside the parenthesis using strfind?

That is, if the statblock reads:

hp 80 (7d10+42)

I'd like to be able to grab the "7d10+42" value.

That way I can quickly randomize the hitpoint values of monsters I drop into the game instead of using the default values (which are usually pretty weak.)


Here's the regex I've been using to extract die rolls with pluses, inside parentheses:
\\([-0-9d\\+]+\\)

I haven't tested in thoroughly, but it should grab anything that looks like die rolls (numbers, the letter 'd', +/-) in a continuous sequence, with a bracket on either end. If you don't want the brackets, but want to capture everything inside, a lookaround might work instead:
(?<=\\()[-0-9d\\+]+(?=\\))
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]

User avatar
Full Bleed
Demigod
Posts: 4547
Joined: Sun Feb 25, 2007 11:53 am
Location: MD
Contact:

Re: PF statblock importer

Post by Full Bleed »

Azhrei wrote:
Full Bleed wrote:So, how do I get it to stop at the semi-colon OR "Fort"?

Remove the trailing .?Fort and that should do it.


Nope. It doesn't stop at the semi colon... in fact it continue to the end of the statblock making for one very large property value. ;)


Biodude, I'm going to need more specific info on where and how to plug in those examples using the code I posted above... what I've tried doesn't seem to work.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
Azhrei
Site Admin
Posts: 12058
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: PF statblock importer

Post by Azhrei »

Full Bleed wrote:Nope. It doesn't stop at the semi colon... in fact it continue to the end of the statblock making for one very large property value. ;)

Huh?

Ohhhh, I see. The regex is being greedy about what is inside the parens so it grabs everything up to the last close paren! Try this instead:

hp ([0-9]+).(\\((.+?)\\))?

Notice that the same "Fort" string is removed, but there's also a "?" after the ".+" -- that makes for the shortest possible string instead of the (default) longest possible string.

Now the regex will break if the parens contains nested parens, but there's no easy way to handle nested parens within RE's so hopefully that doesn't happen. ;)

User avatar
Full Bleed
Demigod
Posts: 4547
Joined: Sun Feb 25, 2007 11:53 am
Location: MD
Contact:

Re: PF statblock importer

Post by Full Bleed »

Azhrei wrote:Try this instead:

hp ([0-9]+).(\\((.+?)\\))?


That did the trick! Thanks. :)
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
Full Bleed
Demigod
Posts: 4547
Joined: Sun Feb 25, 2007 11:53 am
Location: MD
Contact:

Re: PF statblock importer

Post by Full Bleed »

Ok, next problem.

I'm looking to have the parser set the level of specific classes.

So, I'm currently using this to grab the first number after a particular class name:

Code: Select all

[H: id = strfind(statblock, "warrior ([0-9]+)")]


The problem is that Clerics (and maybe some other classes) say things like: "cleric of iomedae"

So what I need is for the parser to find the class name and then grab the next number irrespective of what text lies between the text and the number.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: PF statblock importer

Post by Rumble »

Something like:

Code: Select all

[h:id = strfind(statblock, "cleric.*?([0-9]+)")]


ought to do it. It's just classname(some characters)(capture group forthe number). The match is not greedy, to avoid running past the next number (or that's the idea). So that would get

cleric of iomedae 10

as well as

cleric 5


If you've never used it, I find RegExr and Java Regular Expression Test Applet invaluable for this stuff.

User avatar
Full Bleed
Demigod
Posts: 4547
Joined: Sun Feb 25, 2007 11:53 am
Location: MD
Contact:

Re: PF statblock importer

Post by Full Bleed »

Rumble wrote:Something like:

Code: Select all

[h:id = strfind(statblock, "cleric.*?([0-9]+)")]



Thanks. Works great. :)


If you've never used it, I find RegExr and Java Regular Expression Test Applet invaluable for this stuff.


And thanks for the links. Beats the heck out of trial and error in MT!
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: PF statblock importer

Post by Rumble »

Full Bleed wrote:
Rumble wrote:Something like:

Code: Select all

[h:id = strfind(statblock, "cleric.*?([0-9]+)")]



Thanks. Works great. :)


If you've never used it, I find RegExr and Java Regular Expression Test Applet invaluable for this stuff.


And thanks for the links. Beats the heck out of trial and error in MT!


No prob. What I usually do is create it in RegExr, and then put it in the Java tester to see what works. I then copy the pattern from the Java tester page, since that formats it for Java's regex engine, which is what MapTool uses.

neofax
Great Wyrm
Posts: 1694
Joined: Tue May 26, 2009 8:51 pm
Location: Philadelphia, PA
Contact:

Re: PF statblock importer

Post by neofax »

Be careful as there are some multi-class NPC's and I am not certain this grabs the true class level in that case.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: PF statblock importer

Post by Rumble »

neofax wrote:Be careful as there are some multi-class NPC's and I am not certain this grabs the true class level in that case.


That may be. If it was warrior 5/peasant 2/cleric 4 or whatever, it wouldn't - but you could extend it to capture those as well and sum them up.

User avatar
Full Bleed
Demigod
Posts: 4547
Joined: Sun Feb 25, 2007 11:53 am
Location: MD
Contact:

Re: PF statblock importer

Post by Full Bleed »

Rumble wrote:That may be. If it was warrior 5/peasant 2/cleric 4 or whatever, it wouldn't - but you could extend it to capture those as well and sum them up.


That's exactly what I do. I loop through a list of all classes and assign levels accordingly. I have a udf that pulls the total level or the level of a particular class.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
mfrizzell
Dragon
Posts: 762
Joined: Sat Feb 13, 2010 2:35 am
Location: California

Re: PF statblock importer

Post by mfrizzell »

Rumble wrote:Something like:

Code: Select all

[h:id = strfind(statblock, "cleric.*?([0-9]+)")]


ought to do it. It's just classname(some characters)(capture group forthe number). The match is not greedy, to avoid running past the next number (or that's the idea). So that would get

cleric of iomedae 10

as well as

cleric 5


If you've never used it, I find RegExr and Java Regular Expression Test Applet invaluable for this stuff.


Thanks Rumble that second site you mention stopped the contusions from appearing on my forehead everytime I bang my head on the desk. For the life of me I could not figure out the rules for RegEx. I could monkey see monkey do whatever anyone else had done and get returns when they matched but If I needed something new I was out of luck. All of the tutorials I read didn't quite line up with the rules that MT was using. This site led me to my fisrt success so I'm real happy. So again thanks.
DCI/RPGA# 7208328396 Skype ID mfrizzell77
Characters:
Strabor - Dwarf Avenger 5th Level
Tikkanan - Human Warlock 2nd Level
----------------------------------------------------
"People are more violently opposed to fur than leather because it's safer to harass rich women than motorcycle gangs."

Post Reply

Return to “D&D 3.5/Pathfinder 1e Campaign Macros”