I had a look at the alchemist's poison resistances, and tried to implement it for my ability, but since this ability is a custom ability, xIndex and xCount aren't valid fields. Instead, I tried using abValue as the argument to swap resistance for immunity:
<Pre-levels 1000>
Code:
If we're not active, just get out now
doneif (tagis[Helper.SpcDisable] <> 0)
~ see if a quickfind has been created by another copy
perform quickfind.setfocus
~ if we didn't find a redirection, we're the first copy of this ability to run this script, so we'll make ourselves the FirstCopy.
if (state.isfocus = 0) then
perform quickadd
perform assign[Helper.FirstCopy]
~Add the base value of 2
field[abValue].value += 2
~ otherwise, redirect hero.child[] to the FirstCopy, and make us an upgrade
else
perform focus.redirect
perform assign[Helper.SpecUp]
perform assign[Hide.Statblock]
~ add +2 to the focus's value
focus.field[abValue].value += 2
endif
<Post-levels 10000>
Code:
doneif (tagis[Helper.SpcDisable] <> 0)
doneif (tagis[Helper.FirstCopy] = 0)
if (field[abValue].value <= 6) then
#situational[hero.child[svAll],signed(field[abValue].value) & " bonus on all saving throws against poison.",field[thingname].text]
else
~ If 4 copies are active, that's immunity
if (field[abValue].value >= 8) then
~ We also want to change our special type from resistance to immunity
perform delete[SpecType.Resist]
perform assign[SpecType.Immune]
~ Since we're adding the immune to poison special, this ability
~ doesn't need to be shown once we're an immunity
perform assign[Helper.SpecUp]
endif
endif
<Render 5000>
Code:
if (field[abValue].value <= 6) then
field[livename].text = field[thingname].text & " +" & field[abValue].value
else
field[livename].text = field[thingname].text & " Immunity to poison"
endif
Everything works until the 4th time the hero selects the ability. Resistance to Poison disappears, but immunity to poison doesn't replace it.