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] [GotoByName [GotoByType

wieganka

Sorceror
At the request of Arrr, I've added these 2 commands. GotoByName will search the current map for any mobiles with the requested name, and teleport you to them. Subsequent calls to the command with the same name will teleport you to the next found mobile that has that name. Once all mobiles have been iterated through, it will start back at the beginning. I've also added a GotoByType version that will search the current map for any mobiles with the specified type.

To enable these commands, you need to edit "\Scripts\Commands\Handlers.cs". In the static Initialize() method, add in these 2 Register lines:

Code:
Register("GotoByType", AccessLevel.GameMaster, new CommandEventHandler(GotoByType_OnCommand));
Register("GotoByName", AccessLevel.GameMaster, new CommandEventHandler(GotoByName_OnCommand));

Then, outside of that method, add the following code:

Code:
private static List<Mobile> _GotoMobileTypes = new List<Mobile>();
private static string _LastGetMobileByType;
 
[Usage("GotoByType MobileType")]
[Description("Goes to a mobile based on the type.  Multiple calls will cycle to the next found mobile.")]
public static void GotoByType_OnCommand(CommandEventArgs e)
{
    // Reset the list of found mobiles if the requested type did not match the last used one.
    if (_LastGetMobileByType != null
        && String.Compare(_LastGetMobileByType, e.ArgString, StringComparison.CurrentCultureIgnoreCase) != 0)
    {
        _GotoMobileNames.Clear();
    }
 
    _LastGetMobileByType = e.ArgString;
 
    var map = e.Mobile.Map;
 
    if (map == null || map == Map.Internal) return;
 
    var mobileEnumerator = e.Mobile.Map.GetMobilesInBounds(new Rectangle2D(0, 0, map.Width, map.Height));
    var found = false;
 
    foreach (var mobile in mobileEnumerator)
    {
        var mobileTypeNames = mobile.GetType().FullName.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
        var mobileTypeName = mobileTypeNames[mobileTypeNames.Length - 1];
 
        if (String.Compare(mobileTypeName, e.ArgString, StringComparison.CurrentCultureIgnoreCase) != 0
            || _GotoMobileTypes.Contains(mobile))
            continue;
 
        found = true;
        _GotoMobileTypes.Add(mobile);
 
        if (mobile.Equals(e.Mobile))
        {
            e.Mobile.SendMessage("You found yourself!  Were you lost?");
        }
        else
        {
            e.Mobile.MoveToWorld(mobile.Location, map);
        }
 
        break;
    }
 
    if (!found)
    {
        e.Mobile.SendAsciiMessage(String.Format("No more \"{0}\" mobiles were found.  Run the command again to start from the beginning.", e.ArgString));
        _GotoMobileTypes.Clear();
        _LastGetMobileByType = null;
    }
}
 
private static List<Mobile> _GotoMobileNames = new List<Mobile>();
private static string _LastGetMobileByName;
 
[Usage("GotoByName MobileName")]
[Description("Goes to a mobile based on the name.  Multiple calls will cycle to the next found mobile.")]
public static void GotoByName_OnCommand(CommandEventArgs e)
{
    // Reset the list of found mobiles if the requested name did not match the last used one.
    if (_LastGetMobileByName != null
        && String.Compare(_LastGetMobileByName, e.ArgString, StringComparison.CurrentCultureIgnoreCase) != 0)
    {
        _GotoMobileNames.Clear();
    }
 
    _LastGetMobileByName = e.ArgString;
 
    var map = e.Mobile.Map;
 
    if (map == null || map == Map.Internal) return;
 
    var mobileEnumerator = e.Mobile.Map.GetMobilesInBounds(new Rectangle2D(0, 0, map.Width, map.Height));
    var found = false;
 
    foreach (var mobile in mobileEnumerator)
    {
        if (String.Compare(mobile.RawName, e.ArgString, StringComparison.CurrentCultureIgnoreCase) != 0
            || _GotoMobileNames.Contains(mobile))
            continue;
 
        found = true;
        _GotoMobileNames.Add(mobile);
 
        if (mobile.Equals(e.Mobile))
        {
            e.Mobile.SendMessage("You found yourself!  Were you lost?");
        }
        else
        {
            e.Mobile.MoveToWorld(mobile.Location, map);
        }
 
        break;
    }
 
    if (!found)
    {
        e.Mobile.SendAsciiMessage(String.Format("No more mobiles named \"{0}\" were found.  Run the command again to start from the beginning.", e.ArgString));
        _GotoMobileNames.Clear();
        _LastGetMobileByName = null;
    }
}

...and there you go, compile and then you are all done!
 

Arrrr

Wanderer
Thanks!! This is perfect, now i don't miss sphere at all. I'll check it out soon and report you any issue in case i find any.
 
Top