Aller au contenu

Photo

Battle healer NPC AI


  • Veuillez vous connecter pour répondre
3 réponses à ce sujet

#1
Imperator

Imperator
  • Members
  • 64 messages

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



#2
Imperator

Imperator
  • Members
  • 64 messages

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?



#3
meaglyn

meaglyn
  • Members
  • 802 messages

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


#4
Imperator

Imperator
  • Members
  • 64 messages

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.