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 .