Encountercreature Despawning
Posted: Wed Sep 03, 2003 11:59 am
This script is useful to prevent low level players from being killed by leftover creatures, spawned by higher lvl players. The script checks the area for players. If there are no players in the area, it will check for players again after 30 seconds. If there are no players at that time, the creatures and their inventory are destroyed. Commoners which are spawned using encounters will not be destroyed.
Code: Select all
/*
September 03, 2003 - Eric Ettes - Raiko - zeiren@hotmail.com
This script checks an area for encounterspawns and removes them
Place this script in the OnExit slot of an area
*/
void RemoveInventory(object oTrash){
object oInventory = GetFirstItemInInventory(oTrash);
while(oInventory != OBJECT_INVALID){
DestroyObject(oInventory);
oInventory = GetNextItemInInventory(oTrash);
}
}
void Despawn(object oArea){
object oTrash = GetFirstObjectInArea(oArea);
SetLocalInt(oArea, "DespawnPending", 0);
while(oTrash != OBJECT_INVALID){
if(GetIsEncounterCreature(oTrash) && !GetStandardFactionReputation(STANDARD_FACTION_COMMONER, oTrash)){
RemoveInventory(oTrash);
DestroyObject(oTrash);
}
oTrash = GetNextObjectInArea(oArea);
}
}
void AttemptDespawning(object oArea){
object oTrash = GetFirstObjectInArea(oArea);
while(oTrash != OBJECT_INVALID){
if(GetIsPC(oTrash)){
DelayCommand(30.0, AttemptDespawning(oArea));
return;
}
oTrash = GetNextObjectInArea(oArea);
}
Despawn(oArea);
}
void main(){
object oArea = GetArea(OBJECT_SELF);
object oTrash = GetFirstObjectInArea(oArea);
while(oTrash != OBJECT_INVALID){
if(GetIsPC(oTrash)) return;
oTrash = GetNextObjectInArea(oArea);
}
oTrash = GetFirstObjectInArea(oArea);
if(!GetLocalInt(oArea, "DespawnPending")){
SetLocalInt(oArea, "DespawnPending", 1);
DelayCommand(30.0, AttemptDespawning(oArea));
}
}