The real problem is, this creature will continue to cast this spell every freaking 6 seconds infinitely!
You should use a variable to have them only cast once every 30 seconds or 1 minute.. & Check distance too!
Of course you just don't want the NPC to stand there where they chased the PC down to, they need to return back to where they came from (their first way point).
//REVISED EDITION
//Required Include
#include "x0_i0_walkway"
void main()
{
object oCaster = OBJECT_SELF;
int nCast = GetLocalInt(oCaster, "I_BLESSED");
object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oCaster, 1, CREATURE_TYPE_IS_ALIVE, TRUE);
if(GetIsObjectValid(oTarget) && nCast != TRUE)
{
//If the PC isn't close by... stop here.. (more than 15 meters away)
if(GetDistanceBetween(oTarget, oCaster)>15.0) { return; }
//Prevent Spam
SetLocalInt(oCaster, "I_BLESSED", TRUE);
DelayCommand(30.0, SetLocalInt(oCaster, "I_BLESSED", FALSE));
ClearAllActions();
ActionCastSpellAtObject(SPELL_BLESS, oTarget, METAMAGIC_ANY, TRUE, 20,
PROJECTILE_PATH_TYPE_DEFAULT, TRUE);
}
else
{
if(!GetIsInCombat(oCaster) && !IsInConversation(oCaster))
{
//Um, since we have cast the spell, now let's return back to our station..
WalkWayPoints(FALSE, 1.0);
}
}
//End Main Script
}
//---------------------------
Just so you know for future reference, it would be A LOT better to use a trigger to assing the NPC the command to cast the spell, and of course you would want to set an integer on the Trigger to show that they have case "Bless", so that the NPC doesn't keep blessing every time the PC or anyone in the area enters the trigger. You can use DelayCommand to set the integer back to FALSE that way the NPC is ready to cast again... (maybe after 10 seconds)
////////////////////////////////////////////////////////
// This Script Goes in the OnEnter Event of a Tracks Trigger
//IMPORTANT: Enter the tagname of the NPC to cast the spell here
string NPC_TAGNAME = "tagname";
////////////////////////////////////////////////////////
//Main Script
void main()
{
object oCaster = GetNearestObjectByTag(NPC_TAGNAME, OBJECT_SELF);
object oPC = GetEnteringObject();
if(GetLocalInt(OBJECT_SELF, "BLESSED")==TRUE || !GetIsPC(oPC))
{ return; }
else
{
SetLocalInt(OBJECT_SELF, "BLESSED", TRUE);
DelayCommand(10.0, SetLocalInt(OBJECT_SELF, "BLESSED", FALSE));
AssignCommand(oCaster, ActionCastSpellAtObject(SPELL_BLESS, oPC,
METAMAGIC_ANY, TRUE, 40, PROJECTILE_PATH_TYPE_DEFAULT));
}
//Main script end..
}
Modifié par _Guile, 20 septembre 2011 - 12:29 .