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!

Switching Mobiles in-game

Aimed

Traveler
I'm trying to create a tournament and I want that players on my shard will have their characters stored away and will get other characters for the duration of the tournament instead.

I have everything done, I just don't manage to remove control from the main character and give it to another. I don't fully understand how NetState works but I'm pretty sure it has to do with it.

Can anyone help me?

By the way, my Core is not separated from my scripts. I'm compiling it all together so I can call for Mobiles from scripts and vice-versa.
 

Vorspire

Knight
You'll be risking the loss of the PlayerMobiles associated with the account if you do this and at the minimum, a build-up of internalized Mobile instances with accounts attached to them if they are not handled correctly - a simple Delete() call on a PlayerMobile isn't enough, you have to set them 'Player = false' first (assuming you're replacing their original characters with new PlayerMobile instances).

Anyway, you should be able to switch the netstate reference over to the new mobile with something like:


> Mobile.cs
C#:
public void TransferNetStateTo( Mobile target )
{
     m_NetState.Mobile = target;

     target.NetState = m_NetState;

     NetState = null; 
}
 

Aimed

Traveler
You'll be risking the loss of the PlayerMobiles associated with the account if you do this and at the minimum, a build-up of internalized Mobile instances with accounts attached to them if they are not handled correctly - a simple Delete() call on a PlayerMobile isn't enough, you have to set them 'Player = false' first (assuming you're replacing their original characters with new PlayerMobile instances).

Anyway, you should be able to switch the netstate reference over to the new mobile with something like:


> Mobile.cs
C#:
public void TransferNetStateTo( Mobile target )
{
    m_NetState.Mobile = target;
 
    target.NetState = m_NetState;
 
    NetState = null;
}


I know about the risk that's why I'm saving the main character PlayerMobile at the account like this, code in Account.cs:
Code:
        public void SwapMainCharacter(Mobile m)
        {
            m_MainCharacter = m_Mobiles[0];
            m_Mobiles[0] = m;
        }
 
        public void RetrieveMainCharacter()
        {
            m_Mobiles[0] = m_MainCharacter;
        }

Your code will not work properly, I've already tried this : /
As soon as I set NetState on null - I can type and the text will appear above new mobile, I can equip stuff with my new mobile but my camera and my movement are still bound to the old mobile....
 

Aimed

Traveler
This is what I have atm. e.Mobile is the old mobile:
Code:
            Mobile player = new PlayerMobile();
            Container pack = player.Backpack;
 
            if (pack == null)
            {
                pack = new Backpack();
                pack.Movable = false;
 
                player.AddItem(pack);
            }
            player.Body = 0x191;
            player.Name = "Test Player";
            player.MoveToWorld(e.Mobile.Location, e.Mobile.Map);
            ((Account)e.Mobile.Account).SwapMainCharacter(player);
            player.Account = e.Mobile.Account;
            player.Player = true;
            player.NetState = e.Mobile.NetState;
            e.Mobile.NetState.Mobile = player;
            e.Mobile.Player = false;
            e.Mobile.NetState = null;

It won't allow me to move my new PlayerMobile and I'm still able to move the old e.Mobile, even while it's NetState is set on null, LOL
If I remove e.Mobile.NetState = null;
I can move both characters at the same time....
 
Top