I'm trying to make a cleric ai which will get a target within a sphere around itself and if they're below half health it'll run over to them and heal them. I'm having a bit of trouble though.
object oToHeal = GetFirstObjectInShape(SHAPE_SPHERE, 15.0, GetLocation(OBJECT_SELF), TRUE);
while(GetIsObjectValid(oToHeal))
{
if(GetTag(oToHeal) != "Fighter")
{
oToHeal = GetNextObjectInShape(SHAPE_SPHERE, 15.0, GetLocation(OBJECT_SELF), TRUE);
continue;
}
if(GetCurrentHitPoints(oToHeal)<=(GetMaxHitPoints(oToHeal)/2))
{
ClearAllActions();
ActionCastSpellAtObject(SPELL_HEAL, oToHeal);
}
}