Question for the scripting gods (from a barely adequate scripter.)
I'm trying to write a generic creature (wild animal) flee and return script. The idea is, when the creature with a tag of WILD_ANIMAL sees a PC or an enemy, it will flee to the nearest WP tagged EXIT_WILD_ANIMAL After a certain delay it will respawn - the creature resref is stored as var string. (Eventually I want it to respawn at the exit waypoint and walk back to it's original location) Right now I have it respawning where it fled from though. It works for the first creature. But when the second one respawns, it doesn't flee. It just destorys itself after a delay -- and another one respawns with the same result. Here's my code in the OnUserDefined of the creature.
void BardsCreateSignPostNPC(string sTag, location lLocal)
{
object oCreature = CreateObject(OBJECT_TYPE_CREATURE, sTag, lLocal, FALSE, "WILD_AMIMAL");
SetLocalString(oCreature, "RESREF", sTag);
}
void BardsFleeToExitAndRespawn(float fDelay) {
string sTag = GetTag(OBJECT_SELF);
object oExitWay = GetWaypointByTag("EXIT_" + sTag);
ActionMoveToObject(oExitWay, TRUE);
location lLocal = GetLocation(OBJECT_SELF);
sTag = GetLocalString(OBJECT_SELF, "RESREF");
DelayCommand(fDelay, ActionDoCommand(BardsCreateSignPostNPC(sTag, lLocal)));
DelayCommand(fDelay, ActionDoCommand(DestroyObject(OBJECT_SELF, 1.0)));
}
int nCalledBy=GetUserDefinedEventNumber();
void main()
{
switch(nCalledBy)
{
case 1002: // Called by OnPerception
object oSeen=GetLastPerceived();
if ((GetIsPC(oSeen) && GetLastPerceptionSeen()) || (GetIsEnemy(oSeen) && GetLastPerceptionSeen())) {
ClearAllActions();
effect eGoFast = EffectMovementSpeedIncrease(50); // panic flee
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eGoFast, OBJECT_SELF);
BardsFleeToExitAndRespawn(20.0);
}
break;
}
}
Any help would be greatly appreciated.