GhostOfGod wrote...
And if anyone sees any ways to improve/correct it, feel free.
Only posting because you asked. The only thing i really see is that two locals are not really needed. You can do without the iChecked on simply by setting the other one to -1 if they have already been checked and no waypoints have been found. As far a skipping the nearest WP, It is a good Idea, however the assumption that the nearest WP is the last one they spawned from, will not always be correct. monsters wander and chase PC in combat.
One more things for the OP to consider however. If monsters chase PC's into another area, they will not respawn back into the area they left from.
@ ghost; Nice script by the way. I think what you did is a lot faster then what I was considering posting.
Here is the script with minor edits to remove the second local var.
//#include "i420_s_inc_pstat"
void BuffDamager(object oDamager)
{
//SetPCKillStats(oDamager, OBJECT_SELF);
effect eHeal = EffectHeal(1);
effect eHaste = EffectHaste();
effect eVis = EffectVisualEffect(VFX_DUR_GLOW_RED);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oDamager);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oDamager, 30.0);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eHaste, oDamager, 30.0);
}
void main()
{
object oArea = GetArea(OBJECT_SELF);
int iWPCount = GetLocalInt(oArea, "AREA_SPAWN_WPS");
object oKiller = GetLastKiller();
if (GetIsObjectValid(GetMaster(oKiller)))
oKiller = GetMaster(oKiller);
string sResRef = GetResRef(OBJECT_SELF);
object oWP;
if (!iWPCount)
{
oWP = GetNearestObjectByTag("ZSA_WAYPOINT", oKiller);
while (GetIsObjectValid(oWP))
{
iWPCount++;
oWP = GetNearestObjectByTag("ZSA_WAYPOINT", oKiller, iWPCount);
}
if ( !iWPCount) iWPCount = -1;
SetLocalInt(oArea, "AREA_SPAWN_WPS", iWPCount);
}
if (iWPCount == -1) return;
if (iWPCount == 1) oWP = GetNearestObjectByTag("ZSA_WAYPOINT", oKiller, 1);
else
{
int iRand = Random(iWPCount - 1) +2;
oWP = GetNearestObjectByTag("ZSA_WAYPOINT", oKiller, iRand);
}
CreateObject(OBJECT_TYPE_CREATURE, sResRef, GetLocation(oWP));
BuffDamager(oKiller);
}