Full Version : Question on a DovPlayermobile
xmlspawner >>Scripting Support >>Question on a DovPlayermobile
<< Prev | Next >>
Grimhawk- 05-10-2006
Is it possible to remove a race system using a dov playermobile without it deleting the players chars?
ArteGordon- 05-10-2006

QUOTE (Grimhawk @ May 10, 2006 04:26 pm)
Is it possible to remove a race system using a dov playermobile without it deleting the players chars?

do you mean, go from a dovplayermobile back to a regular playermobile?
yes, it is a little tricky, but it can be done.
Grimhawk- 05-10-2006
Thanks Arte. Just wanted to be sure incase my race system isn't workable with the 2.0.0. update. So I might be asking for help removing it when the update is out.
The only reference to the dovplayermobile is in the charcreation.cs so can you give me an idea of what all I might have to do to remove it?
Thanks for the help.
ArteGordon- 05-10-2006

QUOTE (Grimhawk @ May 10, 2006 04:40 pm)
Thanks Arte. Just wanted to be sure incase my race system isn't workable with the 2.0.0. update. So I might be asking for help removing it when the update is out. The only reference to the dovplayermobile is in the charcreation.cs so can you give me an idea of what all I might have to do to remove it?
Thanks for the help.

what it will involve is using a modified convertplayers.cs script and making some mods to playermobile.cs to allow you to create a playermobile with the same serial as your existing dovplayermobile, and then copy the contents of your old dovplayermobiles to the new playermobiles.
Here is an older thread where I explain how to do it.
http://runuo.com/forums/showthread.php?t=4...rt+playermobile
The same principle would apply to your case. It doesnt matter that you are going dov->playermobile instead of playermobile->dov
Grimhawk- 05-11-2006
Thanks a bunch for the help Arte. I might have more questions if it comes to me having to do that since I've only been messing with scripts a short time off and on hopefully I won't have to. My brain sometimes just doesn't soak up knowledge as good as it used to one of the drawbacks to getting old lol.
ArteGordon- 05-11-2006

QUOTE (Grimhawk @ May 11, 2006 02:01 am)
Thanks a bunch for the help Arte. I might have more questions if it comes to me having to do that since I've only been messing with scripts a short time off and on hopefully I won't have to. My brain sometimes just doesn't soak up knowledge as good as it used to one of the drawbacks to getting old lol.

yeah, I'll be happy to help you do it if you need to.
Grimhawk- 05-17-2006
Arte is this how it should be in convertplayer.cs? I'm still leary on this

CODE
using System; using System.Collections; using System.Reflection; using Server; using Server.Items;
using Server.Mobiles;
using Server.Network;
namespace Server.Scripts.Commands
{
public class ConvertPlayers
{
public static void Initialize()
{
Server.Commands.Register( "ConvertPlayers", AccessLevel.Administrator, new CommandEventHandler( Convert_OnCommand ) );
}
public static void Convert_OnCommand( CommandEventArgs e )
{
e.Mobile.SendMessage( "Converting all players to PlayerMobile. You will be disconnected. Please Restart the server after the world has finished saving." );
ArrayList mobs = new ArrayList( World.Mobiles.Values );
int count = 0;
foreach ( Mobile m in mobs )
{
if ( m.Player && !(m is PlayerMobile ) )
{
count++;
if ( m.NetState != null )
m.NetState.Dispose();
ArcMobile pm = new PlayerMobile( m.Serial );
pm.DefaultMobileInit();
pm.DefaultPlayerMobileInit();
ArrayList copy = new ArrayList( m.Items );
for (int i=0;i<copy.Count;i++)
pm.AddItem( (Item)copy[i] );
CopyProps( pm, m );
for (int i=0;i<m.Skills.Length;i++)
{
pm.Skills[i].Base = m.Skills[i].Base;
pm.Skills[i].SetLockNoRelay( m.Skills[i].Lock );
}
World.Mobiles[m.Serial] = pm;
}
}
if ( count > 0 )
{
NetState.ProcessDisposedQueue();
World.Save();
Console.WriteLine( "{0} players have been converted to PlayerMobile. Please restart the server.", count );
while ( true )
Console.ReadLine();
}
else
{
e.Mobile.SendMessage( "Couldn't find any Players to convert." );
}
}
private static void CopyProps( ArcMobile to, PlayerMobile from )
{
Type type = typeof( PlayerMobile );
PropertyInfo[] props = type.GetProperties( BindingFlags.Public | BindingFlags.Instance );
for (int p=0;p<props.Length;p++)
{
PropertyInfo prop = props[p];
if ( prop.CanRead && prop.CanWrite )
{
try
{
prop.SetValue( to, prop.GetValue( from, null ), null );
}
catch
{
}
}
}
}
}
}

Also where exactly would I place this?

CODE
public void DefaultPlayerMobileInit() { m_VisList = new ArrayList(); m_PermaFlags = new ArrayList(); m_AntiMacroTable = new Hashtable();
m_BOBFilter = new Engines.BulkOrders.BOBFilter();
m_JusticeProtectors = new ArrayList();
}

Sorry for asking so many questions but doing something like this is beyond anything I've done before.
ArteGordon- 05-17-2006
you would want to change the test here

QUOTE
public static void Convert_OnCommand( CommandEventArgs e ) { e.Mobile.SendMessage( "Converting all players to PlayerMobile. You will be disconnected. Please Restart the server after the world has finished saving." ); ArrayList mobs = new ArrayList( World.Mobiles.Values );
int count = 0;
foreach ( Mobile m in mobs )
{
if ( m.Player && !(m is PlayerMobile ) )

change that test in red to
if (m is DovPlayerMobile )
since that is what you want to select for conversion.
and this code

CODE
public void DefaultPlayerMobileInit() { m_VisList = new ArrayList(); m_PermaFlags = new ArrayList(); m_AntiMacroTable = new Hashtable();
m_BOBFilter = new Engines.BulkOrders.BOBFilter();
m_JusticeProtectors = new ArrayList();
}

goes into your PlayerMobile.cs
(edit)
looking at your code again, you have this type called ArcMobile. Is that what you are trying to convert back to PlayerMobile?
I'm assuming that ArcMobile is derived from PlayerMobile.
If so then you want to change the test to
if (m is ArcMobile)
and you want to change this
ArcMobile pm = new PlayerMobile( m.Serial );
to this
PlayerMobile pm = new PlayerMobile( m.Serial );
and then change this
CopyProps( pm, m );
to this
CopyProps( pm, (PlayerMobile )m );
and change this
private static void CopyProps( ArcMobile to, PlayerMobile from )
to this
private static void CopyProps( PlayerMobile to, PlayerMobile from )
Grimhawk- 05-17-2006
Thanks for the help Arte and yes its derived from Playermobile it gets refrenced on char creation for a race title, hue mod and start location thats it.
ArteGordon- 05-17-2006
then it should be no problem.
Grimhawk- 05-17-2006
I did something wrong though I don't know what it says its converting players though its not and they still list as the derived mobile in [props.
Any ideas Arte?
ArteGordon- 05-17-2006
after converting, save and restart.
also, post the convertplayers.cs script you are using.
Grimhawk- 05-17-2006
Here is my convertplayers.cs Arte. It automaticly saves right after doing the convertplayers command then in the RunUO window it tells you how many players it converted and to restart server. It also says you'll be disconnected right after using the command, but instead of disconnecting me it just freezes me like a lag spike and I'm stuck restarting by closing the RunUO window.

CODE
using System; using System.Collections; using System.Reflection; using Server; using Server.Items;
using Server.Mobiles;
using Server.Network;
namespace Server.Scripts.Commands
{
public class ConvertPlayers
{
public static void Initialize()
{
Server.Commands.Register( "ConvertPlayers", AccessLevel.Administrator, new CommandEventHandler( Convert_OnCommand ) );
}
public static void Convert_OnCommand( CommandEventArgs e )
{
e.Mobile.SendMessage( "Converting all players to PlayerMobile. You will be disconnected. Please Restart the server after the world has finished saving." );
ArrayList mobs = new ArrayList( World.Mobiles.Values );
int count = 0;
foreach ( Mobile m in mobs )
{
if ( m.Player && !(m is ArcMobile ) )
{
count++;
if ( m.NetState != null )
m.NetState.Dispose();
PlayerMobile pm = new PlayerMobile( m.Serial );
pm.DefaultMobileInit();
pm.DefaultPlayerMobileInit();
ArrayList copy = new ArrayList( m.Items );
for (int i=0;i<copy.Count;i++)
pm.AddItem( (Item)copy[i] );
CopyProps( pm,(PlayerMobile )m );
for (int i=0;i<m.Skills.Length;i++)
{
pm.Skills[i].Base = m.Skills[i].Base;
pm.Skills[i].SetLockNoRelay( m.Skills[i].Lock );
}
World.Mobiles[m.Serial] = pm;
}
}
if ( count > 0 )
{
NetState.ProcessDisposedQueue();
World.Save();
Console.WriteLine( "{0} players have been converted to PlayerMobile. Please restart the server.", count );
while ( true )
Console.ReadLine();
}
else
{
e.Mobile.SendMessage( "Couldn't find any Players to convert." );
}
}
private static void CopyProps( PlayerMobile to, PlayerMobile from )
{
Type type = typeof( PlayerMobile );
PropertyInfo[] props = type.GetProperties( BindingFlags.Public | BindingFlags.Instance );
for (int p=0;p<props.Length;p++)
{
PropertyInfo prop = props[p];
if ( prop.CanRead && prop.CanWrite )
{
try
{
prop.SetValue( to, prop.GetValue( from, null ), null );
}
catch
{
}
}
}
}
}
}

ArteGordon- 05-18-2006
you need to change this test
if ( m.Player && !(m is ArcMobile ) )
to
if ( m is ArcMobile )
That is what selects the players to be converted. Your current test will only select non-ArcMobile players to be converted, which is not what you want.
Grimhawk- 05-19-2006
Thanks a bunch for all the help Arte. Hopefully won't have to do it when the update comes out ,but atleast now I know how if need be.