Author Topic: NPC pursuit across an area transition  (Read 582 times)

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #15 on: August 05, 2012, 05:05:08 pm »


               

ffbj wrote...

Yeah it's certainly got something to do with the transition script. Look for instance to see if any of your monsters have these conditions:
if (GetLocalInt(GetLocalObject(oPC, "SpawnedBy"),"DontZone") == 1) return;
Whiich returns the script if either local is present on the oPC, the object which enters the transition.


It looked to me that this line was set there to stop the PC from transistioning right back to the area they left from.   Allowing them to land within the trigger in the other area.  I assumed that it is removed when they leave the trigger on the other side.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #16 on: August 05, 2012, 05:21:23 pm »


               [list=1]

  • Yeah maybe the don't zone, but the SpawnedBy, I don't know where that would come in, maybe some custon spawned creatures. Just trying to look under every rock. Still the idea of forcing the creatures toward the nearest tramsition, the one the PC exits from seems like it would be helpful.  I would turn debug just to see, it is a feature.
    You have this when debug is turned on:
        if ((oArea == OBJECT_INVALID) && (nDEBUG))

                SendMessageToPC(oPC,"Movement to an invalid area attempted.  Area was not found with specified TAG.");

        }

        else

            SendMessageToAllDMs("Object was either invalid, already zoning, or had it's Don't Zone flag set.");

    There's that Don't Zone flag which must be set by something else, since it's not set anywhere in the script.
    Grrr! it's sort of fun trying to figure it out.  Like a puzzle with missing pieces. My guess is Don't Zone is something the world maker uses to prevent certain monsters from zoning, which makes sense as you want that capability.  And the spawned by would be something set on creatures spawned by something?  Or maybe summoned creatures have that local set on them.  Just taking stabs in the dark, it seemed a logical line of reasoning though since those two locals  actually return the script.
  • You must be referring to m_n_Zoning which is set to True then False on a delay.  That's to keep the PC from just perpetually zoning I expect as you suggest. Like:
  • SetLocalInt(oPC,"m_nZoning",TRUE); Guess it stands for I am zoning, but Don't_Zone seems seperate.

               
               

               


                     Modifié par ffbj, 05 août 2012 - 04:53 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #17 on: August 05, 2012, 06:01:05 pm »


                I think  you are right about that FFBJ. BUT I must ask, is the default game behavior to cross a normal transition? Is that why you are looking for the problem in my custom area transitions?

In the meantime I rewrote my perception event.

Now I need to move on to the combat script.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #18 on: August 05, 2012, 06:21:27 pm »


               Yes that is correct regarding monsters across transitions in default transitions. Mostly it's what I call the hot pursuit effect, which is if the creature is flagged as being in combat with you they will show up, follow you through the transition.  Of course you can make this effect more or less pronounced by futzing with the AI.
So that seems to be the general thrust, yes, that it's the transition script, an accurate conjecture on your part.  Though the jury is still out.
I did a lot of work in the areas you mention.  If you want I could send you my latest module, a work in progress, which has many features you may enjoy perusing. Just PM me with your e-mail.
The vault link for the seamlesss transition script: (everyone says it's the cat's pajamas).
http://nwvault.ign.c...ts.Detail&id=89 
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #19 on: August 05, 2012, 06:34:48 pm »


               The seamless transition script that you posted is more or less what I am using.

So it appears that I'll need to come up with a solution specific to these transitions. It is a tricky thing.

Incidentally I finally decided to test if a default area transition would work with my current setup... and it does. Tricky tricky.

FYI - my Custom Area Transition is
object: trigger
type: Area Transition
tag: area_trans
all event scripts empty except for Enter which is the area_trans script.
               
               

               


                     Modifié par henesua, 05 août 2012 - 05:41 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #20 on: August 05, 2012, 06:35:11 pm »


               I would try something like this in a Special AI script. 

#include "x2_inc_switches"
#include "NW_I0_GENERIC"
void main()
{
   object oTarget = GetCreatureOverrideAIScriptTarget();
   if ( GetArea(oTarget) != GetArea(OBJECT_SELF)  )
   {
      location nTransloc = GetLocalLocation( oTarget,"Last_Trans_From");
      if (GetAreaFromLocation(nTransloc) == GetArea(OBJECT_SELF))
      {
         SetLocalObject( OBJECT_SELF, "CurrChaseTarget", oTarget);
         ClearAllActions();
         ActionMoveToLocation(nTransloc);
         float fWait = 0.5; //  Guess here.  It will need to be at least
                         //as long as your Transition delay.
         ActionWait(fWait );
         ActionDoCommand( DetermineCombatRound(oTarget));
         SetCreatureOverrideAIScriptFinished();
      }
   }
}

Now keep in mind that you will also need some in the perception script in case the PC trans hops back and forth.

If (  GetLastPerceived() == CurrChaseTarget)
 {
    ClearAllActions ();
    DetermineCombatRound(GetLastPerceived());
...


Edit:  Being pressed to do other things.   Over and out for now.
               
               

               


                     Modifié par Lightfoot8, 05 août 2012 - 05:36 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #21 on: August 05, 2012, 07:58:09 pm »


               I tried OnCombatRound end first, but was unable to getit to cough up the attempted targets etc...

Then I had a crazy idea. I was wondering about the differences between my custom area transition and the default area transition.

Difference 1: my trigger has a script assigned to on enter
Difference 2: default triggers have a destination specified while mine do not.

So I tried leaving my custom triggers the same, but giving it a destination way point.
It worked. The monsters followed my PC across the transition.

Next I tried entering a bogus way point (non existent one) ... it did not work. I transitioned via the seamless areatransition script, but the monster did not follow.

Lastly I tried entering a default way point in another area, it doesn't work. the creature does not follow but pc will transition via area transition script after briefly transitioning to the other area.


So now I have a choice, create a backup waypoint for my seamless area transitions or handle this by script in a combat script - either the function DetermineCombatRound or a custom combat AI which I will need a creative way of applying when the creature loses site of its target.
               
               

               


                     Modifié par henesua, 05 août 2012 - 06:58 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #22 on: August 05, 2012, 08:45:09 pm »


               Cool.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #23 on: August 05, 2012, 09:51:35 pm »


               

henesua wrote...

 
Then I had a crazy idea. I was wondering about the differences between my custom area transition and the default area transition Difference 1: my trigger has a script assigned to on enter

 
The differance here is not as big as you are thinking.   If there is no script assigned the Default script is ran( NW_G0_Transition.nss).   becides that not much differance, except that the script uses GetTransitionTarget to get the point to transistion to. 

 
 

 
So now I have a choice, create a backup waypoint for my seamless area transitions or handle this by script in a combat script - either the function DetermineCombatRound or a custom combat AI which I will need a creative way of applying when the creature loses site of its target.


Did the special AI script I posted above not work?
               
               

               


                     Modifié par Lightfoot8, 05 août 2012 - 08:53 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #24 on: August 05, 2012, 10:52:28 pm »


               

Lightfoot8 wrote...

henesua wrote...
Then I had a crazy idea. I was wondering about the differences between my custom area transition and the default area transition Difference 1: my trigger has a script assigned to on enter


The differance here is not as big as you are thinking.   If there is no script assigned the Default script is ran( NW_G0_Transition.nss).   becides that not much differance, except that the script uses GetTransitionTarget to get the point to transistion to.


Actually I was aware that that particular script runs on Area Transition type triggers. HOWEVER it does not run if a script is placed in OnEnter or OnClicked.

But yes, after a little investigation, I decided that difference #1 was no big deal, hence my focus on difference #2.

 Lightfoot8 wrote... 
Did the special AI script I posted above not work?


I have not tested it yet, but I am fairly confident that that approach would work. Its just that I haven't figured out the cleanest method to implement it. I already use the Custom Combat AI, and so this would require that I dynamically swap in the Pursuit AI in a particular instance, then switch the Custom Combat AI back to what it was previously when the Pursuit is complete.

I also need to create a script which determines when the Pursuit AI is needed.

THEN on top of all of that, the behavior is different than the default game behavior with transitions. So I can modify this default game behavior with this custom combat AI, or I can add way points for my seamless area transitions. At present there are benefits and costs to each of these solutions, and I'm not sure which one I want to implement in the long term.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC pursuit across an area transition
« Reply #25 on: August 06, 2012, 12:12:17 am »


               

henesua wrote...

 
I have not tested it yet, but I am fairly confident that that approach would work. Its just that I haven't figured out the cleanest method to implement it. I already use the Custom Combat AI, and so this would require that I dynamically swap in the Pursuit AI in a particular instance, then switch the Custom Combat AI back to what it was previously when the Pursuit is complete.


Yes, I was rushed before.  I originaly intended to cover this case.  
Simplest solution is to run Both.    You just need to make sure that your Chase AI is added after your normal Sp-AI.  For this example I am going to assume that the SP-AI is add on Spawn or OnEnter  and not at a random time after the creature enters the area.  So your OnAreaEnter script could contain code like the following: 

 
#include "x2_inc_switches"

const string AI_FOLLOW_SCRIPT_NAME = "sp_ai_Follow"; // or what ever.
const string SECONDARY_SP_AI_SCRIPT = "SECONDARY_SP_AI_SCRIPT";

// just because it is missing from x2_include-switches
string GetCreatureOverrideAIScript(object oCreature)
{
    return GetLocalString(oCreature,CREATURE_VAR_CUSTOM_AISCRIPT);
}

// To allow a chain
void SetSecondaryOverrideAIScript(object oCreature , string sScriptName)
{
  SetLocalString(oCreature,SECONDARY_SP_AI_SCRIPT,sScriptName);
}

// To allow a chain
string GetSecondaryOverrideAIScript(object oCreature)
{
  return GetLocalString(oCreature,SECONDARY_SP_AI_SCRIPT);
}

// A delayed function so that the the Follow AI is not added before the original.
void AddFollowSpAI ( object oCreature)
{
   string sSpAIScript =  GetCreatureOverrideAIScript(oCreature);
   if (sSpAIScript != "" && sSpAIScript != AI_FOLLOW_SCRIPT_NAME )
          SetSecondaryOverrideAIScript( oCreature, sSpAIScript);
   
   SetCreatureOverrideAIScript( oCreature, AI_FOLLOW_SCRIPT_NAME);

}


void main()
{
   object oPC = GetEnteringObject();
   if (!GetIsPC(oPC)/*&& And other checks if they can  following */)
       DelayCommand ( 0.5,AddFollowSpAI (oPC));
}


This would change your follow script to look like. 

#include "x2_inc_switches"
#include "NW_I0_GENERIC"
const string SECONDARY_SP_AI_SCRIPT = "SECONDARY_SP_AI_SCRIPT";
 // To allow a chain
string GetSecondaryOverrideAIScript(object oCreature)
{
  return GetLocalString(oCreature,SECONDARY_SP_AI_SCRIPT);
}
 
void main()
{
   object oTarget = GetCreatureOverrideAIScriptTarget();
   if ( GetArea(oTarget) != GetArea(OBJECT_SELF)  )
   {
      location nTransloc = GetLocalLocation( oTarget,"Last_Trans_From");
      if (GetAreaFromLocation(nTransloc) == GetArea(OBJECT_SELF))
      {
         ClearAllActions();
         SetLocalObject( OBJECT_SELF, "CurrChaseTarget", oTarget);
         ActionMoveToLocation(nTransloc);
         float fWait = 0.5; //  Guess here.  It will need to be at least
                         //as long as your Transition delay.
         ActionWait(fWait );
         ActionDoCommand( DetermineCombatRound(oTarget));
         SetCreatureOverrideAIScriptFinished();
         return;
      }
   }
   ExecuteScript( GetSecondaryOverrideAIScript(OBJECT_SELF),OBJECT_SELF);
}


I also need to create a script which determines when the Pursuit AI is needed.

It is handled in the AI script.    If the Creature was a target, It was in the same area.  since the target is now in a different area it needs to follow.

THEN on top of all of that, the behavior is different than the default game behavior with transitions. So I can modify this default game behavior with this custom combat AI, or I can add way points for my seamless area transitions. At present there are benefits and costs to each of these solutions, and I'm not sure which one I want to implement in the long term.


As long as your Transistion script will allow the creature to transistion I do not see a problem with the above AI.

The only thing not handled yet by the AI script is if the PC hops to an area then back.   That would need to be handled in the OnPerception script. 

if ( GetLastPerceived() == GetLocalObject( OBJECT_SELF, "CurrChaseTarget"))
{
   ClearAllActions();
   DetermineCombatRound(GetLastPerceived());
}

Just to stop them from transistioning to the area the PC just came back from.