sahisahi

Member
Cant get this to work i wanted to add a check for a item in player backpack so trap dont shot that player, no sucess so far, traps are supposed to attack any player/ controlled creature near them

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)


Code:
    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);
                      #region trap dont attack is player carry X item
                     
                      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
                   
            
                     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;
#region traps dont attack is player carry X items
             PlayerMobile mobile = (PlayerMobile)m;
              Container pack = m.Backpack;
              Item aam = m.Backpack.FindItemByType(typeof(trapnodamage));
                 if (aam != null)                       
                 return;   
               #endregion                      
                    



            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  );
            }
        }

Refres method i added this:

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


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

Sorry for the mess and thanks as always.
 
Can you post the entire script? There must be a Timer I am missing or something, otherwise how does Refresh() get called?
 
Here is some pseudo code for you. I like to write in pseudo code to "think" out what I want to happen. I am sure you can figure out how to fit this to your code. Let me know if there are more questions.

Code:
global variable List;

Timer()  // is always running
    if the List of players is not empty -
        veryify everyone in the List is qualified
    for everyone in the List - if IsQualified, add them to TempList
    List = TempList;
    for everyone in List - do the effect.

   
IsQualified(Mobile m)
    return ( m is: in range, and they are a player or controlled mob or pet, and not a staff-member, and not carrying the immunity item)


OnMovement()
    if the one who moved is qualified, add them to the List.
 
Hehe, okay i will try, thank you so much :).


edit: Im very lost lol

edit2: can anyone tell me whats wrong about the first code that i post? thanks.
 
Last edited:

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back