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!

Script to change color of container with Magic Trap on it and release from Paralyzation

Justin Davis

Wanderer
I've been busy writing and improving on different scripts for my shard and I thought I would share this one because I think it's kinda cool.

It will change the color of your container to blue when it has the Magic Trap spell on it, its always hard to tell if a container is trapped or not, and it will release you if you are paralyzed by someone with only 1 hit point of damage instead of taking a lot of damage when the trap goes off.

I'm gonna look at it more in depth later when I have time and see if I can get the damage to 0 when the trap goes off, problem with setting it to 0 is you are still paralyzed when trap goes off doesn't free you, so has to be 1 point of damage.

Gotta set an int var in Paralyze.cs and hook to it through TrapableContainer.cs or maybe the duration var, but that var is local to that function so will have to make another var and maybe also deal with mobile m parameter, Maybe set a Global variable but I dont think you have those in C# where I can hook to it from TrapableContainer.cs and refer to it from Paralyze class and drill down to get and set that variable. Ill have to look at it and see if I can set it to 0 damage instead of 1 but I'm sure your toons aren't wimps and can handle 1 hp of damage right?;)
I included the Paralyze.cs in case anyone wants has the time to make it 0 damage instead of 1. But I'm moving on to another script now. Hope you enjoy.

You can put it in your RunUO\Scripts\Items\Containers\TrapableContainer.cs
 

Attachments

  • Paralyze.cs
    2.5 KB · Views: 3
  • TrapableContainer.cs
    6.8 KB · Views: 3

pooka01

Sorceror
Maybe in playermobile.cs or even in core mobile.cs... If you want it easy-but-messy:
make it so OnDoubleClick, if trapped (probably a boolean), from.Paralyzed = false;
Not sure how it could react to the stuns and other paralyze stuffs, but this should work pretty well.
As for the code location, maybe just place that in trapable container, if (this is Pouch) -> etc.

Don't hesitate to post your codes if you get time to or if you can't get it to work.
 

Dian

Sorceror
Yeah, it does sound like you are way over thinking things on the para trigger from the magic trap. It could be done with a couple lines of code in the pouch script Im sure. But really, whats the big deal over the 1 hit point anyways.. it keeps thing in order, and wont conflict with anything else later, had you coded it like you were thinking. ;)

Good stuff though, thanks for sharing :)
 

pooka01

Sorceror
Initially magic trap is to trap stuffs, so technically it should be harmful.
If you ever make premade trapped pouch to drop in a backpack, be really careful, as if you open 3 pouches it kills you. (remember to test it right ;D)
 

boba

Sorceror
Code:
public class Pouch : TrapableContainer
    {
        public override bool HueOnMagicTrap{ get{ return true; } }
 
        [Constructable]
        public Pouch() : base( 0xE79 )
        {
            Weight = 1.0;
        }
 
        public Pouch( 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();
        }
    }
really no need to change the paralyze code
I hope this helps you

it will change to hue 38 aka gm red once you trap it with magic trap
and back to normal once you un trap it

Code:
using System;
using Server.Network;
using Server.Misc;
 
namespace Server.Items
{
    public enum TrapType
    {
        None,
        MagicTrap,
        ExplosionTrap,
        DartTrap,
        PoisonTrap
    }
 
    public abstract class TrapableContainer : BaseContainer, ITelekinesisable
    {
        private TrapType m_TrapType;
        private int m_TrapPower;
        private int m_TrapLevel;
        private Mobile m_TrapCreator;
 
        public virtual bool HueOnMagicTrap { get { return false; } }
 
        [Hue, CommandProperty( AccessLevel.GameMaster )]
        public override int Hue
        {
            get{ return ( HueOnMagicTrap && m_TrapPower > 0 && m_TrapType == TrapType.MagicTrap ) ? 38 : base.Hue; }
            set{ base.Hue = value; }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public TrapType TrapType
        {
            get
            {
                return m_TrapType;
            }
            set
            {
                m_TrapType = value;
                ReleaseWorldPackets();
                Delta( ItemDelta.Update );
            }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public int TrapPower
        {
            get
            {
                return m_TrapPower;
            }
            set
            {
                m_TrapPower = value;
                Delta( ItemDelta.Update );
            }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public int TrapLevel
        {
            get
            {
                return m_TrapLevel;
            }
            set
            {
                m_TrapLevel = value;
            }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public Mobile TrapCreator
        {
            get
            {
                return m_TrapCreator;
            }
            set
            {
                m_TrapCreator = value;
            }
        }
 
        public virtual bool TrapOnOpen{ get{ return true; } }
 
        public TrapableContainer( int itemID ) : base( itemID )
        {
        }
 
        public TrapableContainer( Serial serial ) : base( serial )
        {
        }
 
        private void SendMessageTo( Mobile to, int number, int hue )
        {
            if ( Deleted || !to.CanSee( this ) )
                return;
 
            to.Send( new MessageLocalized( Serial, ItemID, MessageType.Regular, hue, 3, number, "", "" ) );
        }
 
        private void SendMessageTo( Mobile to, string text, int hue )
        {
            if ( Deleted || !to.CanSee( this ) )
                return;
 
            to.Send( new UnicodeMessage( Serial, ItemID, MessageType.Regular, hue, 3, to.Language, "", text ) );
        }
 
        public virtual bool ExecuteTrap( Mobile from )
        {
            if ( m_TrapType != TrapType.None )
            {
                Point3D loc = this.GetWorldLocation();
                Map facet = this.Map;
 
                if ( from.AccessLevel >= AccessLevel.GameMaster )
                {
                    SendMessageTo( from, "That is trapped, but you open it with your godly powers.", 0x3B2 );
                    return false;
                }
 
                switch ( m_TrapType )
                {
                    case TrapType.ExplosionTrap:
                    {
                        SendMessageTo( from, 502999, 0x3B2 ); // You set off a trap!
 
                        if ( from.InRange( loc, 3 ) )
                        {
                            int damage;
 
                            if ( m_TrapLevel > 0 )
                                damage = Utility.RandomMinMax( 8, 20 ) * m_TrapLevel;
                            else
                                damage = m_TrapPower;
 
                            from.Damage(damage);
 
                            // Your skin blisters from the heat!
                            from.LocalOverheadMessage( Network.MessageType.Regular, 0x2A, 503000 );
                        }
 
                        Effects.SendLocationEffect( loc, facet, 0x36BD, 15, 10 );
                        Effects.PlaySound( loc, facet, 0x307 );
 
                        break;
                    }
                    case TrapType.MagicTrap:
                    {
                        if ( from.InRange( loc, 1 ) )
                            from.Damage( m_TrapPower );
                            //AOS.Damage( from, m_TrapPower, 0, 100, 0, 0, 0 );
 
                        Effects.PlaySound( loc, Map, 0x307 );
 
                        Effects.SendLocationEffect( new Point3D( loc.X - 1, loc.Y, loc.Z ), Map, 0x36BD, 15 );
                        Effects.SendLocationEffect( new Point3D( loc.X + 1, loc.Y, loc.Z ), Map, 0x36BD, 15 );
 
                        Effects.SendLocationEffect( new Point3D( loc.X, loc.Y - 1, loc.Z ), Map, 0x36BD, 15 );
                        Effects.SendLocationEffect( new Point3D( loc.X, loc.Y + 1, loc.Z ), Map, 0x36BD, 15 );
 
                        Effects.SendLocationEffect( new Point3D( loc.X + 1, loc.Y + 1, loc.Z + 11 ), Map, 0x36BD, 15 );
 
                        //Update item for hue purposes.
                        ReleaseWorldPackets();
                        Delta( ItemDelta.Update );
 
                        break;
                    }
                    case TrapType.DartTrap:
                    {
                        SendMessageTo( from, 502999, 0x3B2 ); // You set off a trap!
 
                        if ( from.InRange( loc, 3 ) )
                        {
                            int damage;
 
                            if ( m_TrapLevel > 0 )
                                damage = Utility.RandomMinMax( 5, 15 ) * m_TrapLevel;
                            else
                                damage = m_TrapPower;
 
                            from.Damage(damage);
 
                            // A dart imbeds itself in your flesh!
                            from.LocalOverheadMessage( Network.MessageType.Regular, 0x62, 502998 );
                        }
 
                        Effects.PlaySound( loc, facet, 0x223 );
 
                        break;
                    }
                    case TrapType.PoisonTrap:
                    {
                        SendMessageTo( from, 502999, 0x3B2 ); // You set off a trap!
 
                        if ( from.InRange( loc, 3 ) )
                        {
                            Poison poison;
 
                            if ( m_TrapLevel > 0 )
                            {
                                poison = Poison.GetPoison( Math.Max( 0, Math.Min( 4, m_TrapLevel - 1 ) ) );
                            }
                            else
                                poison = null;
 
                            if ( m_TrapPower > 0 )
                            {
                                from.Damage(m_TrapPower);
                                if ( m_TrapLevel == 0 )
                                    poison = Poison.Greater;
                            }
 
                            from.ApplyPoison( from, poison );
 
                            // You are enveloped in a noxious green cloud!
                            from.LocalOverheadMessage( Network.MessageType.Regular, 0x44, 503004 );
                        }
 
                        Effects.SendLocationEffect( loc, facet, 0x113A, 10, 20 );
                        Effects.PlaySound( loc, facet, 0x231 );
 
                        break;
                    }
                }
 
                m_TrapType = TrapType.None;
                m_TrapPower = 0;
                m_TrapLevel = 0;
                return true;
            }
 
            return false;
        }
 
        public virtual void OnTelekinesis( Mobile from )
        {
            Effects.SendLocationParticles( EffectItem.Create( Location, Map, EffectItem.DefaultDuration ), 0x376A, 9, 32, 5022 );
            Effects.PlaySound( Location, Map, 0x1F5 );
 
            if( this.TrapOnOpen )
            {
                ExecuteTrap( from );
            }
        }
 
        public override void Open( Mobile from )
        {
            if ( !this.TrapOnOpen || !ExecuteTrap( from ) )
                base.Open( from );
        }
 
        public override void OnSingleClick( Mobile from )
        {
            base.OnSingleClick( from );
            if ( ( RootParent == from && ( from == m_TrapCreator || from.AccessLevel >= AccessLevel.GameMaster ) ) && m_TrapType == TrapType.MagicTrap && ( m_TrapPower > 0 || m_TrapLevel > 0 ) )
                LabelTo( from, "(trapped)", 38 );
        }
 
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
 
            writer.Write( (int) 3 ); // version
 
            writer.Write( m_TrapCreator );
 
            writer.Write( (int) m_TrapLevel );
 
            writer.Write( (int) m_TrapPower );
            writer.Write( (int) m_TrapType );
        }
 
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
 
            int version = reader.ReadInt();
 
            switch ( version )
            {
                case 3:
                {
                    m_TrapCreator = reader.ReadMobile();
                    goto case 2;
                }
                case 2:
                {
                    m_TrapLevel = reader.ReadInt();
                    goto case 1;
                }
                case 1:
                {
                    m_TrapPower = reader.ReadInt();
                    goto case 0;
                }
                case 0:
                {
                    m_TrapType = (TrapType)reader.ReadInt();
                    break;
                }
            }
        }
    }
}
 

Acetamer

Wanderer
Code:
public class Pouch : TrapableContainer
    {
        public override bool HueOnMagicTrap{ get{ return true; } }
 
        [Constructable]
        public Pouch() : base( 0xE79 )
        {
            Weight = 1.0;
        }
 
        public Pouch( 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();
        }
    }
really no need to change the paralyze code
I hope this helps you

it will change to hue 38 aka gm red once you trap it with magic trap
and back to normal once you un trap it

Code:
using System;
using Server.Network;
using Server.Misc;
 
namespace Server.Items
{
    public enum TrapType
    {
        None,
        MagicTrap,
        ExplosionTrap,
        DartTrap,
        PoisonTrap
    }
 
    public abstract class TrapableContainer : BaseContainer, ITelekinesisable
    {
        private TrapType m_TrapType;
        private int m_TrapPower;
        private int m_TrapLevel;
        private Mobile m_TrapCreator;
 
        public virtual bool HueOnMagicTrap { get { return false; } }
 
        [Hue, CommandProperty( AccessLevel.GameMaster )]
        public override int Hue
        {
            get{ return ( HueOnMagicTrap && m_TrapPower > 0 && m_TrapType == TrapType.MagicTrap ) ? 38 : base.Hue; }
            set{ base.Hue = value; }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public TrapType TrapType
        {
            get
            {
                return m_TrapType;
            }
            set
            {
                m_TrapType = value;
                ReleaseWorldPackets();
                Delta( ItemDelta.Update );
            }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public int TrapPower
        {
            get
            {
                return m_TrapPower;
            }
            set
            {
                m_TrapPower = value;
                Delta( ItemDelta.Update );
            }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public int TrapLevel
        {
            get
            {
                return m_TrapLevel;
            }
            set
            {
                m_TrapLevel = value;
            }
        }
 
        [CommandProperty( AccessLevel.GameMaster )]
        public Mobile TrapCreator
        {
            get
            {
                return m_TrapCreator;
            }
            set
            {
                m_TrapCreator = value;
            }
        }
 
        public virtual bool TrapOnOpen{ get{ return true; } }
 
        public TrapableContainer( int itemID ) : base( itemID )
        {
        }
 
        public TrapableContainer( Serial serial ) : base( serial )
        {
        }
 
        private void SendMessageTo( Mobile to, int number, int hue )
        {
            if ( Deleted || !to.CanSee( this ) )
                return;
 
            to.Send( new MessageLocalized( Serial, ItemID, MessageType.Regular, hue, 3, number, "", "" ) );
        }
 
        private void SendMessageTo( Mobile to, string text, int hue )
        {
            if ( Deleted || !to.CanSee( this ) )
                return;
 
            to.Send( new UnicodeMessage( Serial, ItemID, MessageType.Regular, hue, 3, to.Language, "", text ) );
        }
 
        public virtual bool ExecuteTrap( Mobile from )
        {
            if ( m_TrapType != TrapType.None )
            {
                Point3D loc = this.GetWorldLocation();
                Map facet = this.Map;
 
                if ( from.AccessLevel >= AccessLevel.GameMaster )
                {
                    SendMessageTo( from, "That is trapped, but you open it with your godly powers.", 0x3B2 );
                    return false;
                }
 
                switch ( m_TrapType )
                {
                    case TrapType.ExplosionTrap:
                    {
                        SendMessageTo( from, 502999, 0x3B2 ); // You set off a trap!
 
                        if ( from.InRange( loc, 3 ) )
                        {
                            int damage;
 
                            if ( m_TrapLevel > 0 )
                                damage = Utility.RandomMinMax( 8, 20 ) * m_TrapLevel;
                            else
                                damage = m_TrapPower;
 
                            from.Damage(damage);
 
                            // Your skin blisters from the heat!
                            from.LocalOverheadMessage( Network.MessageType.Regular, 0x2A, 503000 );
                        }
 
                        Effects.SendLocationEffect( loc, facet, 0x36BD, 15, 10 );
                        Effects.PlaySound( loc, facet, 0x307 );
 
                        break;
                    }
                    case TrapType.MagicTrap:
                    {
                        if ( from.InRange( loc, 1 ) )
                            from.Damage( m_TrapPower );
                            //AOS.Damage( from, m_TrapPower, 0, 100, 0, 0, 0 );
 
                        Effects.PlaySound( loc, Map, 0x307 );
 
                        Effects.SendLocationEffect( new Point3D( loc.X - 1, loc.Y, loc.Z ), Map, 0x36BD, 15 );
                        Effects.SendLocationEffect( new Point3D( loc.X + 1, loc.Y, loc.Z ), Map, 0x36BD, 15 );
 
                        Effects.SendLocationEffect( new Point3D( loc.X, loc.Y - 1, loc.Z ), Map, 0x36BD, 15 );
                        Effects.SendLocationEffect( new Point3D( loc.X, loc.Y + 1, loc.Z ), Map, 0x36BD, 15 );
 
                        Effects.SendLocationEffect( new Point3D( loc.X + 1, loc.Y + 1, loc.Z + 11 ), Map, 0x36BD, 15 );
 
                        //Update item for hue purposes.
                        ReleaseWorldPackets();
                        Delta( ItemDelta.Update );
 
                        break;
                    }
                    case TrapType.DartTrap:
                    {
                        SendMessageTo( from, 502999, 0x3B2 ); // You set off a trap!
 
                        if ( from.InRange( loc, 3 ) )
                        {
                            int damage;
 
                            if ( m_TrapLevel > 0 )
                                damage = Utility.RandomMinMax( 5, 15 ) * m_TrapLevel;
                            else
                                damage = m_TrapPower;
 
                            from.Damage(damage);
 
                            // A dart imbeds itself in your flesh!
                            from.LocalOverheadMessage( Network.MessageType.Regular, 0x62, 502998 );
                        }
 
                        Effects.PlaySound( loc, facet, 0x223 );
 
                        break;
                    }
                    case TrapType.PoisonTrap:
                    {
                        SendMessageTo( from, 502999, 0x3B2 ); // You set off a trap!
 
                        if ( from.InRange( loc, 3 ) )
                        {
                            Poison poison;
 
                            if ( m_TrapLevel > 0 )
                            {
                                poison = Poison.GetPoison( Math.Max( 0, Math.Min( 4, m_TrapLevel - 1 ) ) );
                            }
                            else
                                poison = null;
 
                            if ( m_TrapPower > 0 )
                            {
                                from.Damage(m_TrapPower);
                                if ( m_TrapLevel == 0 )
                                    poison = Poison.Greater;
                            }
 
                            from.ApplyPoison( from, poison );
 
                            // You are enveloped in a noxious green cloud!
                            from.LocalOverheadMessage( Network.MessageType.Regular, 0x44, 503004 );
                        }
 
                        Effects.SendLocationEffect( loc, facet, 0x113A, 10, 20 );
                        Effects.PlaySound( loc, facet, 0x231 );
 
                        break;
                    }
                }
 
                m_TrapType = TrapType.None;
                m_TrapPower = 0;
                m_TrapLevel = 0;
                return true;
            }
 
            return false;
        }
 
        public virtual void OnTelekinesis( Mobile from )
        {
            Effects.SendLocationParticles( EffectItem.Create( Location, Map, EffectItem.DefaultDuration ), 0x376A, 9, 32, 5022 );
            Effects.PlaySound( Location, Map, 0x1F5 );
 
            if( this.TrapOnOpen )
            {
                ExecuteTrap( from );
            }
        }
 
        public override void Open( Mobile from )
        {
            if ( !this.TrapOnOpen || !ExecuteTrap( from ) )
                base.Open( from );
        }
 
        public override void OnSingleClick( Mobile from )
        {
            base.OnSingleClick( from );
            if ( ( RootParent == from && ( from == m_TrapCreator || from.AccessLevel >= AccessLevel.GameMaster ) ) && m_TrapType == TrapType.MagicTrap && ( m_TrapPower > 0 || m_TrapLevel > 0 ) )
                LabelTo( from, "(trapped)", 38 );
        }
 
        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
 
            writer.Write( (int) 3 ); // version
 
            writer.Write( m_TrapCreator );
 
            writer.Write( (int) m_TrapLevel );
 
            writer.Write( (int) m_TrapPower );
            writer.Write( (int) m_TrapType );
        }
 
        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
 
            int version = reader.ReadInt();
 
            switch ( version )
            {
                case 3:
                {
                    m_TrapCreator = reader.ReadMobile();
                    goto case 2;
                }
                case 2:
                {
                    m_TrapLevel = reader.ReadInt();
                    goto case 1;
                }
                case 1:
                {
                    m_TrapPower = reader.ReadInt();
                    goto case 0;
                }
                case 0:
                {
                    m_TrapType = (TrapType)reader.ReadInt();
                    break;
                }
            }
        }
    }
}


Hi, boba where are files? how I get files to work? I see two separates? copy and paste? where? I follow directions but none i see? sorry i'm very new
 

Acetamer

Wanderer
Hi, boba where are files? how I get files to work? I see two separates? copy and paste? where? I follow directions but none i see? sorry i'm very new


Anyone? help a new with this? where do i paste code? together same file? or two separates? I paste in same file, replace trappablecontainer file, both code blocks together same file. that code almost kill me with the trap! the damage not 0!... I use Justin fix original post unless someone explain implement Boba code. Not good just leave Boba code like this for a new...
 

boba

Sorceror
under containers.cs go to the line that says pouch as per the example above

this is the line you need to add


public override bool HueOnMagicTrap{ get{ return true; } }


then the next script could be a plug in play if you have a newer version of runuo

and that file is trapablecontainer.cs


I would use winmerge and verify the differences in your trapablecontainer.cs and mine and only change what is needed

I will post both my files below to help you
 

Attachments

  • TrapableContainer.cs
    7 KB · Views: 2
  • Container.cs
    25.1 KB · Views: 1

Acetamer

Wanderer
Bobo, you almost kill AceTamer again! :eek: yes pouch red, yes works, but the damage!? I thought 0 damage this time but I almost die set of two magic trap lol, your script does not deal with no damage Just color of pouch I think? I stick with Justin script only 1 damage and change color also, so I don't die running from many PK lol...
 

Acetamer

Wanderer
Oh I sees Boba ok, misunderstood, but if paralyze it is no good for me with 0, cant escape with 0 damage, so back again to the start of thread, I take the 1 point damage with other code not so bad. Thanks
 

boba

Sorceror
case TrapType.ExplosionTrap:
{
SendMessageTo( from, 502999, 0x3B2 ); // You set off a trap!

if ( from.InRange( loc, 3 ) )
{
int damage;

if ( m_TrapLevel > 0 )
damage = Utility.RandomMinMax( 1, 2) * m_TrapLevel; ///// here is the code to reduce the trap power :)
else
damage = m_TrapPower;

from.Damage(damage);
 

Acetamer

Wanderer
no the 0.1 no work, but both scripts same just one blue bag one red bag at 1 damage, or Boba random 1or 2 damage just color preference now hehe
 
Top