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!

[xgo - make a target go to a specific place (a [go cmd modified)

fwiffo

Sorceror
A simple mod to the [go command, since I had sometime the need to move a lot of players to a specific region or to a specific location/map, I did find very bad to do it with some batch procedure (set location, set map, set blabla), and a one use command is rather perfect considering that the new [screen and other command modifiers made the work even simpler (I'm not lazy, or maybe a little, but some gamemasters in a server are at their best with using the simplest way to do something, rather than forcing them to understand everything of command modifiers).

In Commands\Generic\Commands\Commands.cs add the following

Code:
public class xGoCommand : BaseCommand
    {
        public xGoCommand()
        {
            AccessLevel = AccessLevel.GameMaster;
            Supports = CommandSupport.AllMobiles;
     
            Commands = new string[]{ "xGo" };
            ObjectTypes = ObjectTypes.Mobiles;
            Usage = "xGo \"destination\"";
            Description = "The selected mobile will be sent to specific coordinates / map / region / serial of entity / sextant coords --- It accepts command modifiers! (global - region etc!)";
        }
 
        public override void Execute ( CommandEventArgs e, object o )
        {
            Mobile mob = e.Mobile;
            Mobile from = (Mobile)o;
            if ( e.Length == 1 )
            {
                try
                {
                    int ser = e.GetInt32( 0 );
 
                    IEntity ent = World.FindEntity( ser );
 
                    if ( ent is Item )
                    {
                        Item item = (Item)ent;
 
                        Map map = item.Map;
                        Point3D loc = item.GetWorldLocation();
 
                        Mobile owner = item.RootParent as Mobile;
 
                        if( owner != null && (owner.Map != null && owner.Map != Map.Internal) && !BaseCommand.IsAccessible( from, owner ) /* !from.CanSee( owner )*/ )
                        {
                            mob.SendMessage( "You can not send to what you can not see." );
                            return;
                        }
                        else if ( owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel )
                        {
                            mob.SendMessage( "You can not send to what you can not see." );
                            return;
                        }
                        else if ( !FixMap( ref map, ref loc, item ) )
                        {
                            mob.SendMessage( "That is an internal item and you cannot send to it." );
                            return;
                        }
 
                        from.MoveToWorld( loc, map );
 
                        return;
                    }
                    else if ( ent is Mobile )
                    {
                        Mobile m = (Mobile)ent;
 
                        Map map = m.Map;
                        Point3D loc = m.Location;
 
                        Mobile owner = m;
 
                        if ( owner != null && (owner.Map != null && owner.Map != Map.Internal) && !BaseCommand.IsAccessible( from, owner ) /* !from.CanSee( owner )*/ )
                        {
                            mob.SendMessage( "You can not send to what you can not see." );
                            return;
                        }
                        else if ( owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel )
                        {
                            mob.SendMessage( "You can not send to what you can not see." );
                            return;
                        }
                        else if ( !FixMap( ref map, ref loc, m ) )
                        {
                            mob.SendMessage( "That is an internal mobile and you cannot send to it." );
                            return;
                        }
 
                        from.MoveToWorld( loc, map );
 
                        return;
                    }
                    else
                    {
                        string name = e.GetString( 0 );
                        Map map;
 
                        for ( int i = 0; i < Map.AllMaps.Count; ++i )
                        {
                            map = Map.AllMaps[i];
 
                            if ( map.MapIndex == 0x7F || map.MapIndex == 0xFF )
                                continue;
 
                            if ( Insensitive.Equals( name, map.Name ) )
                            {
                                from.Map = map;
                                return;
                            }
                        }
 
                        Dictionary<string, Region> list = from.Map.Regions;
 
                        foreach( KeyValuePair<string, Region> kvp in list )
                        {
                            Region r = kvp.Value;
 
                            if ( Insensitive.Equals( r.Name, name ) )
                            {
                                from.Location = new Point3D( r.GoLocation );
                                return;
                            }
                        }
 
                        for( int i = 0; i < Map.AllMaps.Count; ++i )
                        {
                            Map m = Map.AllMaps[i];
 
                            if( m.MapIndex == 0x7F || m.MapIndex == 0xFF || from.Map == m )
                                continue;
 
                            foreach( Region r in m.Regions.Values )
                            {
                                if( Insensitive.Equals( r.Name, name ) )
                                {
                                    from.MoveToWorld( r.GoLocation, m );
                                    return;
                                }
                            }
                        }
 
                        if ( ser != 0 )
                            mob.SendMessage( "No object with that serial was found." );
                        else
                            mob.SendMessage( "No region with that name was found." );
 
                        return;
                    }
                }
                catch
                {
                }
 
                mob.SendMessage( "Region name not found" );
            }
            else if ( e.Length == 2 || e.Length == 3 )
            {
                Map map = from.Map;
 
                if ( map != null )
                {
                    try
                    {
                        /*
                        * This to avoid being teleported to (0,0) if trying to teleport
                        * to a region with spaces in its name.
                        */
                        int x = int.Parse( e.GetString( 0 ) );
                        int y = int.Parse( e.GetString( 1 ) );
                        int z = (e.Length == 3 ) ? int.Parse( e.GetString( 2 ) ) : map.GetAverageZ( x, y );
 
                        from.Location = new Point3D( x, y, z );
                    }
                    catch
                    {
                        mob.SendMessage( "Region name not found." );
                    }
                }
            }
            else if ( e.Length == 6 )
            {
                Map map = from.Map;
 
                if ( map != null )
                {
                    Point3D p = Sextant.ReverseLookup( map, e.GetInt32( 3 ), e.GetInt32( 0 ), e.GetInt32( 4 ), e.GetInt32( 1 ), Insensitive.Equals( e.GetString( 5 ), "E" ), Insensitive.Equals( e.GetString( 2 ), "S" ) );
 
                    if ( p != Point3D.Zero )
                        from.Location = p;
                    else
                        mob.SendMessage( "Sextant reverse lookup failed." );
                }
            }
            else
            {
                mob.SendMessage( "Format: xgo [name | serial | (x y [z]) | (deg min (N | S) deg min (E | W)]" );
            }
 
            CommandLogging.WriteLine( mob, "{0} {1} using xgo on {2} \"{3}\"", mob.AccessLevel, CommandLogging.Format( mob ), CommandLogging.Format( from ), e.ArgString);
        }
 
Top