asdf0523

Member
Clean up the world, use this script to clean up all the items and monsters in the world, but how to modify this file promise not to clean players ' houses and items in the House? Seeking advice!

using System;
using System.IO;
using Server;
using System.Text;
using System.Collections;
using System.Net;
using Server.Mobiles;
using Server.Network;
using Server.Commands;

namespace Server.Commands
{
public class WorldItemWipeCommand
{
public static void Initialize()
{
Register( "清理世界", AccessLevel.Administrator, new CommandEventHandler( Clearall_OnCommand ) );
}

public static void Register( string command, AccessLevel access, CommandEventHandler handler )
{
CommandSystem.Register( command, access, handler );
}

[Usage( "清理世界" )]
[Description( "Clear all facets." )]
public static void Clearall_OnCommand( CommandEventArgs e )
{
Mobile from = e.Mobile;
DateTime time = DateTime.Now;

int countItems = 0;
int countMobs = 0;
ArrayList itemsdel = new ArrayList();

foreach ( Item itemdel in World.Items.Values )
{
if ( itemdel.Parent == null )
{
itemsdel.Add( itemdel );
countItems +=1;
}
}

foreach ( Mobile mobdel in World.Mobiles.Values )
{
if ( !mobdel.Player )
{
itemsdel.Add( mobdel );
countMobs +=1;
}
}

foreach ( object itemdel2 in itemsdel )
{
if(itemdel2 is Item) ((Item)itemdel2).Delete();
if(itemdel2 is Mobile) ((Mobile)itemdel2).Delete();

}

double totalTime = ( ( DateTime.Now - time ).TotalSeconds );
from.SendMessage( "{0} items removed. {1} mobs removed. Took {2} seconds!", countItems, countMobs, totalTime );
}
}
}
 
I think one possible way to do this would be in
Code:
foreach ( Item itemdel in World.Items.Values )
{
if ( itemdel.Parent == null )
{
itemsdel.Add( itemdel );
countItems +=1;
}
}

Maybe add another "if" statement under the if ( itemdel.Parent == null ) to check if itemdel is a house or an item contained in a house region, and only do itemsdel.Add if it isn't.
 
I think one possible way to do this would be in
Code:
foreach ( Item itemdel in World.Items.Values )
{
if ( itemdel.Parent == null )
{
itemsdel.Add( itemdel );
countItems +=1;
}
}

Maybe add another "if" statement under the if ( itemdel.Parent == null ) to check if itemdel is a house or an item contained in a house region, and only do itemsdel.Add if it isn't.
Thanks a lot, this problem has been solved, thank you so much for your help!
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back