Ancordia_PRC8/_module/nss/explo_innonexit.nss
Jaysyn904 102ba7dab6 Initial Commit
Initial Commit
2023-09-21 19:51:32 -04:00

115 lines
4.2 KiB
Plaintext

#include "_sh_inc_list"
#include "69_hench_lib"
void Body(object oExiting)
{
//A workaround to prevent the OnEnter event body from firing after loading a saved game
if (GetLocalInt(GetModule(), "LoadCooldown") == TRUE) return;
if (!GetIsPC(oExiting)) return;
if (GetLocalInt(oExiting, "InnVilTransition") == TRUE)
{
DeleteLocalInt(oExiting, "InnVilTransition");
SetLocalInt(oExiting, "FromInnToVil", TRUE);
return;
}
string sAreaString = GetLocalString(OBJECT_SELF, "AreaString");
//Get the outside area, too
object oVilArea = GetArea(GetWaypointByTag("exit_wp_"+sAreaString+"_s"));
//Subtrack from the counter of PCs in the area
SetLocalInt(oVilArea, "Players", GetLocalInt(OBJECT_SELF, "Players")-1);
DeleteLocalInt(oExiting, "TalkedAdv");
DeleteLocalInt(oExiting, "Duel");
ExploreAreaForPlayer(OBJECT_SELF, oExiting, FALSE);
int nPopulated = FALSE;
object oObject; /*= GetFirstObjectInArea(OBJECT_SELF);
while (GetIsObjectValid(oObject))
{
if (GetIsPC(oObject))
{
nPopulated = TRUE;
break;
}
oObject = GetNextObjectInArea(OBJECT_SELF);
}
oObject = GetFirstObjectInArea(oVilArea);
while (GetIsObjectValid(oObject))
{
if (GetIsPC(oObject))
{
nPopulated = TRUE;
break;
}
oObject = GetNextObjectInArea(oVilArea);
}*/
if (GetLocalInt(oVilArea, "Players") > 0) nPopulated = TRUE;
if (nPopulated == FALSE)
{
DeleteLocalInt(oVilArea, "IsPopulated");
DeleteLocalInt(oVilArea, "NO_ESCAPE");
DeleteLocalInt(oVilArea, "ThugNoticed");
DeleteLocalInt(oVilArea, "TributePaid");
DeleteLocalInt(oVilArea, "Level");
DeleteLocalInt(oVilArea, "AmbushPrepared");
DeleteLocalInt(oVilArea, "Duel");
DeleteLocalInt(oVilArea, "MerchantTrouble");
DeleteLocalInt(oVilArea, "DiscoveredVillage");
DeleteLocalInt(oVilArea, "DiscoveredDungeon");
if (GetLocalInt(oVilArea, "Battle") != 0) MusicBattleChange(OBJECT_SELF, GetLocalInt(OBJECT_SELF, "Battle"));
//Delete all items and creatures in the areas and refresh the stores
location lStore;
int nStoreRefreshed;
location lInnStore;
int nInnRefreshed;
oObject = GetFirstObjectInArea(OBJECT_SELF);
while (GetIsObjectValid(oObject))
{
if (GetTag(oObject) == "anc_event_merchant" && nStoreRefreshed != TRUE)
{
lStore = GetLocation(oObject);
DestroyObject(oObject);
CreateObject(OBJECT_TYPE_STORE, "anc_event_mercha", lStore);
nStoreRefreshed = TRUE;
}
if (GetTag(oObject) == "anc_tavern" && nInnRefreshed != TRUE)
{
lInnStore = GetLocation(oObject);
DestroyObject(oObject);
CreateObject(OBJECT_TYPE_STORE, "anc_tavern", lInnStore);
nInnRefreshed = TRUE;
}
if (GetObjectType(oObject) == OBJECT_TYPE_CREATURE || GetObjectType(oObject) == OBJECT_TYPE_ITEM)
{
if ( !GetIsPC(oObject) && !GetIsPC(GetMaster(oObject)) && !GetIsPC(GetMaster(GetMaster(oObject))) && !GetIsPC(GetLastMaster(oObject)) ) //do NOT delete PCs and their associates
DestroyObject(oObject);
}
if (GetObjectType(oObject) == OBJECT_TYPE_TRIGGER)
{
DestroyObject(oObject);
}
oObject = GetNextObjectInArea(OBJECT_SELF);
}
oObject = GetFirstObjectInArea(oVilArea);
while (GetIsObjectValid(oObject))
{
if (GetObjectType(oObject) == OBJECT_TYPE_CREATURE || GetObjectType(oObject) == OBJECT_TYPE_ITEM)
{
if ( !GetIsPC(oObject) && !GetIsPC(GetMaster(oObject)) && !GetIsPC(GetMaster(GetMaster(oObject))) && !GetIsPC(GetLastMaster(oObject)) ) //do NOT delete PCs and their associates
DestroyObject(oObject);
}
oObject = GetNextObjectInArea(oVilArea);
}
}
}
void main()
{
object oExiting = GetExitingObject();
DelayCommand(1.0, Body(oExiting));
}