Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 11-09-2006, 03:15 PM   #1 (permalink)
Forum Newbie
 
Join Date: Sep 2006
Age: 19
Posts: 13
Default Foreach

Never done this, so I am not suprised of the errors, but I dont know how to fix them.
Quote:
Originally Posted by The Console
RunUO - [www.runuo.com] Version 2.0, Build 2357.32527
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...failed (1 errors, 0 warnings)
Errors:
+ Customs/OrbCharger.cs:
CS1579: Line 40: foreach statement cannot operate on variables of type 'Serv
er.Items.Container' because 'Server.Items.Container' does not contain a public d
efinition for 'GetEnumerator'
CS0118: Line 64: 'Server.Items.AirOrb' is a 'type' but is used like a 'varia
ble'
CS0118: Line 64: 'Server.Items.FireOrb' is a 'type' but is used like a 'vari
able'
CS0118: Line 64: 'Server.Items.EarthOrb' is a 'type' but is used like a 'var
iable'
CS0118: Line 64: 'Server.Items.WaterOrb' is a 'type' but is used like a 'var
iable'
CS0118: Line 64: 'Server.Items.DeathOrb' is a 'type' but is used like a 'var
iable'
CS0117: Line 68: 'object' does not contain a definition for 'IsUsed'
CS0103: Line 72: The name 'utility' does not exist in the current context
CS0117: Line 79: 'object' does not contain a definition for 'Delete'
CS0117: Line 84: 'object' does not contain a definition for 'IsUsed'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
And here is the script:
Code:
using System;
using Server;
using Server.Targeting;
using Server.Mobiles;

namespace Server.Items
{
    public class OrbCharger : Item
    {
        [Constructable]
        public OrbCharger()
        {
            Name = "A Spirit Orb Charger";
            //AddComponent( new AddonComponent( 0x2DD8 ), 0, 0, 0 );
        }

        public OrbCharger(Serial serial)
            : base(serial)
        {
        }

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

            writer.WriteEncodedInt(0); // version
        }

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

            int version = reader.ReadEncodedInt();
        }

        public override void OnDoubleClick(Mobile from)
        {
            PlayerMobile m = from as PlayerMobile;

            foreach (Item i in m.Backpack)
            {
                if (i is AirOrb || i is EarthOrb || i is FireOrb || i is WaterOrb || i is DeathOrb)
                {
                    from.SendMessage("Select a spiritual orb to recharge");
                    from.Target = new InternalTarget(this);
                }
                else
                    from.SendMessage("You have no use of this.");
            }
        }

        private class InternalTarget : Target
        {
            private OrbCharger m_Item;

            public InternalTarget(OrbCharger item)
                : base(1, false, TargetFlags.None)
            {
                m_Item = item;
            }

            protected override void OnTarget(Mobile from, object targeted)
            {
                if (targeted != (AirOrb || FireOrb || EarthOrb || WaterOrb || DeathOrb))
                    from.SendMessage("That isn't a Spiritual Orb");
                else
                {
                    if (targeted.IsUsed != true)
                        from.SendMessage("That Orb Is Already Charged!");
                    else
                    {
                        if (utility.Random == 0.33)
                        {
                            switch(2)
                            {
                                case 0:
                                    {
                                        from.SendMessage("You Failed to recharge the orb and it was destroyed!");
                                        targeted.Delete();
                                    }
                                case 1:
                                    {
                                        from.SendMessage("You succesfully charged the orb.");
                                        targeted.IsUsed = false;
                                    }
                            }
                        }
                    }
                }
            }
        }
    }
}
-Zeke- is offline   Reply With Quote
Old 11-09-2006, 03:45 PM   #2 (permalink)
Forum Expert
 
Kenko's Avatar
 
Join Date: Dec 2004
Location: Land of the Poor
Posts: 1,828
Send a message via MSN to Kenko
Default

Code:
            foreach (Item i in m.Backpack)
            {
                if (i is AirOrb || i is EarthOrb || i is FireOrb || i is WaterOrb || i is DeathOrb)
                {
                    from.SendMessage("Select a spiritual orb to recharge");
                    from.Target = new InternalTarget(this);
                }
                else
                    from.SendMessage("You have no use of this.");
            }
to
Code:
            foreach (Item i in m.Backpack.Items)
            {
                if (i is AirOrb || i is EarthOrb || i is FireOrb || i is WaterOrb || i is DeathOrb)
                {
                    from.SendMessage("Select a spiritual orb to recharge");
                    from.Target = new InternalTarget(this);
                }
                else
                    from.SendMessage("You have no use of this.");
            }
Kenko is offline   Reply With Quote
Old 11-09-2006, 05:36 PM   #3 (permalink)
Forum Newbie
 
Join Date: Sep 2006
Age: 19
Posts: 13
Default

Okay, that got ride of the first one but what about the others?

I fixed the delete error (yeay me) but still have no clue on the others.
Quote:
Originally Posted by The Console
Errors:
+ Customs/OrbCharger.cs:
CS0118: Line 68: 'Server.Items.AirOrb' is a 'type' but is used like a 'varia
ble'
CS0118: Line 68: 'Server.Items.FireOrb' is a 'type' but is used like a 'vari
able'
CS0118: Line 68: 'Server.Items.EarthOrb' is a 'type' but is used like a 'var
iable'
CS0118: Line 68: 'Server.Items.WaterOrb' is a 'type' but is used like a 'var
iable'
CS0118: Line 68: 'Server.Items.DeathOrb' is a 'type' but is used like a 'var
iable'
CS0117: Line 68: 'Server.Item' does not contain a definition for 'IsUsed'
CS0117: Line 78: 'Server.Item' does not contain a definition for 'IsUsed'
CS0117: Line 83: 'Server.Item' does not contain a definition for 'IsUsed'
Code:
Code:
using System;
using Server;
using Server.Targeting;
using Server.Mobiles;

namespace Server.Items
{
    public class OrbCharger : Item
    {
        [Constructable]
        public OrbCharger()
        {
            Name = "A Spirit Orb Charger";
            //AddComponent( new AddonComponent( 0x2DD8 ), 0, 0, 0 );
        }

        public OrbCharger(Serial serial)
            : base(serial)
        {
        }

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

            writer.WriteEncodedInt(0); // version
        }

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

            int version = reader.ReadEncodedInt();
        }

        public override void OnDoubleClick(Mobile from)
        {
            PlayerMobile m = from as PlayerMobile;

            foreach (Item i in m.Backpack.Items)
            {
                if (i is AirOrb || i is EarthOrb || i is FireOrb || i is WaterOrb || i is DeathOrb)
                {
                    from.SendMessage("Select a spiritual orb to recharge");
                    from.Target = new InternalTarget(this);
                }
                else
                    from.SendMessage("You have no use of this.");
            }
        }

        private class InternalTarget : Target
        {
            private OrbCharger m_Charger;

            public InternalTarget(OrbCharger charger)
                : base(1, false, TargetFlags.None)
            {
                m_Charger = charger;
            }

            protected override void OnTarget(Mobile from, object targeted)
            {
                if (targeted is Item)
                {
                    Item i = (Item)targeted;

                    if (i == (AirOrb || FireOrb || EarthOrb || WaterOrb || DeathOrb) && i.IsUsed == false)
                    {
                        if (0.33 > Utility.RandomDouble())
                        {
                            from.SendMessage("You Failed to recharge the orb and it was destroyed!");
                            i.Delete();
                        }
                        else
                        {
                            from.SendMessage("You succesfully charged the orb.");
                            i.IsUsed = false;
                        }
                    }
                    else
                    {
                        if (i.IsUsed == true)
                            from.SendMessage("The orb is already charged.");
                        else
                            from.SendMessage("That is not a Spiritual Orb!");
                    }
                }
            }
        }
    }
}
-Zeke- is offline   Reply With Quote
Old 11-09-2006, 06:04 PM   #4 (permalink)
Master of the Internet
 
Join Date: Oct 2005
Age: 45
Posts: 6,283
Default

I guess I was looking in the wrong place, since I found this:

Code:
if (targeted != (AirOrb || FireOrb || EarthOrb || WaterOrb || DeathOrb))
which should look more like this:

Code:
if ((i is AirOrb || i is FireOrb || i is EarthOrb || i is WaterOrb || i is DeathOrb) && i.IsUsed == false)
But... On second look, if I remember right, you have a base class something like BaseOrb. If so, just check

Code:
BaseOrb orb = null;
if(i is BaseOrb)
	orb = i as BaseOrb;
Then you can do your operations on the orb without worrying what specific type it is (I hope anyway).

Hope this makes some sense.
Malaperth is offline   Reply With Quote
Old 11-09-2006, 06:39 PM   #5 (permalink)
Forum Newbie
 
Join Date: Sep 2006
Age: 19
Posts: 13
Default

Thanks Malaperth

That worked.
-Zeke- is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5