Code: Select all
[H: ids = getSelected()]
[H: abort(if(ids == "", 0, 1))]
[H: status=input("junk|Statblock info from Creature Name through Treasure line of Ecology (if it exists). Don't include flavor text/background/descriptions.||LABEL|SPAN=TRUE","junk|If Ecology section comes before Special Abilities, be sure to include Special Abilities section as well. Still no flavor text.||LABEL|SPAN=TRUE","statblock|Insert 5E statblock here|Enter statblock|TEXT|WIDTH=40")]
[H: abort(if(status < 1, 0, 1))]
[H: CRLF = decode("%0D%0A")]
[H: setPropertyType("5E-NPC")]
[H: GP=getProperty("dnd.weapons")]
[H: propnames = getPropertyNames()]
[H, foreach(propname,propnames),CODE: {
[resetProperty(propname)]
}]
[H: setProperty("dnd.weapons", GP)]
[H: '<!-- Lets clean up those pesky non-ascii characters! -->']
[H: statblock = replace(statblock, "\\xD7", "x")]
[H: statblock = replace(statblock, "\\u2013", "-")]
[H: statblock = replace(statblock, "\\u2014", "-")]
[H: statblock = replace(statblock, "%E2%80%93", "-")]
[H: statblock = replace(statblock, " ", " ")]
[H: '<!-- change brackets and braces to parens to avoid stat sheet variable input error -->']
[H: statblock = replace(statblock, "[\\[\\{]","(")]
[H: statblock = replace(statblock, "[\\]\\}]",")")]
[H: '<!-- Start formatting imported statblock and set it to GM notes -->']
[H: '<!-- Search for lines and sections of statblock individually -->']
[H: NameSearch = strfind(statblock, "(.*?)(CoS|OotA|SKT|PotA|ToD|VGM|MM|Tiny|Small|Medium|Large|Huge|Gargantuan)")]
[H: THEName= getGroup(NameSearch, 1, 1)]
[H: NameSearch=trim(THEName)]
[H: setName(trim(THEName))]
[H: setTokenShape("Top down")]
<!-- get stats -->
[H: regex1 = "((\\d+) *[(][\\d +-]+[)]\\t*){6}"]
[H: regex2 = "(\\d+) *[(][\\d +-]+[)]\\t*"]
[H: id = strfind(statblock,regex1)]
[H, if(getFindCount(id)), code: {
[H: stats = json.append("[]","Strength","Dexterity","Constitution","Intelligence","Wisdom","Charisma")]
[H: match = getGroup(id,1,0)]
[H: id = strfind(match,regex2)]
[H, foreach(stat,stats), code: {
[H: set(stat,getGroup(id,roll.count+1,1))]
}]
};{
[H: assert(0,"Stats in statblock not found.",0)]
}]
[H: '<!-- STATS END -->']
[H: '<!-- SET AC -->']
[H: id = strfind(statblock, "(?i)(?<!Hit )Armor Class.([0-9]*) (.*?)\Hit Points ")]
[H, IF(0< getFindCount(id)), CODE: {
[AC=getGroup(id, 1, 1)]
[ACC=getGroup(id, 1, 2)]
[IF(AC==0):AC=10+Dx]
[AC=""+AC+" "+ACC+""]
}]
[H: '<!-- SET Speed -->']
[H: id = strfind(statblock, "(?i)(?<!STR )(Speed.|burrow.|climb.|fly.|swim.)([0-9]+)")]
[H, IF(0< getFindCount(id)), CODE: {
[Speed1=getGroup(id, 1, 2)]
[IF(Speed1==""): setProperty("Speed1","")]
[IF(Speed1!=""): Speed11=getGroup(id, 1, 2)]
[IF(Speed11==""): setProperty("Speed11","")]
[Speed1="Move: "+Speed1+""]
[Spd1=""+Speed11+""]
} ;{
[Speed1=""]
[Spd1=0]
}]
[H, IF(1< getFindCount(id)), CODE: {
[Speed2=getGroup(id, 2, 1)]
[IF(Speed2==""): setProperty("Speed2","")]
[IF(Speed2!=""): Speed22=getGroup(id, 2, 2)]
[IF(Speed22==""): setProperty("Speed22","")]
[Speed2=""+upper(Speed2,1) + ": "+Speed22+""]
[Spd2=""+Speed22+""]
};{
[Spd2=0]
}]
[H, IF(2< getFindCount(id)), CODE: {
[Speed3=getGroup(id, 3, 1)]
[IF(Speed3==""): setProperty("Speed3","")]
[IF(Speed3!=""): Speed33=getGroup(id, 3, 2)]
[IF(Speed33==""): setProperty("Speed33","")]
[Speed3=""+upper(Speed3,1) + ": "+Speed33+""]
[Spd3=""+Speed33+""]
};{
[Spd3=0]
}]
[H, IF(3< getFindCount(id)), CODE: {
[Speed4=getGroup(id, 4, 1)]
[IF(Speed4==""): setProperty("Speed4","")]
[IF(Speed4!=""): Speed44=getGroup(id, 4, 2)]
[IF(Speed44==""): setProperty("Speed44","")]
[Speed4=""+upper(Speed4,1) + ": "+Speed44+""]
[Spd4=""+Speed44+""]
};{
[Spd4=0]
}]
[H, IF(4< getFindCount(id)), CODE: {
[Speed5=getGroup(id, 5, 1)]
[IF(Speed5==""): setProperty("Speed5","")]
[IF(Speed5!=""): Speed55=getGroup(id, 5, 2)]
[IF(Speed55==""): setProperty("Speed55","")]
[Speed5=""+upper(Speed5,1) + ": "+Speed55+""]
[Spd5=""+Speed55+""]
};{
[Spd5=0]
}]
[h:Speed=" "+Speed1+" "+Speed2+" "+Speed3+" "+Speed4+" "+Speed5+"" ]
[h: Spd= Max(eval("Spd1"),eval("Spd2"),eval("Spd3"),eval("Spd4"),eval("Spd5"))]
[H: '<!-- SET Hit Points -->']
[H: id = strfind(statblock, "Hit Points (\\d+) [(]([^)]+)[)]")]
[H, IF(0< getFindCount(id)), CODE: {
[HP=getGroup(id, 1, 1)]
[MaxHP=getGroup(id, 1, 1)]
[HitDice=getGroup(id,1,2)]
}]
[H: '<!-- Hit Points END -->']
[H: '<!-- SET SIZE -->']
[H: id = strfind(statblock, "(Tiny|Small|Medium|Large|Huge|Gargantuan|\w-]+)")]
[H, IF(0< getFindCount(id)),CODE: {
[Size=getGroup(id, 1, 1)]
[setSize(Size)]
}]
[H: '<!-- SET TYPE -->']
[H: id = strfind(statblock, "(aberration.*?|beast.*?|celestial.*?|construct.*?|dragon.*?|elemental.*?|fey.*?|fiend.*?|giant.*?|humanoid.*?|monstrosity.*?|ooze.*?|plant.*?|undead.*?|-)\,")]
[H, IF(0< getFindCount(id)),CODE: {
[Type=getGroup(id, 1, 1)]
[Type=upper(Type, 1)]
}]
[H: '<!-- SET ALIGNMENT -->']
[H: id = strfind(statblock, "\,.(lawful.|neutral.|chaotic.|)(good|neutral|unaligned|evil|\w-]+)")]
[H, IF(0< getFindCount(id)),CODE: {
[Alignment1=getGroup(id, 1, 1)]
[Alignment2=getGroup(id, 1, 2)]
[Alignment1=upper(Alignment1,1)]
[Alignment2=upper(Alignment2,1)]
[Alignment1=trim(Alignment1,1)]
[Alignment2=trim(Alignment2,1)]
[IF(Alignment1==""): Alignment1=""]
[Alignment=""+Alignment1+" " + Alignment2+""]
}]
[H: id = strfind(statblock, "passive Perception.([0-9]+)")]
[H, IF(0< getFindCount(id)), CODE: {
[pass=getGroup(id, 1, 1)]
[IF(pass>=0): setProperty("Passive Perception",pass)]
}]
[H: '<!-- Challenge BEGIN -->']
[H: id = strfind(statblock, "Challenge.([0-9]+)")]
[H, IF(0< getFindCount(id)), CODE: {
[CR=getGroup(id, 1, 1)]
[CR=trim(CR)]
[IF(CR<=4): setProperty("SkillDie",2)]
[IF(CR<=8&&CR>=5): setProperty("SkillDie",3)]
[IF(CR<=12&&CR>=9): setProperty("SkillDie",4)]
[IF(CR<=16&&CR>=13): setProperty("SkillDie",5)]
[IF(CR<=20&&CR>=17): setProperty("SkillDie",6)]
[IF(CR<=24&&CR>=21): setProperty("SkillDie",7)]
[IF(CR<=28&&CR>=25): setProperty("SkillDie",8)]
[IF(CR<=32&&CR>=29): setProperty("SkillDie",9)]
}]
[H: id = strfind(statblock, "Languages (.*) \Challenge")]
[H, IF(0< getFindCount(id)), CODE: {
[Lang1=getGroup(id, 1, 1)]
[Lang1 =trim(Lang1)]
[Lang1 =upper(Lang1,1)]
[IF(Lang1==""): setProperty("Lang1","")]
[Languages=" "+Lang1+""]
}]
[H: id = strfind(statblock, "(?i)\Damage Resistances?(.*?)(Damage Immunities|Condition Immunities|Senses)")]
[H, IF(0< getFindCount(id)), CODE: {
[Resist1=getGroup(id, 1, 1)]
[Resist1=trim(Resist1)]
[Resist1=upper(Resist1,1)]
[IF(Resist1==""): setProperty("Resistance","")]
[IF(Resist1!=""): setProperty("Resistance",Resist1)]
}]
[H: id = strfind(statblock, "(?i)\Damage Immunities?(.*?)(Condition Immunities|Senses)")]
[H, IF(0< getFindCount(id)), CODE: {
[Resist2=getGroup(id, 1, 1)]
[Resist2=trim(Resist2)]
[Resist2=upper(Resist2,1)]
[IF(Resist2==""): setProperty("Immunities","")]
[IF(Resist2!=""): setProperty("Immunities",Resist2)]
}]
[H: id = strfind(statblock, "(?i)\Condition Immunities?(.*?)(Senses)")]
[H, IF(0< getFindCount(id)), CODE: {
[Resist3=getGroup(id, 1, 1)]
[Resist3=trim(Resist3)]
[Resist3=upper(Resist3,1)]
[IF(Resist3==""): setProperty("Condition Immunities","")]
[IF(Resist3!=""): setProperty("Condition Immunities",Resist3)]
}]
[H: '<!-- SET SENSES AND SIGHT -->']
[h, IF(0==0), CODE:{
[H: id = strfind(statblock, "(blindsight.|darkvision.|tremorsense.|truesight.)([0-9]+)(.ft.).*?\,")]
[H, IF(0< getFindCount(id)), CODE: {
[Sense1=getGroup(id, 1, 1)]
[Sense2=getGroup(id, 1, 2)]
[Sense3=getGroup(id, 1, 3)]
[Sense1=trim(Sense1)]
[Sense2=trim(Sense2)]
[Sense3=trim(Sense3)]
[Sense1=upper(Sense1,1)]
[IF(Sense1==""): Sense1=""]
[IF(Sense2==""): Sense2=""]
[Senses=""+Sense1+" " + Sense2+" " + Sense3+" "]
[Sight1=(Sense1 +Sense2)]
[setSightType(Sight1)]
}]
[H, IF(2== getFindCount(id)), CODE: {
[Sense4=getGroup(id, 2, 1)]
[Sense5=getGroup(id, 2, 2)]
[Sense6=getGroup(id, 2, 3)]
[Sense4=trim(Sense4)]
[Sense5=trim(Sense5)]
[Sense6=trim(Sense6)]
[Sense4=upper(Sense4,1)]
[IF(Sense4==""): Sense4=""]
[IF(Sense5==""): Sense5=""]
[Senses=" "+Sense1+" " + Sense2+" " + Sense3+" " +Sense4+" " +Sense5+" " +Sense6+""]
[Sight2=(Sense4 +Sense5)]
[IF(Sense2>Sense5): setSightType(Sight1) ; setSightType(Sight2)]
}]
[IF(Senses==""): setProperty("Senses","")]
[IF(Senses==""): setHasSight(0)]
[IF(Senses!=""): setHasSight(1)]
}]
[H: '<!-- SET XP TO GM NAME -->']
[H: id = strfind(statblock, "Challenge.[0-9]+.(.*XP.)")]
[H, IF(0< getFindCount(id)), CODE: {
[XP=getGroup(id, 1, 1)]
[setGMName(XP)]
}]
[H: '<!-- HATE BARS -->']
[h: setBarVisible("Health", 0)]
[h: ids=getTokenNames()]
[h:gTok=getTokenImage()]
[h:iTok=getTokenHandout()]
[h:setProperty("PIC1",gTok)]
[h:setProperty("PIC2",iTok)]