Another spell calculate problem :-(

Hi all,

OK i'm stumped again :-(

I want to have a spell effect that will be autocast on tactical battles, that kills the caster unless they have a particular unitstat.  Here's the game modifier I am using from the spell effect:

<GameModifier>
   <ModType>Unit</ModType>
   <Attribute>CurHealth</Attribute>
   <Calculate InternalName="Calc" ValueOwner="CastingUnit">
      <Expression><![CDATA[[Unit_GetHPCurrent] * 1]]></Expression>
   </Calculate>
   <Calculate InternalName="Calc2" ValueOwner="CastingUnit">
      <Expression><![CDATA[[UnitStat_JB_CanRideDemonSteed] * [Calc]]]></Expression>
   </Calculate>
   <Calculate InternalName="Calc3" ValueOwner="CastingUnit">
      <Expression><![CDATA[[Calc] - [Calc2]]]></Expression>
   </Calculate>
   <Calculate InternalName="Value">
      <Expression><![CDATA[[Calc3] * -1]]></Expression>
   </Calculate>
</GameModifier>

Now it *almost* works.  After lots of testing (using my 17HP test Sov who has the appropriate unitstat to survive), I have established that:

1) Calc = 17

2) UnitStat_JB_CanRideDemonSteed = 1

3) Calc2 = 17

But for some reason, the Value comes out as -17 (and the poor fella gets killed).

It should be zero... Calc3 should be 17 - 17 = 0 right?  So I think the culprit is Calc3 which seems to be equating to 0 for some reason.  I'm new to this spell calculation stuff and it seems there are a few gotchas.

Hoping mqpiffle, HF or something else with knowledge of this area might eb able to help me out (again) ;-)

Thanks.

 

 

 

 

2,293 views 3 replies
Reply #1 Top

Looks right.

Reply #2 Top

Still working on it but something seems not quite working as expected.

This test spell for example, should subtract 50% hit points unless caster level is 1 (or more) in which case they should take no damage.

Calc2 seems to come out as zero though, because the caster always takes the 50% damage.

 

<SpellDef InternalName="JB_TestSpell98">
   <DisplayName>Test Spell 98 </DisplayName>
   <Description>+5 Fire attack</Description>
   <Image>T_Confusion_Painting.png</Image>
   <IconFG>T_Confusion_Icon.png</IconFG>
   <IconBG>T_Wither_Icon_BG.png</IconBG>
   <IconColor>32,45,243</IconColor>
   <AutoUnlock>1</AutoUnlock>
   <CanStack>0</CanStack>
   <SpellBookSortCategory>Unit</SpellBookSortCategory>
   <SpellBookSortSubCategory>UnitEnchantment</SpellBookSortSubCategory>
   <SpellType>Tactical</SpellType>
   <SpellClass>Defensive</SpellClass>   
   <SpellSubClass>Buff</SpellSubClass>
   <SpellTargetType>FriendlyUnit</SpellTargetType>
   <Range>0</Range>
   <HideInHiergamenon>1</HideInHiergamenon>
   <GameModifier>
      <ModType>Unit</ModType>
      <Attribute>AdjustUnitStat</Attribute>
      <StrVal>UnitStat_Attack_Fire</StrVal>
      <Duration>-1</Duration>
      <Effect>A_Fire_Particle_04</Effect>
      <Value>5</Value>
   </GameModifier>
   <GameModifier>
      <ModType>Unit</ModType>
      <Attribute>CurHealth</Attribute>
      <Calculate InternalName="Calc" ValueOwner="CastingUnit">
         <Expression><![CDATA[[Unit_GetHPCurrent] * 0.5]]></Expression>
      </Calculate>
      <Calculate InternalName="Calc2" ValueOwner="CastingUnit">
          <Expression><![CDATA[[Unit_GetLevel] * [Calc]]]></Expression>
      </Calculate>
      <Calculate InternalName="Calc3" ValueOwner="CastingUnit">
         <Expression><![CDATA[[Calc] - [Calc2]]]></Expression>
      </Calculate>
      <Calculate InternalName="Value">
         <Expression><![CDATA[[Calc3] * -1]]></Expression>
      </Calculate>
   </GameModifier>
   <AIData AIPersonality="AI_General">
      <AIPriority>10</AIPriority>
   </AIData>
   <HitSoundFX>Spell_FlameDart_01</HitSoundFX>
</SpellDef>

Reply #3 Top

OK so I think I got this to work using a revised calculation approach.  Couldn't get it working the other way, some strange problem with the substraction part.  I found if I avoided the [calc] - [calc2] stuff it works fine.  So now i'm using this which seems right.  It kills the caster outright unless they have the appropriate unitstat.

 

<GameModifier>
   <ModType>Unit</ModType>
   <Attribute>CurHealth</Attribute>
   <Calculate InternalName="Calc" ValueOwner="CastingUnit">
      <Expression><![CDATA[[Unit_GetHPCurrent] * 1]]></Expression>
   </Calculate>
   <Calculate InternalName="Calc2" ValueOwner="CastingUnit">
       <Expression><![CDATA[[UnitStat_JB_CanRideDemonSteed] - 1]]></Expression>
   </Calculate>
   <Calculate InternalName="Value">
      <Expression><![CDATA[[Calc2] * [Calc]]]></Expression>
   </Calculate>
</GameModifier>

 

Thanks.