generated from Jaysyn/ModuleTemplate
71 lines
2.4 KiB
Plaintext
71 lines
2.4 KiB
Plaintext
//Since people seem to need it here is a cleanup script that will destroy BodyBags, items, and encounter creatures five minutes after the last player has left the area. This script should be placed in the OnExit event of an area.
|
|
|
|
float RandomDelay()
|
|
{
|
|
int iRND = Random(19);
|
|
float fReturn = IntToFloat(iRND) / 10.0;
|
|
return fReturn;
|
|
}
|
|
void ClearArea()
|
|
{
|
|
// Search area to find is any players are still in area
|
|
object oObject = GetFirstPC();
|
|
while (GetIsObjectValid(oObject))
|
|
{
|
|
if (GetArea(oObject) == OBJECT_SELF)
|
|
{
|
|
// Found a player
|
|
return;
|
|
}
|
|
oObject = GetNextPC();
|
|
}
|
|
// No players found in area so destroy all items, body bags, and encounter creatures
|
|
object oItem;
|
|
float fDelay;
|
|
oObject = GetFirstObjectInArea(OBJECT_SELF);
|
|
while (GetIsObjectValid(oObject))
|
|
{
|
|
//Destroy items/bodybags/encounter creatures
|
|
if (GetObjectType(oObject) == OBJECT_TYPE_ITEM &&
|
|
GetIsObjectValid(GetArea(oObject)) ||
|
|
GetObjectType(oObject) == OBJECT_TYPE_PLACEABLE &&
|
|
GetTag(oObject) == "bh_deathmarker" ||
|
|
GetObjectType(oObject) == OBJECT_TYPE_CREATURE &&
|
|
GetIsEncounterCreature(oObject))
|
|
{
|
|
// Destroy all items in objects inventory to free up memory
|
|
if (GetHasInventory(oObject))
|
|
{
|
|
oItem = GetFirstItemInInventory(oObject);
|
|
while (GetIsObjectValid(oItem))
|
|
{
|
|
fDelay = RandomDelay();
|
|
AssignCommand(oItem, SetIsDestroyable(TRUE));
|
|
DestroyObject(oItem, fDelay);
|
|
oItem = GetNextItemInInventory(oObject);
|
|
}
|
|
}
|
|
fDelay = RandomDelay();
|
|
AssignCommand(oObject, SetIsDestroyable(TRUE));
|
|
DestroyObject(oObject, 2.0 + fDelay);
|
|
}
|
|
oObject = GetNextObjectInArea(OBJECT_SELF);
|
|
}
|
|
}
|
|
void main()
|
|
{
|
|
object oObject = GetFirstPC();
|
|
while (GetIsObjectValid(oObject))
|
|
{
|
|
if (GetArea(oObject) == OBJECT_SELF)
|
|
{
|
|
// Found a player
|
|
return;
|
|
}
|
|
oObject = GetNextPC();
|
|
}
|
|
DelayCommand(600.0, ClearArea());
|
|
}
|
|
|
|
//Note that I have added delays to the objects being destryed because having a ton of objects destroyed at the same time can cause nwserver to crash or in the very least tons of lag.
|