Re: PF statblock importer
Posted: Sat May 22, 2010 5:06 pm
Nope, we want the parens because they create a regex group that can be extracted from the string as a match.
I ran into a problem with the above.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)] } ]
But some look like this:hp 92 (8d10+48)
Fort +12, Ref +5, Will +10
So, how do I get it to stop at the semi-colon OR "Fort"?hp 92 (8d10+48); regeneration 5 (fire or acid)
Fort +12, Ref +5, Will +10
Remove the trailing .?Fort and that should do it.Full Bleed wrote:So, how do I get it to stop at the semi-colon OR "Fort"?
Here's the regex I've been using to extract die rolls with pluses, inside parentheses: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.)
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.Azhrei wrote:Remove the trailing .?Fort and that should do it.Full Bleed wrote:So, how do I get it to stop at the semi-colon OR "Fort"?
Huh?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.
That did the trick! Thanks.Azhrei wrote:Try this instead:
hp ([0-9]+).(\\((.+?)\\))?
Code: Select all
[H: id = strfind(statblock, "warrior ([0-9]+)")]
Code: Select all
[h:id = strfind(statblock, "cleric.*?([0-9]+)")]
Thanks. Works great.Rumble wrote:Something like:
Code: Select all
[h:id = strfind(statblock, "cleric.*?([0-9]+)")]
And thanks for the links. Beats the heck out of trial and error in MT!If you've never used it, I find RegExr and Java Regular Expression Test Applet invaluable for this stuff.
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.Full Bleed wrote:Thanks. Works great.Rumble wrote:Something like:
Code: Select all
[h:id = strfind(statblock, "cleric.*?([0-9]+)")]
And thanks for the links. Beats the heck out of trial and error in MT!If you've never used it, I find RegExr and Java Regular Expression Test Applet invaluable for this stuff.
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.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'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.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.
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.Rumble wrote:Something like:
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 getCode: Select all
[h:id = strfind(statblock, "cleric.*?([0-9]+)")]
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.