It seems that all sorts of wackiness ensues with encounter-spawned creatures when reloading a saved game. Not only do they lose their tags, but GetIsEncounterCreature() starts coming back FALSE instead of TRUE.
Thankfully groups persist across saved games, so I've started using the following script to spawn groups of neutral encounter creatures (like guards). It contains a modified GroupAddEncounter() function that searches around a waypoint to a specified radius, instead of lumping all encounter-spawned creatures in the area together:
------------------------------
// enc_spawn
//
// Spawn an encounter and add them to a group
// based on radius around a waypoint
#include "ginc_group"
// Add encounter spawned creatures to group sGroupName
// bWander 0 - no wander
// 1 - wander
// 2 - don't set (ude default - currently wander)
// lTarget - location of radius search
// fRadius - radius to search
void GroupAddEncounterRadius(string sGroupName, location lTarget, float fRadius, int bWander=2)
{
object oMember = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lTarget, TRUE, OBJECT_TYPE_CREATURE);
while ( GetIsObjectValid(oMember) )
{
if (GetObjectType(oMember) == OBJECT_TYPE_CREATURE)
{
if (GetIsEncounterCreature(oMember))
{
InsertIntoGroup(sGroupName, oMember, FALSE); // adds
}
}
oMember = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lTarget, TRUE, OBJECT_TYPE_CREATURE);
}
if (bWander != 2)
{
GroupSetSpawnInCondition(sGroupName, NW_FLAG_AMBIENT_ANIMATIONS, bWander);
}
}
void SpawnEncounter(object oEncounter, string sGroup, location lLoc, float fRadius)
{
SetEncounterActive(TRUE,oEncounter);
TriggerEncounter(oEncounter,GetFirstPC(),ENCOUNTER_CALC_FROM_FACTION,-1.0);
ResetGroup(GetTag(OBJECT_SELF));
GroupAddEncounterRadius(GetTag(OBJECT_SELF),lLoc, fRadius, 1);
DelayCommand(0.1, SetEncounterActive(FALSE,oEncounter));
}
void main()
{
object oEntering = GetEnteringObject();
if (!GetFactionEqual(oEntering, GetFirstPC()))
return;
string sEncounter = GetLocalString(OBJECT_SELF, "EncounterTag");
object oEncounter = GetNearestObjectByTag(sEncounter, OBJECT_SELF);
string sWP = GetLocalString(OBJECT_SELF, "WP");
float fRadius = GetLocalFloat(OBJECT_SELF, "Radius");
object oTarget = GetObjectByTag(sWP);
location lTarget = GetLocation(oTarget);
SpawnEncounter(oEncounter, sEncounter, lTarget, fRadius);
if (GetObjectType(OBJECT_SELF) == OBJECT_TYPE_TRIGGER)
DestroyObject(OBJECT_SELF, 1.0);
}
------------------------------
To make them hostile:
------------------------------
// enc_group_hostile
//
// Make group of neutral creatures hostile either from
// OnDamage script or from a placeable (door, chest, etc)
#include "ginc_group"
void main()
{
string sGroupName;
if (GetObjectType(OBJECT_SELF) == OBJECT_TYPE_CREATURE)
sGroupName = GetGroupName(OBJECT_SELF);
else
sGroupName = GetLocalString(OBJECT_SELF, "GroupName");
GroupSetScriptHidden(sGroupName, 0);
GroupSetPlotFlag(sGroupName, 0);
GroupSetImmortal(sGroupName, 0);
GroupGoHostile(sGroupName);
}
Modifié par DannJ, 10 mars 2011 - 09:53 .