Author Topic: Creature flee and return script  (Read 447 times)

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Creature flee and return script
« on: June 03, 2012, 09:07:52 pm »


               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. 
               
               

               
            

Legacy_lovellin

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Creature flee and return script
« Reply #1 on: June 03, 2012, 09:42:48 pm »


               You have a typo in BardsCreateSignPostNPC(). You assign as new tag "WILD_AMIMAL" instead of "WILD_ANIMAL". In consequence, the second creature spawned won't find it's exit waypont as the tag doesn't match.
               
               

               
            

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
Creature flee and return script
« Reply #2 on: June 03, 2012, 11:10:01 pm »


               Oh goddess...  *face palm*  I stared at that for 2+ hours and didn't see it.  THANK YOU!