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] [GetPlayer [GotoPlayer Commands

wieganka

Sorceror
I've decided to add these 2 commands to RunUO, and figured I'd share them with everyone else, in case they found them useful. While the Admin gump is nice, sometimes I know exactly who I need to get/goto, and that's why I added this. To use these commands, you would type "[GetPlayer PlayerName" or "[GotoPlayer PlayerName".

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("GetPlayer", AccessLevel.GameMaster, new CommandEventHandler(GetPlayer_OnCommand));
Register("GotoPlayer", AccessLevel.GameMaster, new CommandEventHandler(GotoPlayer_OnCommand));

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

Code:
[Usage("GetPlayer PlayerName")]
[Description("Gets a player based on player name.")]
public static void GetPlayer_OnCommand(CommandEventArgs e)
{
    var player = GetPlayer(e.ArgString);

    if (player == null) return;

    player.MoveToWorld(e.Mobile.Location, e.Mobile.Map);
}

[Usage("GotoPlayer PlayerName")]
[Description("Goes to a player based on player name.")]
public static void GotoPlayer_OnCommand(CommandEventArgs e)
{
    var player = GetPlayer(e.ArgString);

    if (player == null) return;

    var map = player.Map;
    var location = player.Location;

    if (map == null || map == Map.Internal)
    {
        map = player.LogoutMap;
        location = player.LogoutLocation;
    }

    if (map != null && map != Map.Internal)
    {
        e.Mobile.MoveToWorld(location, map);
    }
}

private static Mobile GetPlayer(string playerName)
{
    Mobile retVal = null;

    foreach (var account in Accounts.GetAccounts())
    {
        var accountObject = account as Account;

        if (accountObject == null) continue;

        for (var index = 0; index < accountObject.Length; index++)
        {
            var mobile = accountObject[index];

            if (mobile == null) continue;

            if (String.Compare(mobile.RawName, playerName, StringComparison.CurrentCultureIgnoreCase) != 0)
                continue;

            retVal = mobile;
            break;
        }

        if (retVal != null) break;
    }

    return retVal;
}

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

Arrrr

Wanderer
Nice. I dont know if im asking an impossible, but can you make it generic so it also handles items and monsters? In Sphere you can type ".go orc" and iterate through every orc in the world
 

wieganka

Sorceror
Nice. I dont know if im asking an impossible, but can you make it generic so it also handles items and monsters? In Sphere you can type ".go orc" and iterate through every orc in the world

That is an interesting idea. I can definitely play around with that and see what I can come up with. So, if you do ".go orc", it will transport you to the first found orc, and using it in again, will transport you to the next one...and so and and so forth? That provides some interesting dilemmas (like knowing which orcs you've already been to, and then re-cycling the list once you've been through them all).
 

Dian

Sorceror
If you are using XML spawner, you can use the [xmlfind command, and enter search key words to teleport to spawns of any given type.. not quite the same, but similarly useful.

Nice script, thanks for sharing :)
 

wieganka

Sorceror
That is an interesting idea. I can definitely play around with that and see what I can come up with. So, if you do ".go orc", it will transport you to the first found orc, and using it in again, will transport you to the next one...and so and and so forth? That provides some interesting dilemmas (like knowing which orcs you've already been to, and then re-cycling the list once you've been through them all).

Hey Arrr, here you go, as requested: http://www.runuo.com/community/threads/gotobyname-gotobytype.536000
 
Top