Full Version : Taming Pets Issue
xmlspawner >>Scripting Support >>Taming Pets Issue


<< Prev | Next >>

Erica- 08-22-2006
Hi i am not sure if anyone has noticed it but lets say if theres a player has taming goes into the world and works on his or her taming when the release the taming pet it stays in world so i think thats and issue cause if you had 10 tamers taming in world you would have a lot of loose pets in world and i think thats not a good thing cause its adding mobiles or items in world there should be a way to make them disapear after minutes or hours so you dont have lots of loose pets in world.

ArteGordon- 08-22-2006
what I do is to make other creatures attack them. In BaseAI.cs around line 2520

CODE

     if ( acqType == FightMode.Evil && !bValid )
     {
      if( m is BaseCreature && ((BaseCreature)m).Controlled && ((BaseCreature)m).ControlMaster != null )
      bValid = ( ((BaseCreature)m).ControlMaster.Karma < 0 );
      else
      bValid = ( m.Karma < 0 );
     }

     // ARTEGORDONMOD
     // attack all uncontrolled, previously tamed pets
     if (m is BaseCreature && !((BaseCreature)m).Controlled && ((BaseCreature)m).ControlMaster == null && ((BaseCreature)m).Owners != null && ((BaseCreature)m).Owners.Count > 0)
     {
      bValid = true;
     }

     if ( !bValid )
      continue;


(more fun than just having them disappear smile.gif

Erica- 08-22-2006
Tryed your code was on my owner char tamed a pig to test released and no other creatures attacked it at all .

ArteGordon- 08-22-2006
Hmm, you are right, doesnt seem to work under 2.0.
This way will work. In BaseCreature.cs around line 800

QUOTE

        public virtual bool IsEnemy(Mobile m)
        {
            OppositionGroup g = this.OppositionGroup;

            if (g != null && g.IsEnemy(this, m))
                return true;

            if (m is BaseGuard)
                return false;

            if (GetFactionAllegiance(m) == Allegiance.Ally)
                return false;

            Ethics.Ethic ourEthic = EthicAllegiance;
            Ethics.Player pl = Ethics.Player.Find(m, true);

            if (pl != null && pl.IsShielded && (ourEthic == null || ourEthic == pl.Ethic))
                return false;

            if (!(m is BaseCreature) || m is Server.Engines.Quests.Haven.MilitiaFighter)
                return true;

            BaseCreature c = (BaseCreature)m;

            // ARTEGORDONMOD
            // attack all uncontrolled, previously tamed pets
            if (!c.Controlled && c.ControlMaster == null && c.Owners != null && c.Owners.Count > 0)
                return true;

            return (m_iTeam != c.m_iTeam || ((m_bSummoned || m_bControlled) != (c.m_bSummoned || c.m_bControlled))/* || c.Combatant == this*/ );
        }

Erica- 08-22-2006
It works let say if you tamed a cow or a rabbit ect ect animals that dont attack release them and the rest of the other regular animals wont attack them only monsters will attack not regular creatures is there something missing would be better if and animal or monster attacks it.

ArteGordon- 08-23-2006
that is a little more involved since it means altering the way that the normal non-aggressive AI for animals works.

You need to make these changes:

in BaseCreature.cs around line 800, make these changes

QUOTE


        // ARTEGORDONMOD
        // test for previously tamed creatures
        public static bool IsPreviouslyTamed(Mobile m)
        {
            if (m is BaseCreature)
            {
                BaseCreature c = m as BaseCreature;
                return (!c.Controlled && c.ControlMaster == null && c.Owners != null && c.Owners.Count > 0);
            }
            else
                return false;

        }

        // ARTEGORDONMOD
        // test for nearby previously tamed creatures
        public static bool HasNearbyPreviouslyTamed(Mobile m, int iRange)
        {
            if (m == null) return false;

            Map map = m.Map;

            if (map == null) return false;

            IPooledEnumerable eable = map.GetMobilesInRange(m.Location, iRange);
            foreach (Mobile c in eable)
            {
                if (IsPreviouslyTamed( c )) return true;
            }
            eable.Free();

            return false;
        }

        public virtual bool IsEnemy(Mobile m)
        {
            OppositionGroup g = this.OppositionGroup;

            if (g != null && g.IsEnemy(this, m))
                return true;

            if (m is BaseGuard)
                return false;

            if (GetFactionAllegiance(m) == Allegiance.Ally)
                return false;

            Ethics.Ethic ourEthic = EthicAllegiance;
            Ethics.Player pl = Ethics.Player.Find(m, true);

            if (pl != null && pl.IsShielded && (ourEthic == null || ourEthic == pl.Ethic))
                return false;

            if (!(m is BaseCreature) || m is Server.Engines.Quests.Haven.MilitiaFighter)
                return true;

            BaseCreature c = (BaseCreature)m;

            // ARTEGORDONMOD
            // attack all uncontrolled, previously tamed pets
            if (IsPreviouslyTamed(m))
                return true;


            return (m_iTeam != c.m_iTeam || ((m_bSummoned || m_bControlled) != (c.m_bSummoned || c.m_bControlled))/* || c.Combatant == this*/ );
        }


and then in BaseAI.cs in the AcquireFocusMob method around line 2420

QUOTE

            if (acqType == FightMode.None)
            {
                m_Mobile.FocusMob = null;
                return false;
            }

            // ARTEGORDONMOD
            // allow non-aggressive creatures to attack previously tamed creatures
            if (acqType == FightMode.Aggressor && m_Mobile.Aggressors.Count == 0 && m_Mobile.Aggressed.Count == 0 && m_Mobile.FactionAllegiance == null && m_Mobile.EthicAllegiance == null && !BaseCreature.HasNearbyPreviouslyTamed(m_Mobile, iRange))
            {
                m_Mobile.FocusMob = null;
                return false;
            }

            if (m_Mobile.NextReacquireTime > DateTime.Now)
            {
                m_Mobile.FocusMob = null;
                return false;
            }


and then later in that method around 2530

QUOTE

                       if (acqType == FightMode.Evil && !bValid)
                        {
                            if (m is BaseCreature && ((BaseCreature)m).Controlled && ((BaseCreature)m).ControlMaster != null)
                                bValid = (((BaseCreature)m).ControlMaster.Karma < 0);
                            else
                                bValid = (m.Karma < 0);
                        }

                        // ARTEGORDONMOD
                        // allow non-aggressive creatures to attack previously tamed creatures
                        if (BaseCreature.IsPreviouslyTamed(m))
                            bValid = true;


                        if (!bValid)
                            continue;


With these changes, any creature will target previously tamed pets, including normally aggressive monsters, those that would normally only fight evil creatures, or those that only fight when attacked first.

It can be fun to see how well they do, since they will get stronger with each successful battle.

Haazen- 08-23-2006
Thank you Arte,
This is a great mod.
Thanks for bringing it up Erica.

Erica- 08-24-2006
Hmm thats odd i tryed this one as well and only monster attacks what you tamed not the regular animal wont attack.

ArteGordon- 08-24-2006
QUOTE (Erica @ August 24, 2006 06:04 pm)
Hmm thats odd i tryed this one as well and only monster attacks what you tamed not the regular animal wont attack.

double check the mods to baseai.cs. Those are the ones that allow normally non-aggressive animals to attack.

Erica- 08-24-2006
heres the script seems to be right heres part of it
CODE
if( m_Mobile.ConstantFocus != null )
  {
   m_Mobile.DebugSay( "Acquired my constant focus" );
   m_Mobile.FocusMob = m_Mobile.ConstantFocus;
   return true;
  }

  if( acqType == FightMode.None )
  {
   m_Mobile.FocusMob = null;
   return false;
  }
                 // ARTEGORDONMOD
                 // allow non-aggressive creatures to attack previously tamed creatures
                 //  && !BaseCreature.HasNearbyPreviouslyTamed(m_Mobile, iRange) )<--EDIT Part
  if ( acqType == FightMode.Aggressor && m_Mobile.Aggressors.Count == 0 && m_Mobile.Aggressed.Count == 0 && m_Mobile.FactionAllegiance == null && m_Mobile.EthicAllegiance == null && !BaseCreature.HasNearbyPreviouslyTamed(m_Mobile, iRange) )
  {
   m_Mobile.FocusMob = null;
   return false;
  }


and heres the basecreature one
CODE
public virtual Allegiance GetEthicAllegiance( Mobile mob )
 {
  if ( mob == null || mob.Map != Faction.Facet || EthicAllegiance == null )
   return Allegiance.None;

  Ethics.Ethic ethic = Ethics.Ethic.Find( mob, true );

  if ( ethic == null )
   return Allegiance.None;

  return ( ethic == EthicAllegiance ? Allegiance.Ally : Allegiance.Enemy );
 }
 #endregion
           // ARTEGORDONMOD START
           // test for previously tamed creatures
           public static bool IsPreviouslyTamed(Mobile m)
           {
           if (m is BaseCreature)
           {
               BaseCreature c = m as BaseCreature;
               return (!c.Controlled && c.ControlMaster == null && c.Owners != null && c.Owners.Count > 0);
           }
           else
               return false;

           }

           // ARTEGORDONMOD
           // test for nearby previously tamed creatures
           public static bool HasNearbyPreviouslyTamed(Mobile m, int iRange)
           {
           if (m == null) return false;

           Map map = m.Map;

           if (map == null) return false;

           IPooledEnumerable eable = map.GetMobilesInRange(m.Location, iRange);
           foreach (Mobile c in eable)
           {
               if (IsPreviouslyTamed( c )) return true;
           }
           eable.Free();

           return false;
           }
 // ARTEGORDONMOD END
           public virtual bool IsEnemy( Mobile m )
 {
  OppositionGroup g = this.OppositionGroup;



and other part
CODE
BaseCreature c = (BaseCreature)m;
                 // ARTEGORDONMOD START
                 // attack all uncontrolled, previously tamed pets
                 if (IsPreviouslyTamed(m))
                 return true;
                 // ARTEGORDONMOD END
                 return ( m_iTeam != c.m_iTeam || ( (m_bSummoned || m_bControlled) != (c.m_bSummoned || c.m_bControlled) )/* || c.Combatant == this*/ );





ArteGordon- 08-24-2006
you missed one baseai.cs mod. The one around line 2530

Erica- 08-24-2006
Your right thanks missed that line funny as hell tho tamed a rat by 2 chickens released the rat and both chickens are fighting it lol.

ArteGordon- 08-24-2006
hehe. yeah, I do find it amusing.