Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

243 lines
9.6 KiB
Plaintext

////////////////////////////////////////////////////////////////////////////////
// area_cleaning - Area Cleaning Script.
// By Deva B. Winblood. October 17th, 2008.
////////////////////////////////////////////////////////////////////////////////
/*
This script will cycle through each area with an AREA_DEBUG waypont
at a rate of 1 per heartbeat. It will check the AREA_DEBUG waypoint for
behavior. Here are the possible settings:
nCleanMode = 0 Default = flag each item and container with bToBeCleaned TRUE
on next pass destroy any still remaining. Plot and
artifact items will be left where they are.
1 Guardian = works similar to Default but, it will keep items
in the area worth more than a specified amount.
And store them in a guardian creature. The
creature can be killed to loot the inventory. It
will destroy items worth less than specified value.
2 Rapid = This area works like default but, will delete items
on the first pass.
3 Rapid Guardian = same as guardian but, first pass
4 Lair = Lair rules. Will act as Default if lair is NPC
controlled and no PCs are present. Otherwise, it
will not do anything as it is the player's job to
clean up areas.
5 NoClean = no cleanup done here
sGuardianR = ResRef of guardian
sGuardianT = Tag of guardian
sGuardianN = Name of guardian
nKeepValue = value in gold of items worth keeping. If this is not set then
it defaults to items worth 25 gold or more.
*/
///////////////////////////////
// PROTOTYPES
///////////////////////////////
void fnDoCleanup(object oWP);
///////////////////////////////////////////////////////[ MAIN ]/////////////////
void main()
{
object oMod=GetModule();
object oAreaWP;
int nArea=GetLocalInt(oMod,"nCleanAreaCount");
oAreaWP=GetObjectByTag("AREA_DEBUG",nArea);
if (!GetIsObjectValid(oAreaWP))
{ // start over
nArea=0;
oAreaWP=GetObjectByTag("AREA_DEBUG",nArea);
} // start over
SetLocalInt(oMod,"nCleanAreaCount",nArea+1);
if (GetIsObjectValid(oAreaWP)) DelayCommand(4.0,fnDoCleanup(oAreaWP)); // offset to keep from lagging older scripts
}
///////////////////////////////////////////////////////[ MAIN ]/////////////////
////////////////////////////
// FUNCTIONS
////////////////////////////
int fnGetValue(object oItem)
{
int nValue=0;
if (GetIdentified(oItem)==TRUE) return GetGoldPieceValue(oItem);
else
{
SetIdentified(oItem,TRUE);
nValue=GetGoldPieceValue(oItem);
SetIdentified(oItem,FALSE);
}
return nValue;
} // fnGetValue()
void fnCleanItem(object oItem,object oWP,int nMode,int nKeepValue)
{ // PURPOSE: Clean up items
int bToBeCleaned=GetLocalInt(oItem,"bToBeCleaned");
if (bToBeCleaned)
{ // to be cleaned
if (nMode==1)
{ // Guardian
object oGuardian=GetLocalObject(oWP,"oGuardianCleaner");
if (!GetIsObjectValid(oGuardian))
{ // Create Guardian
string sRes=GetLocalString(oWP,"sGuardianR");
string sTag=GetLocalString(oWP,"sGuardianT");
string sName=GetLocalString(oWP,"sGuardianN");
oGuardian=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oWP),FALSE,sTag);
if (GetIsObjectValid(oGuardian))
{ // Created
SetLocalObject(oWP,"oGuardianCleaner",oGuardian);
if (GetStringLength(sName)>0) SetName(oGuardian,sName);
} // Created
} // Create Guardian
if (GetIsObjectValid(oGuardian))
{ // it exists
object oCopy;
if (fnGetValue(oItem)>=nKeepValue)
{ // copy
oCopy=CopyItem(oItem,oGuardian,TRUE);
DeleteLocalInt(oCopy,"bToBeCleaned");
} // copy
DelayCommand(0.02,DestroyObject(oItem));
} // it exists
else
{ // error
PrintString("ERROR: area_cleaning, Guardian could not be created in area '"+GetName(GetArea(oWP))+"'");
DelayCommand(0.02,DestroyObject(oItem));
} // error
} // Guardian
else if (nMode==4)
{ // Lair
string sTeamID=GetLocalString(GetArea(oWP),"sTeamID");
object oLeader=GetLocalObject(GetModule(),"oTeamLead"+sTeamID);
if (!GetIsObjectValid(oLeader)||!GetIsPC(oLeader))
{ // valid NPC controlled team
oLeader=GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC,oWP,1);
if (!GetIsObjectValid(oLeader))
{ // no PCs in area
DelayCommand(0.02,DestroyObject(oItem));
} // no PCs in area
} // valid NPC controlled team
} // Lair
DelayCommand(0.02,DestroyObject(oItem));
} // to be cleaned
else
{ // not to be cleaned
if (nMode==0||nMode==4||nMode==1)
{ // destroyed
SetLocalInt(oItem,"bToBeCleaned",TRUE);
} // destroyed
else if (nMode==2)
{ // rapid
DelayCommand(0.02,DestroyObject(oItem));
} // rapid
else if (nMode==3)
{ // Rapid Guardian
object oGuardian=GetLocalObject(oWP,"oGuardianCleaner");
if (!GetIsObjectValid(oGuardian))
{ // Create Guardian
string sRes=GetLocalString(oWP,"sGuardianR");
string sTag=GetLocalString(oWP,"sGuardianT");
string sName=GetLocalString(oWP,"sGuardianN");
oGuardian=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oWP),FALSE,sTag);
if (GetIsObjectValid(oGuardian))
{ // Created
SetLocalObject(oWP,"oGuardianCleaner",oGuardian);
if (GetStringLength(sName)>0) SetName(oGuardian,sName);
} // Created
} // Create Guardian
if (GetIsObjectValid(oGuardian))
{ // it exists
object oCopy;
if (fnGetValue(oItem)>=nKeepValue)
{ // copy
oCopy=CopyItem(oItem,oGuardian,TRUE);
DeleteLocalInt(oCopy,"bToBeCleaned");
} // copy
DelayCommand(0.02,DestroyObject(oItem));
} // it exists
else
{ // error
PrintString("ERROR: area_cleaning, Guardian could not be created in area '"+GetName(GetArea(oWP))+"'");
DelayCommand(0.02,DestroyObject(oItem));
} // error
} // Rapid Guardian
} // not to be cleaned
} // fnCleanItem()
void fnCleanContainer(object oContainer,object oWP,int nMode,int nKeepValue)
{ // PURPOSE: Clean up containers
int bToBeCleaned=GetLocalInt(oContainer,"bToBeCleaned");
if (bToBeCleaned)
{ // to be cleaned
object oItem=GetFirstItemInInventory(oContainer);
object oCopy;
while(GetIsObjectValid(oItem))
{ // copy items
if (fnGetValue(oItem)>=nKeepValue||GetPlotFlag(oItem)||GetLocalInt(oItem,"bNoClean")||GetStringUpperCase(GetStringLeft(GetTag(oItem),4))=="RTS_")
{ // preserve
oCopy=CreateObject(OBJECT_TYPE_ITEM,GetResRef(oItem),GetLocation(oContainer),FALSE,GetTag(oItem));
DelayCommand(0.2,fnCleanItem(oCopy,oWP,nMode,nKeepValue));
DelayCommand(0.02,DestroyObject(oItem));
} // preserve
else
{ // destroy
DelayCommand(0.02,DestroyObject(oItem));
} // destroy
oItem=GetNextItemInInventory(oContainer);
} // copy items
DelayCommand(0.1,DestroyObject(oContainer));
} // to be cleaned
else
{ // not to be cleaned
SetLocalInt(oContainer,"bToBeCleaned",TRUE);
} // not to be cleaned
} // fnCleanContainer()
void fnDoCleanup(object oWP)
{ // PURPOSE: Do cleanup for this area
int nMode=GetLocalInt(oWP,"nCleanMode");
int nKeepValue=GetLocalInt(oWP,"nKeepValue");
object oItem;
object oContainer;
float fDelay=0.05;
int nN;
if (nMode==5) return;
if (nMode==0) nMode=GetLocalInt(GetArea(oWP),"nCleanMode");
if (nKeepValue<1) nKeepValue=25;
// ITEMS:
nN=1;
oItem=GetNearestObject(OBJECT_TYPE_ITEM,oWP,nN);
while(GetIsObjectValid(oItem))
{ // check items
if (!GetLocalInt(oItem,"bNoClean")&&!GetPlotFlag(oItem)&&GetStringUpperCase(GetStringLeft(GetTag(oItem),4))!="RTS_")
{ // process item
DelayCommand(fDelay,fnCleanItem(oItem,oWP,nMode,nKeepValue));
fDelay=fDelay+0.02;
} // process item
nN++;
oItem=GetNearestObject(OBJECT_TYPE_ITEM,oWP,nN);
} // check items
// CONTAINERS:
nN=1;
oContainer=GetNearestObject(OBJECT_TYPE_PLACEABLE,oWP,nN);
while(GetIsObjectValid(oContainer))
{ // check container
if (GetHasInventory(oContainer)&&!GetPlotFlag(oContainer)&&!GetLocalInt(oContainer,"bNoClean")&&!GetUseableFlag(oContainer)&&GetTag(oContainer)!="wazoo_pl_chest"&&GetTag(oContainer)!="unit_inv")
{ // container
DelayCommand(fDelay,fnCleanContainer(oItem,oWP,nMode,nKeepValue));
fDelay=fDelay+0.02;
} // container
nN++;
oContainer=GetNearestObject(OBJECT_TYPE_PLACEABLE,oWP,nN);
} // check container
} // fnDoCleanup()