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!

Scripts wont compile with Warnings

Fastburn

Sorceror
I have been developing a shard on a windows computer before pushing it to our dedicated live server. I recently started moving the scripts over and have attempted to start the server. In Windows, this compiles fine (with no errors/ some warnings), in Mono-RunUO it fails to compile (with no errors / some warnings)

If I remove the indicated scripts, it boots up fine. The scripts are not incredibly vital, but they are things we want to use. I am not sure if I can fix the warnings. If anyone can tell me how to force it to compile with warnings like windows, that would help. Otherwise, any help repairing these warnings would be great.

Code:
$ mono RunUO.exe
RunUO - [www.runuo.com] Version 2.0, Build 3567.9188
Core: Running on .NET Framework Version 2.0.50727
Core: Optimizing for 4 processors
Core: Unix environment detected
Scripts: Compiling C# scripts...ScriptCompiler: : /home/sl/runuotest/RunUO.exe (Location of the symbol related to previous warning)
done (0 errors, 2 warnings)
Warnings:
+ Custom/Commands/Staff/Control.cs:
    CS0108: Line 575: `Server.Items.ControlItem.Items' hides inherited member `Server.Item.Items'. Use the new keyword if hiding was intended
+ Custom/Systems/Publisher/Publisher.cs:
    CS0162: Line 92: Unreachable code detected
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

The offending 'warning' scripts:

Control.cs
Code:
/*********************************************
Version: 1.0.1

Changes:
1.0.1:
    - Added "private static object Construct(...)" to "class ControlCommand"
    - Following command arguments added: NoStats, NoSkills, NoItems

-- Please do not edit this Header --

Scripted by Quick_silver
for www.Welt-von-Midgrd.ch
and everyone who want to use it.

Please note me if you make Changes in the Scripts.

|*****Instalation*****>
Notice strings in engish are commented in the code, so you can replace the germans.

To uncontrol at death add the following lines to the PlayerMobbile.cs or edit the OnBeforeDeath() function.

    public override bool OnBeforeDeath()
    {
        return ControlCommand.UncontrolDeath( (Mobile)this );
    }

And now: Have fun...

*********************************************/

using System;
using System.Collections;
using System.Reflection;
using Server.Mobiles;
using Server.Targeting;
using Server.Items;
using Server.Commands;
 
namespace Server.Mobiles
{
    public class ControlCommand
    {
        public static AccessLevel accessLevel = AccessLevel.GameMaster;

        private static Layer[] m_DesiredLayerOrder = new Layer[]
        {
            Layer.Cloak,
            Layer.Bracelet,
            Layer.Ring,
            Layer.Shirt,
            Layer.Pants,
            Layer.InnerLegs,
            Layer.Shoes,
            Layer.Arms,
            Layer.InnerTorso,
            Layer.MiddleTorso,
            Layer.OuterLegs,
            Layer.Neck,
            Layer.Waist,
            Layer.Gloves,
            Layer.OuterTorso,
            Layer.OneHanded,
            Layer.TwoHanded,
            Layer.FacialHair,
            Layer.Hair,
            Layer.Helm
        };

        public static void Initialize()
        {
            CommandSystem.Register( "Control", accessLevel, new CommandEventHandler( Control_OnCommand ) );
        }

        [Usage( "Control [target]" )]
        [Description( "Lets you control a NPC" )]
        //"Let you control a NPC."
        private static void Control_OnCommand( CommandEventArgs e )
        {
            Mobile from = e.Mobile;

            e.GetInt32( 0 );

            if ( from != null )
            {
                from.SendMessage( "Choose the target to control?" );
                //"Choose the target to control..."

                from.Target = new InternalTarget( e.Arguments );
            }
        }

        private class InternalTarget : Target
        {
            string[] m_parameter;

            public InternalTarget( params string[] parameter ) : base( -1, true, TargetFlags.None )
            {
                m_parameter = parameter;
            }

            protected override void OnTarget( Mobile from, object targeted )
            {
                bool stats = true;
                bool skills = true;
                bool items = true;

                for (int i=0; i<m_parameter.Length; i++)
                    if (string.Compare(m_parameter[i], "NoStats", true) == 0)
                        stats = false;

                for (int i=0; i<m_parameter.Length; i++)
                    if (string.Compare(m_parameter[i], "NoSkills", true) == 0)
                        skills = false;

                for (int i=0; i<m_parameter.Length; i++)
                    if (string.Compare(m_parameter[i], "NoItems", true) == 0)
                        items = false;
 
                DoControl( from, targeted, stats, skills, items );
            }
        }

        public static ControlItem GetControlItem( Mobile from )
        {
            Item result = SearchItemInCont( typeof(ControlItem), from.Backpack);

            if ( result != null && result is ControlItem )
                return (ControlItem)result;
            else
                return null;
        }

        private static Item SearchItemInCont( Type targetType, Container cont )
        {
            Item item;

            if( cont != null && !cont.Deleted )
            {
                for (int i = 0; i < cont.Items.Count;i++)
                {
                    item = (Item)cont.Items[i];
                    // recursively search containers
                    if( item != null && !item.Deleted)
                    {
                        if ( item.GetType() == targetType )
                            return item;
                        else if ( item is Container )
                            item = SearchItemInCont(targetType, (Container)item);

                        if ( item != null && item.GetType() == targetType )
                            return item;
                    }
                }
            }

            return null;
        }

        public static void DoControl( Mobile from, object targeted, bool stats, bool skills, bool items )
        {
            Mobile target;

            if ( from is PlayerMobile && targeted is Mobile)
            {
                if ( targeted is PlayerMobile && ((PlayerMobile)targeted).Player )
                {
                    from.SendMessage("You Cant control players");
                    //"You cant control players"
                    return;
                }

                target = (Mobile)targeted;
                ControlItem controlItem = GetControlItem(from);

                if ( controlItem == null )
                {
                    from.SendMessage("Stats: {0} Skills: {1} Items: {2}", stats, skills, items);
                    StartControl(from, target, stats, skills, items);
                }
                else
                {
                    from.SendMessage("Stats: {0} Skills: {1} Items: {2}", controlItem.Stats, controlItem.Skills, controlItem.Items);
                    ChangeControl(target, controlItem, controlItem.Stats, controlItem.Skills, controlItem.Items);
                }
            }
            else if ( from is PlayerMobile && targeted is ControlItem )
                ((Item)targeted).Delete();
        }
 
        private static void StartControl( Mobile from, Mobile target, bool stats, bool skills, bool items )
        {
            from.SendMessage("You leave your Body an control {0}, {1}", target.Name, target.Title);
            //"You leave your Body an control {0}, {1}"

            //Clone Player
            PlayerMobile playerClone = (PlayerMobile)DupeMobile(from);

            //Create ControlItem
            ControlItem controlItem = new ControlItem(from, playerClone, target, stats, skills, items);
            from.Backpack.DropItem(controlItem);

            //Backup Equip
            MoveEquip(from, playerClone, items);
            //Equip from target to player
            MoveEquip(target, from, items);
            CopyProps(target, from, stats, skills);

            target.Internalize();
            playerClone.Internalize();

        }

        private static void ChangeControl( Mobile target, ControlItem controlItem, bool stats, bool skills, bool items )
        {

            Mobile from                            = controlItem.Owner;
            PlayerMobile oldPlayer    = controlItem.Player;
            Mobile oldNPC                      = controlItem.NPC;

            if ( oldNPC != null )
            {
                //NPC Wiederherstellen
                if ( !oldNPC.Deleted )
                {
                    //Props immer übernehmen bei der Rückverwandlung?
                    CopyProps( from, oldNPC, stats, skills );
                    MoveEquip(from, oldNPC, items);
                }
                else
                {
                    from.SendMessage("Der originale NPC wurde gelöscht und wird nicht wiederhergestellt. Grund könnte ein manueller Respawn gewesen sein");
                    oldNPC.Delete();
                }
            }

            //Neuen Mobile übernehmen oder Control abbrechen
            if ( target != oldPlayer && target != null && !target.Deleted ) //Neues Mobile übernehmen
            {
                from.SendMessage("You Control {0}, {1}", target.Name, target.Title);
                //"You Control  {0}, {1}"

                //Update ControlItem
                controlItem.NPC = target;
                controlItem.Stats = stats;
                controlItem.Skills = skills;
                controlItem.Items = items;

                CopyProps( target, from, stats, skills );
                MoveEquip(target, from, items);

                target.Internalize();
            }
            else if ( target == oldPlayer && !target.Deleted )
            {
                controlItem.Delete();
            }
        }

        public static void EndControl( ControlItem controlItem, bool stats, bool skills, bool items )
        {
            Mobile from                            = controlItem.Owner;
            PlayerMobile oldPlayer    = controlItem.Player;
            Mobile oldNPC                      = controlItem.NPC;

            if ( from == null )
                return;

            from.SendMessage("You are in your original Body");
            //"You are in your original Body"

            //NPC wiederherstellen
            if ( oldNPC != null && !oldNPC.Deleted )
            {
                //Props immer übernehmen bei der Rückverwandlung?
                CopyProps( from, oldNPC, stats, skills );
                MoveEquip( from, oldNPC, items );
            }
            else
            {
                from.SendMessage("The original NPC was deleted. Maybe because a manual respawn");
                //"The original NPC was deleted. Maybe because a manual respawn"
                oldNPC.Delete();
            }

            if ( oldPlayer != null && !oldPlayer.Deleted )
            {
                //Spieler Wiederherstellen (100%)
                CopyProps( oldPlayer, from, true, true );
                MoveEquip( oldPlayer, from, true );

                oldPlayer.Delete();
            }
        }

        public static bool UncontrolDeath( Mobile from )
        {
            if ( from.AccessLevel < accessLevel )
                return true;

            ControlItem controlItem = GetControlItem(from);

            if ( controlItem != null )
            {
                controlItem.Delete();
                from.Hits = from.HitsMax;
                return false;
            }

            return true;
        }

        private static void MoveEquip( Mobile from, Mobile to, bool items)
        {
            Item item;

            for ( int i = 0; i < m_DesiredLayerOrder.Length; ++i )
            {
                item = to.FindItemOnLayer( m_DesiredLayerOrder[i] );
                if ( item != null )
                    item.Bounce(to);

                item = from.FindItemOnLayer( m_DesiredLayerOrder[i] );
                if( item != null )
                {
                    to.EquipItem(item);
                }
            }

            //Backpack
            if ( from.Backpack != null && !(from.Backpack is VendorBackpack) && items )
            {

                if ( to.Backpack == null )
                    to.EquipItem( new Backpack() );

                ArrayList itemsToMove = new ArrayList();

                for (int i = 0; i < from.Backpack.Items.Count;++i)
                {
                    item = (Item)from.Backpack.Items[i];

                    if( item != null && !item.Deleted && item.LootType != LootType.Newbied && item.LootType != LootType.Blessed )
                    {
                        itemsToMove.Add( item );
                    }
                }

                for ( int i = 0; i < itemsToMove.Count; ++i)
                {
                    to.Backpack.DropItem((Item)itemsToMove[i]);
                }
                itemsToMove.Clear();

            }
        }

        //With items for DupeCommand?
        public static Mobile DupeMobile( object mobile )
        {
            Type t = mobile.GetType();
            object o = Construct(t);

            if (o == null)
            {
                Console.WriteLine("Unable to dupe {0}. Mobile must have a 0 parameter constructor.",t.Name);
                return null;
            }

            if (o is Mobile)
            {
                Mobile newMobile = (Mobile)o;
                Mobile srcMobile = (Mobile)mobile;
                CopyProperties( o, mobile, t, "Parent", "NetState" );

                newMobile.Player = false;
                newMobile.UpdateTotals();
                return newMobile;
            }

            return null;
        }

        private static void CopyProps(Mobile from, Mobile target, bool stats, bool skills)
        {
            try
            {
                if ( from.Map == Map.Internal )
                    from.MoveToWorld(target.Location, target.Map);

                if ( stats )
                    CopyMobileProps( target, from, "Parent", "NetState", "Player", "AccessLevel" );
                else
                    CopyMobileProps( target, from, "Parent", "NetState", "Player", "AccessLevel", "RawStr", "Str", "RawDex", "Dex", "RawInt", "Int", "Hits", "Mana", "Stam" );

                if ( skills )
                    for ( int i = 0; i < target.Skills.Length; ++i )
                    {
                        target.Skills[i].Base = from.Skills[i].Base;
                    }
            }
            catch
            {
                Console.WriteLine("Error in Control.cs -> CopyProps(Mobile from, Mobile target, bool stats, bool skills)");
                return;
            }
        }

        private static void CopyMobileProps( Mobile dest, Mobile src, params string[] omitProps )
        {
            Type type = src.GetType();

            PropertyInfo[] props = type.GetProperties();

            for ( int i = 0; i < props.Length; i++ )
            {
                try
                {
                    bool omit = false;
                    for (int j=0; j<omitProps.Length; j++)
                        if (string.Compare(omitProps[j], props[i].Name, true) == 0)
                        {
                            omit = true;
                            break;
                        }

                    if ( props[i].CanRead && props[i].CanWrite && !omit)
                    {
                        props[i].SetValue( dest, props[i].GetValue( src, null ), null );
                    }
                }
                catch
                {
                    //Console.WriteLine( "Denied" );
                }
            }
        }

        private static bool CompareType(object o, Type type)
        {
            if (o.GetType() == type || o.GetType().IsSubclassOf(type))
                return true;
            else
                return false;
        }

        private static void CopyProperties ( object dest, object src, Type type , params string[] omitProps )
        {
            if (!CompareType(dest,type) || !CompareType(src,type) || (dest.GetType() != src.GetType()) )
                return;

            PropertyInfo[] props = type.GetProperties();

            for ( int i = 0; i < props.Length; i++ )
            {
                try
                {
                    bool omit = false;
                    for (int j=0; j<omitProps.Length; j++)
                        if (string.Compare(omitProps[j], props[i].Name, true) == 0)
                        {
                            omit = true;
                            break;
                        }

                    if ( props[i].CanRead && props[i].CanWrite && !omit)
                    {
                        //Console.WriteLine( "Setting {0} = {1}", props[i].Name, props[i].GetValue( src, null ) );
                        props[i].SetValue( dest, props[i].GetValue( src, null ), null );
                    }
                }
                catch
                {
                    //Console.WriteLine( "Denied" );
                }
            }
        }

        private static object Construct( Type type, params object[] constructParams)
        {
            bool constructed=false;
            object toReturn=null;
            ConstructorInfo[] info = type.GetConstructors();

            foreach ( ConstructorInfo c in info )
            {
                if (constructed) break;
                ParameterInfo[] paramInfo = c.GetParameters();

                if ( paramInfo.Length == constructParams.Length )
                {
                    try
                    {
                        object o = c.Invoke( constructParams );

                        if ( o != null )
                        {
                            constructed = true;
                            toReturn = o;
                        }
                    }
                    catch
                    {
                        toReturn = null;
                    }
                }
            }
            return toReturn;
        }
 
    }

}
 
namespace Server.Items
{
    public class ControlItem : Item
    {
        private Mobile m_Owner;
        private Mobile m_Player;
        private Mobile m_NPC;

        private bool m_Stats;
        private bool m_Skills;
        private bool m_Items;

        [CommandProperty( AccessLevel.GameMaster )]
        public PlayerMobile Owner
        {
            get
            {
                if ( m_Player is PlayerMobile )
                    return (PlayerMobile)m_Owner;
                else return null;
            }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public PlayerMobile Player
        {
            get
            {
                if ( m_Player is PlayerMobile )
                    return (PlayerMobile)m_Player;
                else return null;
            }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public Mobile NPC
        {
            get{ return m_NPC; }
            set{ m_NPC = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool Stats
        {
            get{ return m_Stats; }
            set{ m_Stats = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool Skills
        {
            get{ return m_Skills; }
            set{ m_Skills = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool Items
        {
            get{ return m_Items; }
            set{ m_Items = value; }
        }
 
        public ControlItem( Mobile owner, Mobile player, Mobile npc, bool stats, bool skills, bool items ) : base( 0x2106 )
        {
            m_Owner = owner;
            m_Player = player;
            m_NPC = npc;

            m_Stats = stats;
            m_Skills = skills;
            m_Items = items;

            Name = "Control Item";
            LootType = LootType.Blessed;
        }

        public ControlItem( Mobile owner, Mobile player, Mobile npc ) : base( 0x2106 )
        {
            m_Owner = owner;
            m_Player = player;
            m_NPC = npc;

            m_Stats = true;
            m_Skills = true;
            m_Items = true;

            Name = "Control Item";
            LootType = LootType.Blessed;
        }
 
        public ControlItem( Serial serial ) : base( serial )
        {
        }
 
        public override void OnDoubleClick( Mobile from )
        {
            if ( from == m_Owner )
                Delete();

            base.OnDoubleClick( from );
        }

        public override void OnAdded( object parent )
        {
            base.OnAdded( parent );

            if ( RootParent != m_Owner )
                Delete();
        }

        public override bool DropToWorld( Mobile from, Point3D p )
        {
            Delete();
 
            return false;
            //return base.DropToWorld( from, p );
        }
 
        public override void OnDelete()
        {
            ControlCommand.EndControl( this, m_Stats, m_Skills, m_Items );

            base.OnDelete();
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.Write( (int) 1 ); // version

            //Version 1
            writer.Write( (bool)m_Stats );
            writer.Write( (bool)m_Skills );
            writer.Write( (bool)m_Items );

            //Version 0
            writer.Write( (Mobile)m_Owner );
            writer.Write( (Mobile)m_Player );
            writer.Write( (Mobile)m_NPC );

        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();

            switch ( version )
            {
                case 1:
                {
                    m_Stats = reader.ReadBool();
                    m_Skills = reader.ReadBool();
                    m_Items = reader.ReadBool();
                    goto case 0;
                }
                case 0:
                {
                    m_Owner = reader.ReadMobile();
                    m_Player = reader.ReadMobile();
                    m_NPC = reader.ReadMobile();
                    break;
                }
            }

        }
   
    }
}

Publisher.cs
Code:
using System;
using System.Collections;
using Server.Items;
using Server.ContextMenus;
using Server.Misc;
using Server.Network;
using Server;
using System.Data;
using Server.Engines.Publisher;

namespace Server.Mobiles
{
    public class Publisher: BaseVendor
    {
        #region Construction Logic

        [Constructable]
        public Publisher() : base( "the publisher" )
        {
        }
        public Publisher( Serial serial ) : base( serial )
        {
        }
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.Write( (int) 0 ); // version
        }
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();
        }
        #endregion

        #region SBInfo
        private ArrayList m_SBInfos = new ArrayList();
        protected override ArrayList SBInfos{ get { return m_SBInfos; } }
        public override void InitSBInfo()
        {
            m_SBInfos.Add( new SBPublisher() );
        }
        #endregion

        public override NpcGuild NpcGuild{ get{ return NpcGuild.BardsGuild; } }
        public override bool HandlesOnSpeech( Mobile from )
        {
            if ( from.InRange( this.Location, 12 ) )
                return true;

            return base.HandlesOnSpeech( from );
        }
        public override void OnSpeech( SpeechEventArgs e )
        {
            // TODO: read keywords and respond with information on publishing

            if (e.Mobile.Criminal)
            {
                e.Handled = true;
                this.Say(500389); // I will not do business with a criminal!
                base.OnSpeech( e );
                return;
            }
            base.OnSpeech( e );
        }
//        public override void AddCustomContextEntries( Mobile from, ArrayList list )
//        {
//            // view media
//
//            //if ( from.Alive )
//            //    list.Add( new OpenMedia( from, this ) );
//
//            base.AddCustomContextEntries( from, list );
//        }
        public override bool OnDragDrop(Mobile from, Item dropped)
        {
            if (dropped is BaseBook)
            {
                BaseBook book = (BaseBook)dropped;

                if( book.Author == null )//added
                {
                    return false;
                }
                else if( book != null )//was if
                {
                    Publish( from, book );
                Effects.PlaySound(from.Location, from.Map, 0x249);
                return base.OnDragDrop (from, dropped);
                return true;
                }

            }
            else
            {
                PublicOverheadMessage( MessageType.Regular, 0x3B2, 500607 ); // I'm not interested in that.
                    return false;
            }

            return base.OnDragDrop (from, dropped);
        }

        private void Publish(Mobile contributor, BaseBook book)
        {
            PublishedBook publishedBook = book as PublishedBook;
            if(publishedBook != null)
            {
                publishedBook.AddContributor(contributor.Name);
                Republish(contributor, publishedBook);
                return;
            }

            // change into published book
            publishedBook = new PublishedBook(book);
            publishedBook.AddContributor(contributor.Name);
            if(!publishedBook.IsPublishable())
            {
                publishedBook.Delete();
                this.SayTo(contributor, "You might want to try writing something of interest first.");
            }
            else if(XmlBook.Save(publishedBook))
            {
                switch (Utility.Random( 3 ) )
                {
                    case 0:
                    {
                        contributor.AddToBackpack(new Gold(300, 400));
                        this.SayTo(contributor, "This seems to be a excellent material. Let me see... hm... here - your royalty. You should see the story soon. I am sure it will sell well.");
                        contributor.SendMessage("You receive a good amount of gold.");

                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }

                    case 1:
                    {
                        contributor.AddToBackpack(new Gold(200, 300));
                        this.SayTo(contributor, "This seems to be decent material. Let me see... hm... here - your royalty. You should see the story soon. I hope it will sell well.");
                        contributor.SendMessage("You receive a decent amount of gold.");

                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }

                    case 2:
                    {
                        contributor.AddToBackpack(new Gold(100, 200));
                        this.SayTo(contributor, "I don't know if this is good enough to be sold, but let me see... hm... here - I can't give you more for this. I am not sure it will sell at all.");
                        contributor.SendMessage("You receive some gold.");

                        contributor.AddToBackpack(publishedBook);
                        book.Delete();
                        break;
                    }
 
                }
 
            }
            else
            {
                publishedBook.Delete();
                this.SayTo(contributor, "Our machines are not working right. Check back later.");
            }
        }

        private void Republish(Mobile contributor, PublishedBook book)
        {
            if(!book.IsPublishable())
            {
                this.SayTo(contributor, "You might want to try writing something of interest first.");
            }
            else if(book.IsModified())
            {
                book.AddContributor(contributor.Name);
                if(XmlBook.Save(book))
                {
                    book.RePublish();
                    contributor.AddToBackpack(new Gold (100));
                    this.SayTo(contributor, "Your book appears to have changed. Let me publish that for you!");
                    contributor.SendMessage("You receive some gold.");

                }
                else
                {
                    this.SayTo(contributor, "Our machines are not working right. Check back later.");
                }
            }
            else
            {
                this.SayTo(contributor, "It looks the same as the last story we printed.");
            }
        }
    }
}
 

Soteric

Knight
Control.cs
Code:
private bool m_Items;

[CommandProperty( AccessLevel.GameMaster )]
        public bool Items
        {
            get{ return m_Items; }
            set{ m_Items = value; }
        }
You have to use other names instead of Items and m_Items because those are already used in base Item class.

Publisher.cs
Rich (BB code):
                return base.OnDragDrop (from, dropped);
                return true;
The code in red will never be executed because first return stops the method execution. That's what compiler is trying to tell you.
 

Fastburn

Sorceror
Thank you, I was able to get the Publisher warning fixed. I'm still stumped on the Control script, I tried to change Items and m_Items to say, Item1 and m_Items1 but ran into errors. Can you point how to fix that?

Also, is there a reason as to why RunUO on Mono refuses to compile on Warnings? It's awfully annoying for my test server to run perfectly on windows, but refuse to compile on Linux. If there is a reason, is there a way to 'force' it to compile with warnings?
 

Soteric

Knight
You should post the error. As for "refuses to compile on Warnings" I suppose there is a key that suppress the warnings but I'm not familiar with Mono.
 

Fastburn

Sorceror
Here is the error when I attempt to change m_items and Items to m_items1 and Items1. Can you help me fix this? I'm at a loss of how to do it without creating issues.

Code:
Errors:
+ Custom/Commands/Staff/Control.cs:
    CS1502: Line 185: The best overloaded method match for 'Server.Mobiles.Contr
olCommand.ChangeControl(Server.Mobile, Server.Items.ControlItem, bool, bool, boo
l)' has some invalid arguments
    CS1503: Line 185: Argument '5': cannot convert from 'System.Collections.Gene
ric.List<Server.Item>' to 'bool'
    CS0200: Line 249: Property or indexer 'Server.Item.Items' cannot be assigned
to -- it is read only
    CS0029: Line 249: Cannot implicitly convert type 'bool' to 'System.Collectio
ns.Generic.List<Server.Item>'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

Control.cs (w/ changes I assumed would work)
Code:
/*********************************************
Version: 1.0.1

Changes:
1.0.1:
    - Added "private static object Construct(...)" to "class ControlCommand"
    - Following command arguments added: NoStats, NoSkills, NoItems

-- Please do not edit this Header --

Scripted by Quick_silver
for www.Welt-von-Midgrd.ch
and everyone who want to use it.

Please note me if you make Changes in the Scripts.

|*****Instalation*****>
Notice strings in engish are commented in the code, so you can replace the germans.

To uncontrol at death add the following lines to the PlayerMobbile.cs or edit the OnBeforeDeath() function.

    public override bool OnBeforeDeath()
    {
        return ControlCommand.UncontrolDeath( (Mobile)this );
    }

And now: Have fun...

*********************************************/

using System;
using System.Collections;
using System.Reflection;
using Server.Mobiles;
using Server.Targeting;
using Server.Items;
using Server.Commands;
 
namespace Server.Mobiles
{
    public class ControlCommand
    {
        public static AccessLevel accessLevel = AccessLevel.GameMaster;

        private static Layer[] m_DesiredLayerOrder = new Layer[]
        {
            Layer.Cloak,
            Layer.Bracelet,
            Layer.Ring,
            Layer.Shirt,
            Layer.Pants,
            Layer.InnerLegs,
            Layer.Shoes,
            Layer.Arms,
            Layer.InnerTorso,
            Layer.MiddleTorso,
            Layer.OuterLegs,
            Layer.Neck,
            Layer.Waist,
            Layer.Gloves,
            Layer.OuterTorso,
            Layer.OneHanded,
            Layer.TwoHanded,
            Layer.FacialHair,
            Layer.Hair,
            Layer.Helm
        };

        public static void Initialize()
        {
            CommandSystem.Register( "Control", accessLevel, new CommandEventHandler( Control_OnCommand ) );
        }

        [Usage( "Control [target]" )]
        [Description( "Lets you control a NPC" )]
        //"Let you control a NPC."
        private static void Control_OnCommand( CommandEventArgs e )
        {
            Mobile from = e.Mobile;

            e.GetInt32( 0 );

            if ( from != null )
            {
                from.SendMessage( "Choose the target to control?" );
                //"Choose the target to control..."

                from.Target = new InternalTarget( e.Arguments );
            }
        }

        private class InternalTarget : Target
        {
            string[] m_parameter;

            public InternalTarget( params string[] parameter ) : base( -1, true, TargetFlags.None )
            {
                m_parameter = parameter;
            }

            protected override void OnTarget( Mobile from, object targeted )
            {
                bool stats = true;
                bool skills = true;
                bool items = true;

                for (int i=0; i<m_parameter.Length; i++)
                    if (string.Compare(m_parameter[i], "NoStats", true) == 0)
                        stats = false;

                for (int i=0; i<m_parameter.Length; i++)
                    if (string.Compare(m_parameter[i], "NoSkills", true) == 0)
                        skills = false;

                for (int i=0; i<m_parameter.Length; i++)
                    if (string.Compare(m_parameter[i], "NoItems", true) == 0)
                        items = false;
 
                DoControl( from, targeted, stats, skills, items );
            }
        }

        public static ControlItem GetControlItem( Mobile from )
        {
            Item result = SearchItemInCont( typeof(ControlItem), from.Backpack);

            if ( result != null && result is ControlItem )
                return (ControlItem)result;
            else
                return null;
        }

        private static Item SearchItemInCont( Type targetType, Container cont )
        {
            Item item;

            if( cont != null && !cont.Deleted )
            {
                for (int i = 0; i < cont.Items.Count;i++)
                {
                    item = (Item)cont.Items[i];
                    // recursively search containers
                    if( item != null && !item.Deleted)
                    {
                        if ( item.GetType() == targetType )
                            return item;
                        else if ( item is Container )
                            item = SearchItemInCont(targetType, (Container)item);

                        if ( item != null && item.GetType() == targetType )
                            return item;
                    }
                }
            }

            return null;
        }

        public static void DoControl( Mobile from, object targeted, bool stats, bool skills, bool items )
        {
            Mobile target;

            if ( from is PlayerMobile && targeted is Mobile)
            {
                if ( targeted is PlayerMobile && ((PlayerMobile)targeted).Player )
                {
                    from.SendMessage("You Cant control players");
                    //"You cant control players"
                    return;
                }

                target = (Mobile)targeted;
                ControlItem controlItem = GetControlItem(from);

                if ( controlItem == null )
                {
                    from.SendMessage("Stats: {0} Skills: {1} Items: {2}", stats, skills, items);
                    StartControl(from, target, stats, skills, items);
                }
                else
                {
                    from.SendMessage("Stats: {0} Skills: {1} Items: {2}", controlItem.Stats, controlItem.Skills, controlItem.Items);
                    ChangeControl(target, controlItem, controlItem.Stats, controlItem.Skills, controlItem.Items);
                }
            }
            else if ( from is PlayerMobile && targeted is ControlItem )
                ((Item)targeted).Delete();
        }
 
        private static void StartControl( Mobile from, Mobile target, bool stats, bool skills, bool items )
        {
            from.SendMessage("You leave your Body an control {0}, {1}", target.Name, target.Title);
            //"You leave your Body an control {0}, {1}"

            //Clone Player
            PlayerMobile playerClone = (PlayerMobile)DupeMobile(from);

            //Create ControlItem
            ControlItem controlItem = new ControlItem(from, playerClone, target, stats, skills, items);
            from.Backpack.DropItem(controlItem);

            //Backup Equip
            MoveEquip(from, playerClone, items);
            //Equip from target to player
            MoveEquip(target, from, items);
            CopyProps(target, from, stats, skills);

            target.Internalize();
            playerClone.Internalize();

        }

        private static void ChangeControl( Mobile target, ControlItem controlItem, bool stats, bool skills, bool items )
        {

            Mobile from                            = controlItem.Owner;
            PlayerMobile oldPlayer    = controlItem.Player;
            Mobile oldNPC                      = controlItem.NPC;

            if ( oldNPC != null )
            {
                //NPC Wiederherstellen
                if ( !oldNPC.Deleted )
                {
                    //Props immer übernehmen bei der Rückverwandlung?
                    CopyProps( from, oldNPC, stats, skills );
                    MoveEquip(from, oldNPC, items);
                }
                else
                {
                    from.SendMessage("Der originale NPC wurde gelöscht und wird nicht wiederhergestellt. Grund könnte ein manueller Respawn gewesen sein");
                    oldNPC.Delete();
                }
            }

            //Neuen Mobile übernehmen oder Control abbrechen
            if ( target != oldPlayer && target != null && !target.Deleted ) //Neues Mobile übernehmen
            {
                from.SendMessage("You Control {0}, {1}", target.Name, target.Title);
                //"You Control  {0}, {1}"

                //Update ControlItem
                controlItem.NPC = target;
                controlItem.Stats = stats;
                controlItem.Skills = skills;
                controlItem.Items = items;

                CopyProps( target, from, stats, skills );
                MoveEquip(target, from, items);

                target.Internalize();
            }
            else if ( target == oldPlayer && !target.Deleted )
            {
                controlItem.Delete();
            }
        }

        public static void EndControl( ControlItem controlItem, bool stats, bool skills, bool items )
        {
            Mobile from                            = controlItem.Owner;
            PlayerMobile oldPlayer    = controlItem.Player;
            Mobile oldNPC                      = controlItem.NPC;

            if ( from == null )
                return;

            from.SendMessage("You are in your original Body");
            //"You are in your original Body"

            //NPC wiederherstellen
            if ( oldNPC != null && !oldNPC.Deleted )
            {
                //Props immer übernehmen bei der Rückverwandlung?
                CopyProps( from, oldNPC, stats, skills );
                MoveEquip( from, oldNPC, items );
            }
            else
            {
                from.SendMessage("The original NPC was deleted. Maybe because a manual respawn");
                //"The original NPC was deleted. Maybe because a manual respawn"
                oldNPC.Delete();
            }

            if ( oldPlayer != null && !oldPlayer.Deleted )
            {
                //Spieler Wiederherstellen (100%)
                CopyProps( oldPlayer, from, true, true );
                MoveEquip( oldPlayer, from, true );

                oldPlayer.Delete();
            }
        }

        public static bool UncontrolDeath( Mobile from )
        {
            if ( from.AccessLevel < accessLevel )
                return true;

            ControlItem controlItem = GetControlItem(from);

            if ( controlItem != null )
            {
                controlItem.Delete();
                from.Hits = from.HitsMax;
                return false;
            }

            return true;
        }

        private static void MoveEquip( Mobile from, Mobile to, bool items)
        {
            Item item;

            for ( int i = 0; i < m_DesiredLayerOrder.Length; ++i )
            {
                item = to.FindItemOnLayer( m_DesiredLayerOrder[i] );
                if ( item != null )
                    item.Bounce(to);

                item = from.FindItemOnLayer( m_DesiredLayerOrder[i] );
                if( item != null )
                {
                    to.EquipItem(item);
                }
            }

            //Backpack
            if ( from.Backpack != null && !(from.Backpack is VendorBackpack) && items )
            {

                if ( to.Backpack == null )
                    to.EquipItem( new Backpack() );

                ArrayList itemsToMove = new ArrayList();

                for (int i = 0; i < from.Backpack.Items.Count;++i)
                {
                    item = (Item)from.Backpack.Items[i];

                    if( item != null && !item.Deleted && item.LootType != LootType.Newbied && item.LootType != LootType.Blessed )
                    {
                        itemsToMove.Add( item );
                    }
                }

                for ( int i = 0; i < itemsToMove.Count; ++i)
                {
                    to.Backpack.DropItem((Item)itemsToMove[i]);
                }
                itemsToMove.Clear();

            }
        }

        //With items for DupeCommand?
        public static Mobile DupeMobile( object mobile )
        {
            Type t = mobile.GetType();
            object o = Construct(t);

            if (o == null)
            {
                Console.WriteLine("Unable to dupe {0}. Mobile must have a 0 parameter constructor.",t.Name);
                return null;
            }

            if (o is Mobile)
            {
                Mobile newMobile = (Mobile)o;
                Mobile srcMobile = (Mobile)mobile;
                CopyProperties( o, mobile, t, "Parent", "NetState" );

                newMobile.Player = false;
                newMobile.UpdateTotals();
                return newMobile;
            }

            return null;
        }

        private static void CopyProps(Mobile from, Mobile target, bool stats, bool skills)
        {
            try
            {
                if ( from.Map == Map.Internal )
                    from.MoveToWorld(target.Location, target.Map);

                if ( stats )
                    CopyMobileProps( target, from, "Parent", "NetState", "Player", "AccessLevel" );
                else
                    CopyMobileProps( target, from, "Parent", "NetState", "Player", "AccessLevel", "RawStr", "Str", "RawDex", "Dex", "RawInt", "Int", "Hits", "Mana", "Stam" );

                if ( skills )
                    for ( int i = 0; i < target.Skills.Length; ++i )
                    {
                        target.Skills[i].Base = from.Skills[i].Base;
                    }
            }
            catch
            {
                Console.WriteLine("Error in Control.cs -> CopyProps(Mobile from, Mobile target, bool stats, bool skills)");
                return;
            }
        }

        private static void CopyMobileProps( Mobile dest, Mobile src, params string[] omitProps )
        {
            Type type = src.GetType();

            PropertyInfo[] props = type.GetProperties();

            for ( int i = 0; i < props.Length; i++ )
            {
                try
                {
                    bool omit = false;
                    for (int j=0; j<omitProps.Length; j++)
                        if (string.Compare(omitProps[j], props[i].Name, true) == 0)
                        {
                            omit = true;
                            break;
                        }

                    if ( props[i].CanRead && props[i].CanWrite && !omit)
                    {
                        props[i].SetValue( dest, props[i].GetValue( src, null ), null );
                    }
                }
                catch
                {
                    //Console.WriteLine( "Denied" );
                }
            }
        }

        private static bool CompareType(object o, Type type)
        {
            if (o.GetType() == type || o.GetType().IsSubclassOf(type))
                return true;
            else
                return false;
        }

        private static void CopyProperties ( object dest, object src, Type type , params string[] omitProps )
        {
            if (!CompareType(dest,type) || !CompareType(src,type) || (dest.GetType() != src.GetType()) )
                return;

            PropertyInfo[] props = type.GetProperties();

            for ( int i = 0; i < props.Length; i++ )
            {
                try
                {
                    bool omit = false;
                    for (int j=0; j<omitProps.Length; j++)
                        if (string.Compare(omitProps[j], props[i].Name, true) == 0)
                        {
                            omit = true;
                            break;
                        }

                    if ( props[i].CanRead && props[i].CanWrite && !omit)
                    {
                        //Console.WriteLine( "Setting {0} = {1}", props[i].Name, props[i].GetValue( src, null ) );
                        props[i].SetValue( dest, props[i].GetValue( src, null ), null );
                    }
                }
                catch
                {
                    //Console.WriteLine( "Denied" );
                }
            }
        }

        private static object Construct( Type type, params object[] constructParams)
        {
            bool constructed=false;
            object toReturn=null;
            ConstructorInfo[] info = type.GetConstructors();

            foreach ( ConstructorInfo c in info )
            {
                if (constructed) break;
                ParameterInfo[] paramInfo = c.GetParameters();

                if ( paramInfo.Length == constructParams.Length )
                {
                    try
                    {
                        object o = c.Invoke( constructParams );

                        if ( o != null )
                        {
                            constructed = true;
                            toReturn = o;
                        }
                    }
                    catch
                    {
                        toReturn = null;
                    }
                }
            }
            return toReturn;
        }
 
    }

}
 
namespace Server.Items
{
    public class ControlItem : Item
    {
        private Mobile m_Owner;
        private Mobile m_Player;
        private Mobile m_NPC;

        private bool m_Stats;
        private bool m_Skills;
        private bool m_Items1;

        [CommandProperty( AccessLevel.GameMaster )]
        public PlayerMobile Owner
        {
            get
            {
                if ( m_Player is PlayerMobile )
                    return (PlayerMobile)m_Owner;
                else return null;
            }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public PlayerMobile Player
        {
            get
            {
                if ( m_Player is PlayerMobile )
                    return (PlayerMobile)m_Player;
                else return null;
            }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public Mobile NPC
        {
            get{ return m_NPC; }
            set{ m_NPC = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool Stats
        {
            get{ return m_Stats; }
            set{ m_Stats = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool Skills
        {
            get{ return m_Skills; }
            set{ m_Skills = value; }
        }

        [CommandProperty( AccessLevel.GameMaster )]
        public bool Items1
        {
            get{ return m_Items1; }
            set{ m_Items1 = value; }
        }
 
        public ControlItem( Mobile owner, Mobile player, Mobile npc, bool stats, bool skills, bool items ) : base( 0x2106 )
        {
            m_Owner = owner;
            m_Player = player;
            m_NPC = npc;

            m_Stats = stats;
            m_Skills = skills;
            m_Items1 = items;

            Name = "Control Item";
            LootType = LootType.Blessed;
        }

        public ControlItem( Mobile owner, Mobile player, Mobile npc ) : base( 0x2106 )
        {
            m_Owner = owner;
            m_Player = player;
            m_NPC = npc;

            m_Stats = true;
            m_Skills = true;
            m_Items1 = true;

            Name = "Control Item";
            LootType = LootType.Blessed;
        }
 
        public ControlItem( Serial serial ) : base( serial )
        {
        }
 
        public override void OnDoubleClick( Mobile from )
        {
            if ( from == m_Owner )
                Delete();

            base.OnDoubleClick( from );
        }

        public override void OnAdded( object parent )
        {
            base.OnAdded( parent );

            if ( RootParent != m_Owner )
                Delete();
        }

        public override bool DropToWorld( Mobile from, Point3D p )
        {
            Delete();
 
            return false;
            //return base.DropToWorld( from, p );
        }
 
        public override void OnDelete()
        {
            ControlCommand.EndControl( this, m_Stats, m_Skills, m_Items1 );

            base.OnDelete();
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.Write( (int) 1 ); // version

            //Version 1
            writer.Write( (bool)m_Stats );
            writer.Write( (bool)m_Skills );
            writer.Write( (bool)m_Items1 );

            //Version 0
            writer.Write( (Mobile)m_Owner );
            writer.Write( (Mobile)m_Player );
            writer.Write( (Mobile)m_NPC );

        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();

            switch ( version )
            {
                case 1:
                {
                    m_Stats = reader.ReadBool();
                    m_Skills = reader.ReadBool();
                    m_Items1 = reader.ReadBool();
                    goto case 0;
                }
                case 0:
                {
                    m_Owner = reader.ReadMobile();
                    m_Player = reader.ReadMobile();
                    m_NPC = reader.ReadMobile();
                    break;
                }
            }

        }
   
    }
 

Soteric

Knight
Because here
Code:
ChangeControl(target, controlItem, controlItem.Stats, controlItem.Skills, controlItem.Items);
you are still using Items which is type of List, not bool. By the way in C# for bool types you could use prefix has or is (like HasItems or IsItem). It makes things more clear.
 

Fastburn

Sorceror
I'm still very new to C#, and I'm still having trouble fixing these. I hate to ask but could you make the fixes for me? I'd vary much appreciate it. I'm sorry for having to ask it, but I'm at my wits end.
 

Soteric

Knight
Change this
Code:
ChangeControl(target, controlItem, controlItem.Stats, controlItem.Skills, controlItem.Items);
to this
Code:
ChangeControl(target, controlItem, controlItem.Stats, controlItem.Skills, controlItem.Items1);
 
Top