Clear Area Script

Hello everbody,

Can anyone please help with a script that fires when the player leaves a area and that deletes any objects, creatures, corpses, placeables, sounds, lights etc. EXCEPT waypoints in that specific area?

Thank you very much in advance!

B.

Try with this, the script should be slotted in the “On Exit” event slot of the area that you intend to clear when the player leaves it.

void main()
{
	object oPC = GetExitingObject();
	if (GetIsOwnedByPlayer(oPC) == FALSE) return;
	
	object oAREA = OBJECT_SELF;
	object oOBJ = GetFirstObjectInArea(oAREA);
	while (oOBJ != OBJECT_INVALID)
	{
		if (GetObjectType(oOBJ) != OBJECT_TYPE_WAYPOINT)
		{
			SetPlotFlag(oOBJ, FALSE);
			SetImmortal(oOBJ, FALSE);
			DestroyObject(oOBJ, 0.5);
		}
		oOBJ = GetNextObjectInArea(oAREA);
	}
}
2 Likes

Works like a charm.

Thank you, @Clangeddin !

@Blackwood

Wow!

You really need to destroy all objects but waypoints? :dizzy_face:

Yes, I’m working on a rogue-like system where areas are infinitely used while placeables, enemies and so on are assigned randomly every time you enter them.

2 Likes

@Blackwood

I was guessing a random dungeon type effect - I imagine that to be quite some task to get working with all the varying placeables and potential sizes and orientations. All the best! :+1:

1 Like

The different orientations of placeables are the worst. A lot of trial and error. But I hope that the replayability will make it worthwhile in the end.

2 Likes

Scoops up the nifty bit of code :alien:

1 Like