NPC recognize it's out of combat?
#1
Posté 08 février 2011 - 01:27
My objective is to have the NPC walk back to it's spawnpoint once it's out of combat using the SetLocalLocation function.
#2
Posté 08 février 2011 - 01:48
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 .
#3
Posté 08 février 2011 - 02:53
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.Xovian wrote...
if(GetIsInCombat(OBJECT_SELF)==FALSE)
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"));
}
}
#4
Posté 08 février 2011 - 03:27
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.
#5
Posté 08 février 2011 - 12:49
#6
Posté 08 février 2011 - 03:59
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);
}
#7
Posté 09 février 2011 - 12:03
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 .





Retour en haut







