I thing I have done it!
The script is this:
_________________________________________________________________________________
#include "nw_i0_generic"
void main()
{
object oPC = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION,
PERCEPTION_SEEN);
ClearAllActions(TRUE);
float distance = GetDistanceBetween(OBJECT_SELF, oPC);
location loc1 = GenerateNewLocationFromLocation(GetLocation(OBJECT_SELF),distance*1.5, GetFacing(OBJECT_SELF), GetFacing(OBJECT_SELF));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectMovementSpeedIncrease(99),OBJECT_SELF,2.0f);
TurnToFaceObject(oPC,OBJECT_SELF);
ActionForceMoveToLocation(loc1, TRUE,0.3f);
ActionAttack (oPC);
}
__________________________________________________________________________________
The script, called "distanceattack" must be launched putting in heartbeat those lines:
object oPC = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION,
PERCEPTION_SEEN);
if (oPC != OBJECT_INVALID && GetIsEnemy(oPC))
if ((GetDistanceToObject(oPC) >= 3.5f) && (GetDistanceToObject(oPC) <= 6.5f))
{
ExecuteScript("distanceattack", OBJECT_SELF);
}
_______________________________________________________________________________
It works almost perfectly: every 6 seconds the enemy runs to PC and attack him.
Problems:
1- Sometime the forcemove command causes a enemy teleport.
2- Because of a interference with the other default ai scripts, sometimes between a charge and another 12 seconds passe. That dont happen if you deselect all the other ai script for the enemy npc.
3- Sometime (rarely) the enemy run in the wrong direction.
Suggestions are welcome!
Modifié par Uther78, 17 avril 2011 - 09:52 .