Author Topic: Battle healer NPC AI  (Read 590 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Battle healer NPC AI
« on: July 19, 2016, 08:00:13 am »


               

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);

}

}



               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Battle healer NPC AI
« Reply #1 on: July 19, 2016, 07:17:25 pm »


               

Nevermind, this seems to work somewhat okay, though it keeps giving me an "error" too many instructions.


 


On a side note I can't get it to cast raise dead or resurrection, it has both spells memorized and the thing it's trying to raise has set destroyable turned off. Anyone know why I can't make it raise things?



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Battle healer NPC AI
« Reply #2 on: July 25, 2016, 02:02:35 pm »


               

You need another of these inside but at the very end of the while loop block. Otherwise you are not modifying the loop condition most of the time and hence just running until you hit TMI:



oToHeal = GetNextObjectInShape(SHAPE_SPHERE, 15.0, GetLocation(OBJECT_SELF), TRUE);

               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Battle healer NPC AI
« Reply #3 on: July 25, 2016, 07:25:12 pm »


               

thank you. is it safe to use these kinds of while loops in code like.. copiously? because I want to also have instead of "GetNearestCreature." something more like what I have up here so that the AI takes into account every single actor in a given space equally. but I'm afraid it might cause lag or something. I want to use it for both the players/creatures they target as enemies and use it for all functions regarding buffs or using items on allies.