RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

[2.x] Cleanup Mobile(s) Commands

Dian

Sorceror
Here are 3 different commands useful while world building, spawning and plain cleanup.

Commands are;

[WipePreTamed - Deletes ALL Mobiles on current facet that have been tamed at least once and released. Will not delete anything that is currently controlled (tame).

[WipeMobiles - Deletes ALL Mobiles on current facet (BaseCerature only) that is not Tame or Stabled.

[WipeVendors - Deletes ALL vendors on the current facet.

These are useful while world building, and spawning the map. I would run the WipePreTamed command just before a shard restart as needed, generally. This is the most useful for larger shards that have many tamers working their skill, and leaving massive amounts of critters wandering about, lost and confused.. put them out of their misery!

These commands are not something that would generally be needed often, but if/when the situation arises, its nice to have a command that does exactly what you want.

Download the file, or copy/paste the code from the block below, for those that can not download files.

C#:
using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Mobiles;
using Server.Commands;
 
namespace Server.Scripts.Commands
{
    public class WipePreTame
    {
        public static void Initialize()
        {
            CommandSystem.Register("WipePreTame", AccessLevel.Owner, new CommandEventHandler(WipePreTame_OnCommand));
        }
       
        [Usage( "WipePreTame" )]
            [Description( "Removes all mobiles from current map that have been tamed and released at least once." )]
        public static void WipePreTame_OnCommand( CommandEventArgs e )
              {
           
            Map map = e.Mobile.Map;
 
            if ( map == null || map == Map.Internal )
            {
                e.Mobile.SendMessage( "You may not run that command here." );
                return;
            }
 
            ArrayList list = new ArrayList();
 
            foreach ( Mobile m in World.Mobiles.Values )
            {
                if ( m.Map == map  &&  !m.Player  )
                {
                    if( m is BaseCreature )
                    {
                        if( !((BaseCreature)m).Controlled && ((BaseCreature)m).Owners.Count >= 1 && !((BaseCreature)m).IsStabled == true )
                            list.Add( m );
                    }
                }
            }
           
            if ( list.Count > 0 )
            {
                CommandLogging.WriteLine( e.Mobile, "{0} {1} starting facet clear of {2} ({3} unwanted mobiles)", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), map, list.Count );
 
                e.Mobile.SendGump(
                    new WarningGump( 1060635, 30720,
                    String.Format( "There is {0} pre-tamed creature{1} in this facet. Continuing with this command will completly delete them from this facet you are in. Do you really wish to continue?",
                    list.Count, list.Count == 1 ? "" : "s" ),
                    0xFFC000, 360, 260, new WarningGumpCallback( DelList_Callback ), list ) );
            }
            else
            {
                e.Mobile.SendMessage( "There were no mobiles found to delete." );
            }
        }
       
        public static void DelList_Callback( Mobile from, bool okay, object state )
        {
            if ( okay )
            {
                ArrayList list = (ArrayList)state;
 
                CommandLogging.WriteLine( from, "{0} {1} deleting {2} pre-tamed creatures", from.AccessLevel, CommandLogging.Format( from ), list.Count );
 
                for ( int i = 0; i < list.Count; ++i )
                {
                    object obj = list[i];
 
                    if ( obj is Item )
                        ((Item)obj).Delete();
                    else if ( obj is Mobile )
                        ((Mobile)obj).Delete();
                }
 
                from.SendMessage( "You have deleted {0} pre-tamed creature{1}.", list.Count, list.Count == 1 ? "" : "s" );
            }
            else
            {
                from.SendMessage( "You have chosen not to delete those creatures." );
            }
        }
    }
   
    public class WipeMobiles
    {
        public static void Initialize()
        {
            CommandSystem.Register( "WipeMobiles", AccessLevel.Administrator, new CommandEventHandler( WipeMobiles_OnCommand ) );
        }
       
        [Usage( "WipeMobiles" )]
            [Description( "Removes all mobiles from the current map that are not tame or stabled." )]
        public static void WipeMobiles_OnCommand( CommandEventArgs e )
              {
           
            Map map = e.Mobile.Map;
 
            if ( map == null || map == Map.Internal )
            {
                e.Mobile.SendMessage( "You may not run that command here." );
                return;
            }
 
            ArrayList list = new ArrayList();
 
            foreach ( Mobile m in World.Mobiles.Values )
            {
                if ( m.Map == map  &&  !m.Player  )
                {
                    if( m is BaseCreature )
                    {
                        if( !((BaseCreature)m).Controlled && !((BaseCreature)m).IsStabled == true )
                            list.Add( m );
                    }
                }
            }
           
            if ( list.Count > 0 )
            {
                CommandLogging.WriteLine( e.Mobile, "{0} {1} starting facet clear of {2} ({3} mobiles. )", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), map, list.Count );
 
                e.Mobile.SendGump(
                    new WarningGump( 1060635, 30720,
                    String.Format( "There is {0} mobile{1} in this facet. Continuing with this command will completly delete them from this facet you are in. After deletion, only mobiles that were spawned from a spawn item will be replaced. Do you really wish to continue?",
                    list.Count, list.Count == 1 ? "" : "s" ),
                    0xFFC000, 360, 260, new WarningGumpCallback( DelList_Callback ), list ) );
            }
            else
            {
                e.Mobile.SendMessage( "There were no mobiles found to delete." );
            }
        }
       
        public static void DelList_Callback( Mobile from, bool okay, object state )
        {
            if ( okay )
            {
                ArrayList list = (ArrayList)state;
 
                CommandLogging.WriteLine( from, "{0} {1} deleting {2} mobiles", from.AccessLevel, CommandLogging.Format( from ), list.Count );
 
                for ( int i = 0; i < list.Count; ++i )
                {
                    object obj = list[i];
 
                    if ( obj is Item )
                        ((Item)obj).Delete();
                    else if ( obj is Mobile )
                        ((Mobile)obj).Delete();
                }
 
                from.SendMessage( "You have deleted {0} mobile{1}.", list.Count, list.Count == 1 ? "" : "s" );
            }
            else
            {
                from.SendMessage( "You have chosen not to delete those mobiles." );
            }
        }
    }
   
    public class WipeVendors
    {
        public static void Initialize()
        {
            CommandSystem.Register( "WipeVendors", AccessLevel.Administrator, new CommandEventHandler( WipeVendors_OnCommand ) );
        }
       
        [Usage( "WipeVendors" )]
            [Description( "Removes all Vendors from the current map." )]
        public static void WipeVendors_OnCommand( CommandEventArgs e )
              {
           
            Map map = e.Mobile.Map;
 
            if ( map == null || map == Map.Internal )
            {
                e.Mobile.SendMessage( "You may not run that command here." );
                return;
            }
 
            ArrayList list = new ArrayList();
 
            foreach ( Mobile m in World.Mobiles.Values )
            {
                if ( m.Map == map  &&  !m.Player  )
                {
                    if( m is BaseVendor )
                    {
                    //    if( !((BaseCreature)m).Controled && ((BaseCreature)m).Owners.Count >= 1 && !((BaseCreature)m).IsStabled == true )
                            list.Add( m );
                    }
                }
            }
           
            if ( list.Count > 0 )
            {
                CommandLogging.WriteLine( e.Mobile, "{0} {1} starting facet clear of {2} ({3} vendors. )", e.Mobile.AccessLevel, CommandLogging.Format( e.Mobile ), map, list.Count );
 
                e.Mobile.SendGump(
                    new WarningGump( 1060635, 30720,
                    String.Format( "There are {0} vendor{1} in this facet. Continuing with this command will completly delete them from this facet you are in. After deletion, only vendors that were spawned from a spawn item will be replaced. Do you really wish to continue?",
                    list.Count, list.Count == 1 ? "" : "s" ),
                    0xFFC000, 360, 260, new WarningGumpCallback( DelList_Callback ), list ) );
            }
            else
            {
                e.Mobile.SendMessage( "There were no vendors found to delete." );
            }
        }
       
        public static void DelList_Callback( Mobile from, bool okay, object state )
        {
            if ( okay )
            {
                ArrayList list = (ArrayList)state;
 
                CommandLogging.WriteLine( from, "{0} {1} deleting {2} vendors", from.AccessLevel, CommandLogging.Format( from ), list.Count );
 
                for ( int i = 0; i < list.Count; ++i )
                {
                    object obj = list[i];
 
                    if ( obj is Item )
                        ((Item)obj).Delete();
                    else if ( obj is Mobile )
                        ((Mobile)obj).Delete();
                }
 
                from.SendMessage( "You have deleted {0} vendor{1}.", list.Count, list.Count == 1 ? "" : "s" );
            }
            else
            {
                from.SendMessage( "You have chosen not to delete those vendors." );
            }
        }
    }
}
 

Attachments

  • WipeMobileCommands.cs
    7.1 KB · Views: 7
Top