I was working on a portion where the PC can frighten the NPC and found a problem with the default state script nw_g0_fear.
nw_g0_fear only forces the frightened creature to run away from enemies rather than the person who applies the frighten effect to the subject. One potential solution to this would be to find the creator of the frightened/fear effect, but I wasn't sure if this would eat up too many resources on each heartbeat. So instead I created a local integer flag to check for.
int GetCreatureIsAfraidOfTarget(object oCreature, object oTarget) { return GetLocalInt(oCreature, "AI_AFRAID_"+ObjectToString(oCreature)); }The downside of this is that I have to delete the flag with a delay if the fear has a particular duration. Say a Delay of 30 seconds.
So which is worse? Having a 30 second delay or once a heartbeat iterating through all the affects on an NPC looking for the creature which caused the fear effect in the first place?
What about doing something like this...
void main()
{
int nFear = GetHasEffect(EFFECT_TYPE_FRIGHTENED);
object oCreator = GetEffectCreator(nFear);
SendForHelp();
//Allow the target to recieve commands for the round
SetCommandable(TRUE);
ClearAllActions();
int nCnt = 1;
//Get the nearest creature to the affected creature
object oTarget = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, nCnt);
float fDistance = GetDistanceBetween(OBJECT_SELF, oTarget);
while (GetIsObjectValid(oTarget) && fDistance < 5.0)
{
if (oTarget == oCreator)
{
//Run away if they are the source of the fear effect
ActionMoveAwayFromObject(oTarget, TRUE);
break;
}
//If not an enemy interate and find the next target
nCnt++;
oTarget = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, nCnt);
}
//Disable the ability to recieve commands.
SetCommandable(FALSE);
}





Retour en haut








