| Author |
Sticky: Post
Working Scripts Here |
| Edret
|
Posted: Wednesday, 03 July 09:32PM |
Script Name: Standard NPC Behavior v1.0
What it does: Provides a modular approach to applying standard behavior
to your NPC's. Have this script called by your NPC's heartbeat event,
apply the appropriate waypoint, and your NPC will act accordingly.
Distinguishes between day and night behaviors. The beauty of this script
is that you can use it on all but your most complex NPC's to do a wide
variety of behaviors. One script for a number of different actions.
Notes: Future versions will add more behaviors such as worshiping,
closing objects, etc. The three actions implemented here, however, will
be plenty to make convincingly real NPC's.
Although extensively tested, this is a complex script and may have a
couple bugs (although it should work fine in most standard situations).
Then again, so does NWN so no one's perfect. If you find any bugs, reply
to this message and I'll get right no it.
Here is the script:
NWScript:
#include "NW_I0_GENERIC"
void main()
{
string sNPCTag = GetTag(OBJECT_SELF);
object oWaypoint;
effect sleepEffect = EffectSleep();
if(!IsInConversation(OBJECT_SELF) && !GetIsFighting(OBJECT_SELF))
{
if(!GetIsNight())
{
if((oWaypoint = GetWaypointByTag(sNPCTag + "_WP" + "_D" + "_SLEEP")) != OBJECT_INVALID)
{
ClearAllActions();
if(GetDistanceToObject(oWaypoint) > -1.0f && GetDistanceToObject(oWaypoint) < 3.0f)
{
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, sleepEffect, OBJECT_SELF, 60.0f);
SetLocalInt(OBJECT_SELF, "NATURAL_SLEEPING", 1);
}
else
{
ActionMoveToObject(oWaypoint);
}
return;
}
if((oWaypoint = GetWaypointByTag(sNPCTag + "_WP" + "_D" + "_RANDWALK")) != OBJECT_INVALID)
{
if(GetDistanceToObject(oWaypoint) > -1.0f && GetDistanceToObject(oWaypoint) < 5.0f)
{
ActionRandomWalk();
}
else
{
ClearAllActions();
ActionMoveToObject(oWaypoint);
}
return;
}
if((oWaypoint = GetWaypointByTag(sNPCTag + "_WP+" + "_D" + "_WAYPTWALK")) != OBJECT_INVALID)
{
ClearAllActions();
WalkWayPoints();
return;
}
}
else
{
if((oWaypoint = GetWaypointByTag(sNPCTag + "_WP" + "_N" + "_SLEEP")) != OBJECT_INVALID)
{
ClearAllActions();
if(GetDistanceToObject(oWaypoint) > -1.0f && GetDistanceToObject(oWaypoint) < 3.0f)
{
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, sleepEffect, OBJECT_SELF, 60.0f);
SetLocalInt(OBJECT_SELF, "NATURAL_SLEEPING", 1);
}
else
{
ActionMoveToObject(oWaypoint);
}
return;
}
if((oWaypoint = GetWaypointByTag(sNPCTag + "_WP" + "_N" + "_RANDWALK")) != OBJECT_INVALID)
{
if(GetDistanceToObject(oWaypoint) > -1.0f && GetDistanceToObject(oWaypoint) < 5.0f)
{
ActionRandomWalk();
}
else
{
ClearAllActions();
ActionMoveToObject(oWaypoint);
}
return;
}
if((oWaypoint = GetWaypointByTag(sNPCTag + "_WP+" + "_N" + "_WAYPTWALK")) != OBJECT_INVALID)
{
ClearAllActions();
WalkWayPoints();
return;
}
}
}
}
|
|