bestuo

Initiate
Hello servuo community

Im customizing a monster, i want it to ignore players

ive been checking scripts, the only thing ive found is the AlterMeleeDamageTo method

i added it and changed to damage = 0;

it still attacking players dealing 1 damage, so is there any method to ignore playermobiles?
 
Set them to Fightmode.None:

public ServantOfSemidar()

: base(AIType.AI_Melee, FightMode.None, 10, 1, 0.2, 0.4)
 
i didnt check that one... i missed it,

and will it attack other basecreatures?
 
Last edited:
Not what you asked but check Team on basecreatures, it will make them fight each other. If someone looking for this information and ends up here.
 
Last edited:
Well i created a staff that summons liches on hit,

i wanted to avoid players from geting hit by those liches,

thats why im asking if there was a way to make a certain creature ignore playermobiles / dont attack them
 
If this is a one-off thing, add this override into your lich (not in the constructable area):
Code:
  public override bool IsEnemy(Mobile m)
  {
      BaseCreature c = m as BaseCreature;
       if (m is PlayerMobile || c != null && c.Controlled)
       {
         return false;
       }

  	return base.IsEnemy(m);
  }

This will make them not attack controlled pets and players. They should still fight back and attack blade spirits, though. For making them attack creatures, having them set to a different team will work.

I was already going to look into doing something like this, I think I'll do so now and report back later.
 
Last edited:
Very friendly and polite, i will test this as soon as i can and post here.


Thank you.

Just tested, lich still can attack players
 
Change the condition to this?
Code:
if (m is PlayerMobile || (c != null && c.Controlled))
This will probably work, that's pretty much trial-error but if it's still not working then it's another problem.
 
Ah, yes....could be an order of operations error. Always was a little fuzzy on how those work with logicals. Best use the parentheses.
Also, one line might need changed.
BaseCreature c = (BaseCreature)m;
might need to instead be:
BaseCreature c = m as BaseCreature;
 
Last edited:
BaseCreature c = m as BaseCreature;
Is the right thing to use.

It will simply be null if it's not a BaseCreature, the other one will say it can't be casted to BaseCreature if it's not one.
 
Well two things.

I would probably do it like this so there wouldnt be a variable declared just for a tiny check.
Code:
public override bool IsEnemy(Mobile m)
{
	if (m != null && (m is PlayerMobile || (m is BaseCreature && (m as BaseCreature).Controlled)))
	{
		return false;
	}
	return base.IsEnemy(m);
}

And next part is that if this is put in the normal Lich it would mean that they would not attack any player while I thought it would only be meant to do that when they are spawned by the staff on attack?
 
Yeah, you're right, I should've just used the parentheses, though I'm somewhat allergic to using them like that, as they can very quickly become an illegible mess of code-babble. Definitely bad for optimization, but using the variable keeps the check lines nice, neat, and easily readable.

Also, I'm pretty sure it's impossible for m to be null here? It certs isn't used in the normal IsEnemy module. :p

And no, it would need to be a distinct creature, in the same way summoned creatures have their own file. So the creature's type would be, for example, StaffLich rather than Lich.
[doublepost=1478421609][/doublepost]Here's a more systematic version. With this version, you should only need to set your StaffLich up with the IsFakePlayer override set to true.
Code:
      public virtual bool IsFakePlayer{ get{ return true; } }               // Am I considered a player by creatures?
IsFakePlayer is designed to make a creature aligned with players and pets, and other creatures will treat them as such.
By default, they will attack other creatures that will attack them (excepting players or fakeplayers set to override the default and attack players/fakes). Which fightmodes they target, not attacking players/fakes, and not attacking other creature teams by default can all be overridden.
Replacement for IsEnemy module in basecreature.cs:
Code:
//GS
     public virtual bool IsTeamEnemy{ get{ return !IsFakePlayer; } }             // Are other teams my enemy?
     public virtual bool IsPlayerEnemy{ get{ return !IsFakePlayer; } }           // Are players my enemy?
     public virtual bool IsFakePlayer{ get{ return false; } }               // Am I considered a player by creatures?

     // Fake Player Same-Team Creature Targets
     public virtual bool IsMonsterEnemy{ get{ return true; } }               // Are aggressive creatures my enemy?
     public virtual bool IsAnimalEnemy{ get{ return false; } }               // Are passive creatures my enemy?
     public virtual bool IsGoodEnemy{ get{ return Karma < 0; } }               // Are good-aligned creatures my enemy?
     public virtual bool IsEvilEnemy{ get{ return Karma > 0; } }               // Are evil-aliged creatures my enemy?

     public virtual bool IsEnemy(Mobile m)
     {
       XmlIsEnemy a = (XmlIsEnemy)XmlAttach.FindAttachment(this, typeof(XmlIsEnemy));

       if (a != null)
       {
         return a.IsEnemy(m);
       }

       // Are they a Guard?
       if (m is BaseGuard)
       {
         return false;
       }

       OppositionGroup g = OppositionGroup;

       // Are they part of my Opposition Group?
       if (g != null && g.IsEnemy(this, m))
       {
         return true;
       }

       // Are they part of my Faction?
       if (GetFactionAllegiance(m) == Allegiance.Ally)
       {
         return false;
       }

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

       // Are they part of my Ethic?
       if (pl != null && pl.IsShielded && (ourEthic == null || ourEthic == pl.Ethic))
       {
         return false;
       }

       BaseCreature c = m as BaseCreature;

       // Ignore a player, player pet, or fake player?
       if (!IsPlayerEnemy)
       {
         if (m is PlayerMobile)
         {
           return false;
         }

         if (c != null && (c.Controlled || c.IsFakePlayer))
         {
           return false;
         }
       }

       // Am I a fake player?
       if (IsFakePlayer)
       {
         // Ignore a non-creature, pet, fake player, or militia fighter
         if (c != null && !c.Controlled && !c.IsFakePlayer && !(m is MilitiaFighter))
         {
           // Are they an aggressive creature?
           if (c.FightMode == FightMode.Closest || c.FightMode == FightMode.Strongest || c.FightMode == FightMode.Weakest)
           {
             // Do I fight aggressive creatures?
             if (IsMonsterEnemy)
             {
               return true;
             }
           }
           // Are they a passive creature?
           else if (c.FightMode == FightMode.Aggressor)
           {
             // Do I fight passive creatures?
             if (IsAnimalEnemy)
             {
               return true;
             }
           }
           // Are they a good-aligned creature?
           else if (c.FightMode == FightMode.Evil)
           {
             // Do I fight good-aligned creatures?
             if (IsGoodEnemy)
             {
               return true;
             }
           }
           // Are they an evil-aligned creature?
           else if (c.FightMode == FightMode.Good)
           {
             // Do I fight evil-aligned creatures?
             if (IsEvilEnemy)
             {
               return true;
             }
           }
         }
       }

       // Are they a non-creature, fake player, or militia fighter?
       if (!(m is BaseCreature) || m is MilitiaFighter || c.IsFakePlayer)
       {
         return true;
       }

       // Summons should have same rules as their master, if their master is another creature
       if (c.Summoned && c.SummonMaster != null && c.SummonMaster is BaseCreature)
       {
         c = c.SummonMaster as BaseCreature;
       }

       BaseCreature t = this;

       // Summons should have same rules as their master, if their master is another creature
       if (t.Summoned && t.SummonMaster != null && t.SummonMaster is BaseCreature)
       {
         t = t.SummonMaster as BaseCreature;
       }

       // Do we fight other teams? Are we on different teams?
       if (IsTeamEnemy && (t.m_iTeam != c.m_iTeam))
       {
         return true;
       }

       // This section is somewhat weird, since BaseAI is the only place I know that uses IsEnemy
       // But it specifically prevents summoned/controlled creatures from checking IsEnemy
       // Left in, just in case it's used somewhere else.

       if (!IsPlayerEnemy)
       {
         // EVEN if I'm not Summoned/Controlled, DON'T fight those who are Summoned/Controlled
         if (!(t.Summoned || t.Controlled))
         {
           return false;
         }

         // If Summoned/Controlled, fight those who are not Summoned/Controlled
         return !(c.Summoned || c.Controlled);
       }

       // If Summoned/Controlled, fight those who are not Summoned/Controlled
       // If not Summoned/Controlled, fight those who are Summoned/Controlled
       return (t.Summoned || t.Controlled) != (c.Summoned || c.Controlled);
     }
//GS//
Note that you'll need my AcquireFocusMob fix (if you're not using latest SVN) for it to work right. It solves a few problems with logical faults the old version had.
Code:
//GS
     public virtual bool AcquireFocusMob(int iRange, FightMode acqType, bool bPlayerOnly, bool bFacFriend, bool bFacFoe)
     {
       if (m_Mobile.Deleted)
       {
         return false;
       }

       if (m_Mobile.BardProvoked)
       {
         if (m_Mobile.BardTarget == null || m_Mobile.BardTarget.Deleted)
         {
           m_Mobile.FocusMob = null;
           return false;
         }
         else
         {
           m_Mobile.FocusMob = m_Mobile.BardTarget;
           return (m_Mobile.FocusMob != null);
         }
       }
       else if (m_Mobile.Controlled)
       {
         if (m_Mobile.ControlTarget == null || m_Mobile.ControlTarget.Deleted || m_Mobile.ControlTarget.Hidden ||
           !m_Mobile.ControlTarget.Alive || m_Mobile.ControlTarget.IsDeadBondedPet ||
           !m_Mobile.InRange(m_Mobile.ControlTarget, m_Mobile.RangePerception * 2))
         {
           if (m_Mobile.ControlTarget != null && m_Mobile.ControlTarget != m_Mobile.ControlMaster)
           {
             m_Mobile.ControlTarget = null;
           }

           m_Mobile.FocusMob = null;
           return false;
         }
         else
         {
           m_Mobile.FocusMob = m_Mobile.ControlTarget;
           return (m_Mobile.FocusMob != null);
         }
       }

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

       if (acqType == FightMode.Aggressor && m_Mobile.Aggressors.Count == 0 && m_Mobile.Aggressed.Count == 0 &&
         m_Mobile.FactionAllegiance == null && m_Mobile.EthicAllegiance == null)
       {
         m_Mobile.FocusMob = null;
         return false;
       }

       if (m_Mobile.NextReacquireTime > Core.TickCount)
       {
         m_Mobile.FocusMob = null;
         return false;
       }

       m_Mobile.NextReacquireTime = Core.TickCount + (int)m_Mobile.ReacquireDelay.TotalMilliseconds;

       m_Mobile.DebugSay("Acquiring...");

       Map map = m_Mobile.Map;

       if (map != null)
       {
         Mobile newFocusMob = null;
         double val = double.MinValue;
         double theirVal;

         var eable = map.GetMobilesInRange(m_Mobile.Location, iRange);

         foreach (Mobile m in eable)
         {
           if (m.Deleted || m.Blessed)
           {
             continue;
           }

           // Let's not target ourselves...
           if (m == m_Mobile || m is BaseFamiliar)
           {
             continue;
           }

           // Dead targets are invalid.
           if (!m.Alive || m.IsDeadBondedPet)
           {
             continue;
           }

           // Staff members cannot be targeted.
           if (m.IsStaff())
           {
             continue;
           }

           // Does it have to be a player?
           if (bPlayerOnly && !m.Player)
           {
             continue;
           }

           // Can't acquire a target we can't see.
           if (!m_Mobile.CanSee(m))
           {
             continue;
           }

           if (m_Mobile.Summoned && m_Mobile.SummonMaster != null)
           {
             // If this is a summon, it can't target its controller.
             if (m == m_Mobile.SummonMaster)
               continue;

             // It also must abide by harmful spell rules if the master is a player.
             if (m_Mobile.SummonMaster is PlayerMobile && !Server.Spells.SpellHelper.ValidIndirectTarget(m_Mobile.SummonMaster, m))
               continue;

             // Players animated creatures cannot attack other players directly.
             if (m is PlayerMobile && m_Mobile.IsAnimatedDead && m_Mobile.SummonMaster is PlayerMobile)
               continue;
           }

           // If we only want faction friends
           if (bFacFriend && !bFacFoe)
           {
             // Ignore anyone who's not a friend
             if (!m_Mobile.IsFriend(m))
             {
               continue;
             }
           }
           // Don't ignore friends we want to and can help
           else if (!bFacFriend || !m_Mobile.IsFriend(m))
           {
             // Ignore anyone we can't hurt
             if (!m_Mobile.CanBeHarmful(m, false))
             {
               continue;
             }

             // Don't ignore hostile mobiles
             if (!IsHostile(m))
             {
               // Ignore anyone if we don't want enemies
               if (!bFacFoe)
               {
                 continue;
               }

               //Ignore anyone under EtherealVoyage
               if (TransformationSpellHelper.UnderTransformation(m, typeof(EtherealVoyageSpell)))
               {
                 continue;
               }

               // Ignore players with activated honor
               if (m is PlayerMobile && ((PlayerMobile)m).HonorActive && !(m_Mobile.Combatant == m))
               {
                 continue;
               }

               // Xmlspawner faction check
               // Ignore mob faction ranked players, more highly more often
               //if (!Server.Engines.XmlSpawner2.XmlMobFactions.CheckAcquire(this.m_Mobile, m))
               //continue;

               // We want a faction/ethic enemy
               bool bValid = (m_Mobile.GetFactionAllegiance(m) == BaseCreature.Allegiance.Enemy ||
                      m_Mobile.GetEthicAllegiance(m) == BaseCreature.Allegiance.Enemy);

               BaseCreature c = m as BaseCreature;

               // We want a special FightMode enemy
               if (!bValid)
               {
                 // We want a karma enemy
                 if (acqType == FightMode.Evil)
                 {
                   if (c != null && c.Controlled && c.ControlMaster != null)
                   {
                     bValid = (c.ControlMaster.Karma < 0);
                   }
                   else
                   {
                     bValid = (m.Karma < 0);
                   }
                 }
                 // We want a karma enemy
                 else if (acqType == FightMode.Good)
                 {
                   if (c != null && c.Controlled && c.ControlMaster != null)
                   {
                     bValid = (c.ControlMaster.Karma > 0);
                   }
                   else
                   {
                     bValid = (m.Karma > 0);
                   }
                 }
               }

               // Don't ignore valid targets
               if (!bValid)
               {
                 // Ignore anyone if we are a Passive FightMode
                 if (acqType == FightMode.Good || acqType == FightMode.Evil || acqType == FightMode.Aggressor)
                 {
                   continue;
                 }
                 // Ignore anyone if we are an Uncontrolled Summon
                 else if (c != null && c.Summoned)
                 {
                   continue;
                 }
                 // We want an enemy (We are an Aggressive FightMode)
                 else if (m_Mobile.IsEnemy(m))
                 {
                   bValid = true;
                 }
                 // Ignore anyone else
                 else
                 {
                   continue;
                 }
               }
             }
           }

           theirVal = m_Mobile.GetFightModeRanking(m, acqType, bPlayerOnly);

           if (theirVal > val && m_Mobile.InLOS(m))
           {
             newFocusMob = m;
             val = theirVal;
           }
         }

         eable.Free();

         m_Mobile.FocusMob = newFocusMob;
       }

       return (m_Mobile.FocusMob != null);
     }
//GS//
 
Last edited:
Well two things.

I would probably do it like this so there wouldnt be a variable declared just for a tiny check.
Code:
public override bool IsEnemy(Mobile m)
{
	if (m != null && (m is PlayerMobile || (m is BaseCreature && (m as BaseCreature).Controlled)))
	{
		return false;
	}
	return base.IsEnemy(m);
}

And next part is that if this is put in the normal Lich it would mean that they would not attack any player while I thought it would only be meant to do that when they are spawned by the staff on attack?

I created a new lich, so it wont affect normal ones :p

Annnnnnd i tried this, i tried griffon method, also what pooka said and still not working guys! but thanks so much for the replies

This is surprising, you all should team up and create a ultima online server, would be sucessfull im sure.

Now i will try the IsFakePlayer method, im afraid of editing basecreature thought

Thank you
 
Just remember to have a clean backup always. I usually name my clean backup .cs.txt (While other backups get .txt or .bak or something)
[doublepost=1478429931][/doublepost]
I created a new lich, so it wont affect normal ones :p

Annnnnnd i tried this, i tried griffon method, also what pooka said and still not working guys!

Did you forget to set the team to some non-zero amount? To make the simple one attack creatures you'd need to change its team in the constructable area (Say, right below where the Body is declared) like this:
Team = 66;

For the big one, it is irrelevant, since unless you add in an override, the team is ignored.
 
Last edited:
I forgot :oops: will do it now, haha thanks !

So u want me to add the Team = 66; in the stafflch script also

publicvirtualbool IsFakePlayer{get{returntrue;}} // Am I considered a player by creatures?

Then edit the basecreature and apply the last fix?
 
Last edited:
The small changes (team and IsEnemy override) are separate from the more systematic version. Both the team and isenemy override should be removed if you use the isfakeplayer override and the BaseAI/BaseCreature changes.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back