The OnPerception distance is too great for what you are asking (a few feet). And it only fires once per perception. The player would have to get far away from the creature and then go back into it's perception field again.
This is something that you will want to fire using the creatures OnHeartbeat event.
I made this for NPCs. You could use it or a modified version of it:
#include "nw_i0_generic"
void main()
{
object oSelf = OBJECT_SELF;
location lSelf = GetLocation(oSelf);
object oThreat = GetFirstObjectInShape(SHAPE_SPHERE, 3.0, lSelf, TRUE, OBJECT_TYPE_CREATURE);
string sThreat = GetName(oThreat);
int iWarned = GetLocalInt(oSelf, sThreat + "WARNED");
string sSay;
switch (Random(4))
{
case 0: sSay = "Get away from me" ;break;
case 1: sSay = "Leave me alone" ;break;
case 2: sSay = "Go away" ;break;
case 3: sSay = "Leave me be" ;break;
}
if (GetIsObjectValid(oThreat) && GetIsPC(oThreat) && !GetIsDead(oThreat))
{
if (!iWarned)
{
SpeakString(sSay + ".");
SetLocalInt(oSelf, sThreat + "WARNED", 1);
}
else if (iWarned == 1)
{
SpeakString("I'm warning you. " + sSay + ".");
SetLocalInt(oSelf, sThreat + "WARNED", iWarned + 1);
}
else if (iWarned == 2)
{
SpeakString("I'm not going to tell you again! " + sSay + "!");
SetLocalInt(oSelf, sThreat + "WARNED", iWarned + 1);
}
else if (iWarned > 2)
{
DetermineCombatRound(oThreat);
}
}
ExecuteScript("nw_c2_default1", oSelf);
}
It gives the player 3 warnings(and I made the creature's warnings a bit random). After that it will turn hostile and attack. It also remembers each player who gets to close and how many warnings the player has had. So if the player backs off and then comes back later it will continue with the warnings or attack if the player already had his 3 warnings, etc.. The player that is the closest to the creature will be it's current threat
If you need to modify it in any way just ask.
Hope it helps. Good luck.
Modifié par GhostOfGod, 06 juin 2011 - 05:07 .