Repeating trap issue

Discussion in 'Script Support' started by maybeshewill, Oct 11, 2017.

  1. maybeshewill

    maybeshewill Sorceror

    Joined:
    Nov 6, 2010
    Messages:
    401
    Likes Received:
    65
    Hello runuo, im glad forums are back also love their new look.

    Im trying to make the repeating trap dont attack if player is carrying certain item.

    Repeatingtrap.cs:

    Code:
    using System;
     using Server;
     using Server.Targeting;
     using System.Collections;
     using System.Collections.Generic;
     using Server.ContextMenus;
     using Server.Mobiles;
     using Server.Misc;
     using Server.Spells;
     using Server.Items;
     using Server.Gumps;
    
    namespace Server.Items
    {
        public class RepeatingTrap : BaseTrap
        {
    
            private int m_TrapRange;
            private int m_MinDamage;
            private int m_MaxDamage;
            private int m_SpellEffect;
            private double  m_RefireDelay;
            private bool m_NoDamageHidden;
            private int m_Sound;
            
            public override void OnDoubleClick( Mobile from )
            {
                if ( from.AccessLevel >= AccessLevel.GameMaster )
                    from.SendGump( new PropertiesGump( from, this ) );
            }
            
            [CommandProperty(AccessLevel.GameMaster)]
            public int TrapRange
            {
                get { return m_TrapRange; }
                set { m_TrapRange = value; }
            }
            
            [CommandProperty(AccessLevel.GameMaster)]
            public int MinDamage
            {
                get { return m_MinDamage; }
                set { m_MinDamage = value; }
            }
            
            [CommandProperty(AccessLevel.GameMaster)]
            public int MaxDamage
            {
                get { return m_MaxDamage; }
                set { m_MaxDamage = value; }
            }
            
            [CommandProperty(AccessLevel.GameMaster)]
            public int SpellEffect
            {
                get { return m_SpellEffect; }
                set { m_SpellEffect = value; }
            }
            
            [CommandProperty(AccessLevel.GameMaster)]
            public double RefireDelay
            {
                get { return m_RefireDelay; }
                set { m_RefireDelay = value; }
                
            }
            
            [CommandProperty( AccessLevel.GameMaster )]
            public bool NoDamageHidden
            {
                get{ return m_NoDamageHidden; }
                set { m_NoDamageHidden = value; }
    
            }
            
            [CommandProperty(AccessLevel.GameMaster)]
            public int Sound
            {
                get { return m_Sound; }
                set { m_Sound = value; }
            }
            
            private Timer m_Timer;
    
            [Constructable]
            public RepeatingTrap() : base( 0x0428 )
            {
     
                m_TrapRange = 9;
                Visible = false;
                m_MinDamage = 5;
                m_MaxDamage = 10;
                m_SpellEffect = 7166;
                m_RefireDelay = .25;
                m_Sound = 564;
                m_NoDamageHidden = false;
            }
    
            public virtual void StartTimer()
            {
                if ( m_Timer == null )
                    m_Timer = Timer.DelayCall( TimeSpan.FromSeconds( RefireDelay ), TimeSpan.FromSeconds( RefireDelay ), new TimerCallback( Refresh ) );
            }
    
            public virtual void StopTimer()
            {
                if ( m_Timer != null )
                    m_Timer.Stop();
    
                m_Timer = null;
            }
    
            public virtual void CheckTimer()
            {
                Map map = this.Map;
    
                if ( map != null && map.GetSector( GetWorldLocation() ).Active )
                    StartTimer();
                else
                    StopTimer();
            }
    
            public override void OnLocationChange( Point3D oldLocation )
            {
                base.OnLocationChange( oldLocation );
    
                CheckTimer();
            }
    
            public override void OnMapChange()
            {
                base.OnMapChange();
    
                CheckTimer();
            }
    
            public override void OnSectorActivate()
            {
                base.OnSectorActivate();
    
                StartTimer();
            }
    
            public override void OnSectorDeactivate()
            {
                base.OnSectorDeactivate();
    
                StopTimer();
            }
    
                    
            public virtual void Refresh()
            {
                
                bool foundPlayer = false;
                
                ArrayList list = new ArrayList();
    
                foreach ( Mobile mob in GetMobilesInRange( TrapRange ) )
                {
                    if ( !mob.Alive || mob.AccessLevel > AccessLevel.Player || (mob.Hidden && NoDamageHidden) )
                        continue;
                
                    
                    if ( ( (this.Z + 8) >= mob.Z && (mob.Z + 16) > this.Z ) )
                    {
                        if (mob is BaseCreature && (((BaseCreature)mob).Controlled || ((BaseCreature)mob).Summoned ))
                             list.Add(mob);
                    
                          
                
                    
                        
                
                         else if (mob.Player)
                             list.Add(mob);
                                            
                        foundPlayer = true;
                        
                        foreach (Mobile mm in list)
                        {
                        
                         Effects.SendMovingEffect( this, mm, SpellEffect, 5, 0, false, true );
                         Effects.PlaySound( Location, Map, Sound );
                         Spells.SpellHelper.Damage( TimeSpan.FromSeconds( 0.5 ), mm, mm, Utility.RandomMinMax( MinDamage, MaxDamage ), 100, 0, 0, 0, 0 );
                    
                        }
                    
                                        
                    
                }
            
                }
            
            }
            
            
            public override void OnMovement( Mobile m, Point3D oldLocation )
            {
                base.OnMovement( m, oldLocation );
    
                if ( m.Location == oldLocation || !m.Player || !m.Alive || m.AccessLevel > AccessLevel.Player || m.Hidden )
                    return;
                            
                        
    
    
    
                if ( CheckRange( m.Location, oldLocation, TrapRange ) )
                {
                    CheckTimer();
                    
                    Effects.SendMovingEffect( this, m, SpellEffect, 5, 0, false, true );
                    Spells.SpellHelper.Damage( TimeSpan.FromSeconds( 0.5 ), m, m, Utility.RandomMinMax( MinDamage, MaxDamage ), 100, 0, 0, 0, 0 );
                    Effects.PlaySound( Location, Map, Sound  );
                }
            }
    
            public RepeatingTrap( Serial serial ) : base( serial )
            {
            }
    
            public override void Serialize( GenericWriter writer )
            {
                base.Serialize( writer );
    
                writer.Write( (int) 0 ); // version
                
                writer.Write( m_TrapRange );
                writer.Write( m_MinDamage );
                writer.Write( m_MaxDamage );
                writer.Write( m_SpellEffect );
                writer.Write( m_RefireDelay );
                writer.Write( m_NoDamageHidden );
                writer.Write( m_Sound );
    
            }
    
            public override void Deserialize( GenericReader reader )
            {
                base.Deserialize( reader );
    
                int version = reader.ReadInt();
    
                switch ( version )
                {
                    
                    case 0:
                    {
                        m_TrapRange = reader.ReadInt();
                        m_MinDamage = reader.ReadInt();
                        m_MaxDamage = reader.ReadInt();
                        m_SpellEffect = reader.ReadInt();
                        m_RefireDelay = reader.ReadDouble();
                        m_NoDamageHidden = reader.ReadBool();
                        m_Sound = reader.ReadInt();
                        CheckTimer();
    
                        break;
                    }
                }
            }
        }
    }

    on Refresh method i added;

    Code:
    #region trap dont attack is player carry X item
                      
                                      if (mob.Player)
                          {
                          PlayerMobile mobile = (PlayerMobile)mob;
                            Container pack = mob.Backpack;
                           Item tnd = mob.Backpack.FindItemByType(typeof(trapnodamage));
                       if (mob.Player && mob != null && tnd != null)
                       {
        
                         foundPlayer = false; 
                     }
    }
                        
                    
                     #endregion


    On movement method i added this


    Code:
    #region traps dont attack is player carry X items
                 PlayerMobile mobile = (PlayerMobile)m;
                  Container pack = m.Backpack;
                  Item aam = m.Backpack.FindItemByType(typeof(Keyyew));
                     if (aam != null)                     
                     return; 
                   #endregion                  
    current issue:

    Player without carrying the item DOESNT get attacked by the trap, if he go offscreen and come back he gets attacked 1 time by the trap. (The trap should attack as soon as someone is near the trap and keep attacking him non stop)
     

    Attached Files:

  2. Grimoric

    Grimoric Sorceror

    Joined:
    Feb 8, 2006
    Messages:
    74
    Likes Received:
    25
    Your trap is now fond of smith hammers :)

    -Grim
     

    Attached Files:

    maybeshewill likes this.
  3. maybeshewill

    maybeshewill Sorceror

    Joined:
    Nov 6, 2010
    Messages:
    401
    Likes Received:
    65
    Thank you so much Grimoric, going to change the item asap, or blacksmiths are going to become gods ;p
     
  4. Hammerhand

    Hammerhand RunUO Moderator
    Staff Member

    Joined:
    Sep 11, 2004
    Messages:
    8,622
    Likes Received:
    508
    Blacksmiths ARE gods.. otherwise warriors would be fighting dragons with sticks & slingshots while wearing leather armor. Or running for their lives. ;)
     
    Grimoric and maybeshewill like this.

Share This Page