Author Topic: NPC recognize it's out of combat?  (Read 579 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
NPC recognize it's out of combat?
« on: February 08, 2011, 01:27:17 am »


               Where do I go to identify when an NPC is out of combat?

My objective is to have the NPC walk back to it's spawnpoint once it's out of combat using the SetLocalLocation function.
               
               

               
            

Legacy_Xovian

  • Full Member
  • ***
  • Posts: 158
  • Karma: +0/-0
NPC recognize it's out of combat?
« Reply #1 on: February 08, 2011, 01:48:46 am »


               A simple check can be added to the script you're using.

void main()
{
//Your code here
//add the following
if(GetIsInCombat(OBJECT_SELF)==FALSE)
 {
  WalkWayPoints(TRUE, 2.0);
 }

As long as you have a way point tag called (check the area marked tags on the same tab line as creatures, items ect, it will be the last one)  " WP_[insert creature name] " it will automatically walk the way points if it meets this condition. Note you'll need to make sure this script is somewhere in the OnHeartBeat script of the creature.

If you need this to be enabled across multiple areas make sure you have tag based scripting enabled and enable the cross area walk way points tag. Read through x2_inc_switch. (Or is it x2_i0_switch"? )
               
               

               


                     Modifié par Xovian, 08 février 2011 - 01:48 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
NPC recognize it's out of combat?
« Reply #2 on: February 08, 2011, 02:53:48 am »


               

Xovian wrote...


if(GetIsInCombat(OBJECT_SELF)==FALSE)

That's the stuff. I tried it by playing with the OnCombatRoundEnd, thinking it would only do the checks while the mob is in combat, but it didn't work. So I placed it in the OnPerception script.

In case this may be useful to another, below is my solution to the simple problem of having a creature return to its spawn point once it's done chasing the player.

This requiered two script changes


OnSpawn is where I recorded where the mob spawned at.


void main()
{
SetLocalLocation(OBJECT_SELF, "WHERE_I_SPAWNED", GetLocation(OBJECT_SELF));
}


OnPerception is what sends the mobs back to it's spawn point.

void main()
{
    ExecuteScript("nw_c2_default2", OBJECT_SELF);
object oNoticed = GetLastPerceived();
if (GetLastPerceptionSeen() && GetIsEnemy(oNoticed)== FALSE)
      {
         ClearAllActions();
         ActionMoveToLocation( GetLocalLocation( OBJECT_SELF, "WHERE_I_SPAWNED"));
      }
}

               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC recognize it's out of combat?
« Reply #3 on: February 08, 2011, 03:27:53 am »


               @ buddywarrior

Please note that returning to a post waypoint is already part of the default system.  



   // * Walk among a set of waypoints.

   // * 1. Find waypoints with the tag "WP_" + NPC TAG + "_##" and walk

   // *    among them in order.

   // * 2. If the tag of the Way Point is "POST_" + NPC TAG, stay there

   // *    and return to it after combat.

   //

   // * Optional Parameters:

   // * void WalkWayPoints(int nRun = FALSE, float fPause = 1.0)

   //

   // * If "NW_FLAG_DAY_NIGHT_POSTING" is set above, you can also

   // * create waypoints with the tags "WN_" + NPC Tag + "_##"

   // * and those will be walked at night. (The standard waypoints

   // * will be walked during the day.)

   // * The night "posting" waypoint tag is simply "NIGHT_" + NPC tag.


               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
NPC recognize it's out of combat?
« Reply #4 on: February 08, 2011, 12:49:26 pm »


               Agreed Lightfoot8. However I'm spawning random creatures at a single waypoint. I went with SetLocalLocation to solve the problem. I would be interested to hear other solutions for this though.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
NPC recognize it's out of combat?
« Reply #5 on: February 08, 2011, 03:59:30 pm »


               Ok,  How about just giving your creatures a new tag when you spawn them. 


const string WAY_POINT_TAG = "POST_SpawnPoint";
void main()
{
   string sResRef = "ResRef of the creature to create";
   object oWP = GetWaypointByTag(WAY_POINT_TAG);
   string sNewTag   = GetStringRight( WAY_POINT_TAG,GetStringLength(WAY_POINT_TAG)-5);
   CreateObject (OBJECT_TYPE_CREATURE, sResRef,GetLocation(oWP),FALSE,sNewTag);
}


               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
NPC recognize it's out of combat?
« Reply #6 on: February 09, 2011, 12:03:18 am »


               More of a style thing but you don't have to use true/false you can just use the ! in front of the statement so if GetIsInCombat becomes if (!GetIsInCombat()) returns true if the object in question is not in combat.
Plus I don't think you need to describe the caller as object self since it is assumed that the caller is object self.

like:
 if  (!GetIsInCombat())
//if not in combat do this...etc...
               
               

               


                     Modifié par ffbj, 09 février 2011 - 12:13 .