You can have variables be expressions and the math will still work. This allows you to have a more precise MaxMP check. You only need to use setcalc if you want to display the results of the expressions.
Here's an example from MP grading that I used to use for WHM.
Code:
<var name="MaxMP">$%SubJobSubMP + $MeritMP + $GearMP + $FoodMP</var>
Code:
<include name="MPLock2">
<changelock Lock="yes" when="$MPLockWhen" slot="$Lock02Slot|$Lock01Slot" />
<if advanced='%MP <= ($MaxMP - $Lock02MP - $Lock01MP)'>
<changelock Lock="no" when="$MPLockWhen" slot="$Lock02Slot|$Lock01Slot" />
</if>
<elseif advanced='%MP <= ($MaxMP - $Lock02MP)'>
<changelock Lock="no" when="$MPLockWhen" slot="$Lock02Slot" />
</elseif>
</include>
The same concept is used in this code for making Uggalepih Pendant work properly under Dark Arts (since %MPAfterCast does not factor in the 10% mp cost reduction -- or 20% increase under Light Arts).
Code:
<!-- 35 is MP from gear, the rest should be self explainitory -->
<var name="PendantMP">$%SubJobSubMP + $MeritMP + 35</var>
Code:
<include name="MPMultiplier">
<!-- Matching Grimoire -->
<if advanced='
((bool)buffactive("Dark Arts|Addendum: Black") AND "%Type" = "BlackMagic") OR
((bool)buffactive("Light Arts|Addendum: White") AND "%Type" = "WhiteMagic")'>
<var cmd="set MPMultiplier 0.9" />
<if buffactive="Penury|Parsimony">
<var cmd="set MPMultiplier 0.5" />
</if>
</if>
<!-- Opposing Grimoire -->
<elseif buffactive="* Arts|Addendum: *">
<var cmd="set MPMultiplier 1.2" />
</elseif>
<!-- No Grimoire -->
<else>
<var cmd="set MPMultiplier 1" />
</else>
<var cmd="setcalc MPAftercast %MP - (int)(%MPCost * $MPMultiplier)" />
<var cmd="setcalc SpellCost (int)(%MPCost * $MPMultiplier)" />
<var cmd="setcalc CastTime (%CastTime * $MPMultiplier)" />
</include>
Code:
<include name="PendantRules">
<var cmd="setcalc PendantCheck (int)(($PendantMP) * .51)" />
<if advanced='$UsePendant == 1 AND %MainJobLvl >= 70 AND $MPAftercast < $PendantCheck'>
<equip when="midcast">
<neck>Uggalepih Pendant</neck>
</equip>
<addtochat color="158">Using Pendant: [MP Aftercast: $MPAftercast (%MP - $SpellCost)] < [Trigger MP: $PendantCheck]</addtochat>
</if>
</include>