Author Topic: spawn generic NPC and walk waypoints  (Read 586 times)

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
spawn generic NPC and walk waypoints
« on: February 11, 2011, 03:41:31 am »


               I am trying to think of a way to spawn town guards all based on the same blueprint and then have them walk waypoints. Since they would normally need different tags to do this I am not sure how to do it since I dont know of a way to adjust tags upon spawn in.

Any good solutions or thoughts? 
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
spawn generic NPC and walk waypoints
« Reply #1 on: February 11, 2011, 07:42:40 am »


               Sure. The function CreateObject has a parameter at the end to make a new tag for the object.

object CreateObject(int nObjectType, string sTemplate, location lLocation, int bUseAppearAnimation=FALSE, string sNewTag="")

I'm not sure how you are spawning them but CreateObject can do it too.

Hope it helps get ya started anyway.
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
spawn generic NPC and walk waypoints
« Reply #2 on: February 11, 2011, 10:32:23 am »


               so an example would be to make a script that creates gaurds and way points with gard tags.

// create_grds_way
void main()
{
/*

// Create an object of the specified type at lLocation.
// - nObjectType: OBJECT_TYPE_ITEM, OBJECT_TYPE_CREATURE, OBJECT_TYPE_PLACEABLE,
//   OBJECT_TYPE_STORE, OBJECT_TYPE_WAYPOINT
// - sTemplate
// - lLocation
// - bUseAppearAnimation
// - sNewTag - if this string is not empty, it will replace the default tag
// - from the template
object CreateObject(int nObjectType, string sTemplate, location lLocation, int bUseAppearAnimation=FALSE, string sNewTag="")



// stalker script (but in an NPC's OnHeartbeat script)
// supplied by Cheiron
void main()
{
    object oTarget = GetNearestCreature(
         CREATURE_TYPE_PLAYER_CHAR,
         PLAYER_CHAR_IS_PC
    );

    ClearAllActions();
    object oArea = GetArea(oTarget);
    vector vPosition = GetPosition(oTarget);

    float fOrientation = GetFacing(oTarget);
    // this is where AngleToVector shows it's powers!!
    vector vNewPos = AngleToVector(fOrientation);
    float vX = vPosition.x - vNewPos.x;
    float vY = vPosition.y - vNewPos.y;
    float vZ = vPosition.z;

    vNewPos = Vector(vX, vY, vZ);

    ActionMoveToLocation(
         Location(oArea, vNewPos, fOrientation)
    ); // go stand right behind the PC (if he's still there)
    ActionDoCommand(SetFacing(fOrientation)); // turn towards PC
}
*/
//////////////////////////////////
//
// create GaurdNPC and Waypoints
//
///////////////////////////////////
int iNumber=0;
object oEpiCenterWayPoint=GetObjectByTag("WP_EpiCenter");
object oArea = GetArea(oEpiCenterWayPoint);
vector vPosition = GetPosition(oEpiCenterWayPoint);
float fOrientation = GetFacing(oEpiCenterWayPoint);

vector vNewPos = AngleToVector(fOrientation);
// here you can +/- to x,y,z.  allowing you to place you waypoints ware you want
// randomly.  As seen in example above in the Lexicon Under Vectors
float vX=vPosition.x;
float vY=vPosition.y;
float vZ=vPosition.z;

vNewPos = Vector(vX, vY, vZ);
location lLocationWay=Location(oArea, vNewPos, fOrientation);
// note you will need a waypoint or a location for your gaurd also
iNumber ++;
string sUniqGaurdName="gard"+IntToString(iNumber);
location lLocationGaurd=GetLocation(GetObjectByTag("WP_EpiCenter"));
CreateObject(OBJECT_TYPE_CREATURE,"resref_ofgaurd",lLocationGaurd,FALSE,sUniqGaurdName);
CreateObject(OBJECT_TYPE_WAYPOINT,"WP_gaurd",lLocationWay,FALSE,"WP_"+sUniqGaurdName);
/*
1) you need to create to way points. Call first "WP_EpiCenter" place this in
center of an area.  Call second "WP_gaurd".

2) you will need to create a creature, your gaurd and think of the naming when
you name it you will create it by its resref "gaurd" is what I use for simple
script testing.

3) then use the example script, and info to do what you wanted to do by default
the npc should walk its waypoints if they match its tag.

*/

// end of script
}

NOTE: this script compiles and will work but its not 100% random it shows more of how you can create a random creature and random waypoint by using tags.  you could place this script in a triger, or a area on enter.  If you have any question please ask.
               
               

               


                     Modifié par Greyfort, 11 février 2011 - 10:36 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
spawn generic NPC and walk waypoints
« Reply #3 on: February 11, 2011, 11:15:20 pm »


               I do not have enough information to give you a well thought out responce.  What I would need to know is how you are swawning the Guards, Encounter, triggen, Area OnEnter?  Also how you are wanting to go about retriving the  Tags for to set the guards to: Stored as locals or just searching the entire area for way point sets and setting the a guard to walk each ?



If all the guards are spawned close to there walking points, It could be as simple of the trick that LordOfWorms Recently posted for changing the name on store signs:



Create a Dummy Guard blueprint.  Give it a HB script to scan for the closest waypoint, Create a Guard from your real guard blueprint setting the tag to walk the waypoints and then  self destructing.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
spawn generic NPC and walk waypoints
« Reply #4 on: February 11, 2011, 11:22:00 pm »


               One thing I do to give some randomness is to put say a dozen or so wp's along various roads, and name them all WP_Road. Then in the script of the npc's as they move around randomly I will make d4 random actions, one of which is to walk to the nearest WP_Road. In this way the npc's move around more randomly and it is difficult to predict their path. For clarification:

object oRoad = GetNearestObjectByTag ("Wp_Road");
 ActionForceMoveToObject(oRoad, FALSE);

Of course in my case the action is usually within a case statement with other possibilities included, but that is the general idea.
               
               

               


                     Modifié par ffbj, 11 février 2011 - 11:31 .
                     
                  


            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
spawn generic NPC and walk waypoints
« Reply #5 on: February 13, 2011, 08:34:05 pm »


               Thanks for the suggestions. This is what I ended up going with. It goes on enter of my encounter that spawns some randomized NPCs in the area.



#include "awa_inc_debug"

void main()

{

   if (GetLocalInt(OBJECT_SELF, "doOnce") == 0)

   //if (GetEncounterActive(OBJECT_SELF) == TRUE)

   {

string sWalkerTag = GetLocalString(OBJECT_SELF,"walker_tag");

string sWalkerRes = GetLocalString(OBJECT_SELF,"walker_resref");

string sWayPoint = GetLocalString(OBJECT_SELF,"walker_waypoint");

object oWayPoint = GetNearestObjectByTag(sWayPoint);

location lLocation = GetLocation(oWayPoint);

object oWalker = CreateObject(OBJECT_TYPE_CREATURE, sWalkerRes, lLocation, FALSE, sWalkerTag);

string sTag = GetTag(oWalker);

AWA_DEBUG("Guards tag = "+sTag);

   SetLocalInt(OBJECT_SELF, "doOnce", 1);

   }

}



I also added something into my on area exit script that runs the cleanup routine to reset the variable so that this spawns again after the creatures are destroyed.