Tag-playing kids
Want some action on your town/city streets? Here is the code for some kids
playing "tag".
You need two or more kids with the tag "TAGCHILD" in your area, which have
the spawn in condition NW_FLAG_HEARBEAT_EVENT set in their OnSpawn script.
Exactly one of them needs to have the local variable "nChasing" set to 1 in
the same script:
SetLocalInt(OBJECT_SELF, "nChasing", 1);
In the custom OnUserDefined script insert the following code in the
HEARTBEAT section (nUser==1001).
If you don't want them to play the whole time, you can encapsulate the code
in some starting condition.
NWScript:
if (GetLocalInt(OBJECT_SELF, "nChasing") == 1)
{
object oChased = GetNearestObjectByTag("TAGCHILD");
if (GetDistanceToObject(oChased) < 1.0f )
{
SpeakString("Tag!");
AssignCommand(oChased, ClearAllActions());
SetLocalInt(OBJECT_SELF, "nChasing", 0);
SetLocalInt(oChased, "nTagged", 1);
ClearAllActions();
ActionMoveAwayFromObject(oChased, TRUE);
}
else
{
ActionForceMoveToObject(oChased, TRUE, 0.0f);
}
}
else
{
if (GetLocalInt(OBJECT_SELF, "nTagged") == 1)
{
SetLocalInt(OBJECT_SELF, "nTagged", 0);
SetLocalInt(OBJECT_SELF, "nChasing", 1);
}
else
{
object oChaser = GetNearestObjectByTag("TAGCHILD");
if (GetLocalInt(oChaser, "nChasing") == 1)
ActionMoveAwayFromObject(oChaser, TRUE);
else
ActionForceMoveToObject(oChaser, TRUE, 8.0f);
}
}
Be careful with this code, as it places some overhead on you Heartbeat
Events, adding too many kids can affect performance.
Also, this kiddies go all over the place, even opening doors. Make sure they
can't get into dangerous areas, unless you want some awful atrocities.
Have fun, Uthoroc
|