Opywang

Member
When you have pet on guard, and if you attack first pet does nothing. On Demise they seem to have figure it out, and pet guard at everything that attack you no matter what if anybody know the AI script for that I would appreciate it very much!
 
If you are attacked, the pet will guard you & attack the attacker. If YOU attack a mob, it will only defend you from other attackers. It defends against an aggressor, but not a mob you attack. And if you have more than 1 pet out & guarding, only the 1st one you pulled from the stables will defend against an aggressor, any others need to "hear" the kill command. To change that would most likely require modifications to BaseAI.cs itself.
 
You could override PlayerMobile.OnCombatantChange() and loop through the player's follower's list, fetching pets that are in Guard mode, then setting their Combatant to the player's current Combatant.

Code:
// Required (top of script): 
// using System.Linq;

public override void OnCombatantChange()
{
	base.OnCombatantChange();

	if (Combatant != null)
	{
		foreach (var pet in AllFollowers.OfType<BaseCreature>())
		{
			if (pet.Combatant != null && pet.Combatant != Combatant && pet.ControlOrder == OrderType.Guard)
			{
				pet.Attack(Combatant);
			}
		}
	}
}
 
Has anyone here applied Voxpires code? Does it produce any unexpected unintended consequences?
 
Yes I tried to apply this but sadly my Shard runs on RunUO V. 2.0 so (as far as I know) using System.Linq; does not work for me and neither does the code without it. No idea how this might work in my case but wide open to ideas. Thanks
 
Yes I tried to apply this but sadly my Shard runs on RunUO V. 2.0 so (as far as I know) using System.Linq; does not work for me and neither does the code without it. No idea how this might work in my case but wide open to ideas. Thanks
You can upgrade your project .NET support.

Otherwise, this is the code without Linq:
C#:
public override void OnCombatantChange()
{
    base.OnCombatantChange();

    if (Combatant != null)
    {
        foreach (var m in AllFollowers)
        {
            BaseCreature pet = m as BaseCreature;

            if (pet != null && pet.Combatant != null && pet.Combatant != Combatant && pet.ControlOrder == OrderType.Guard)
            {
                pet.Attack(Combatant);
            }
        }
    }
}
 
Thank you Voxpire. As always your knowledge is 'bang on' and your response is prompt.

I really appreciate the information and it works perfectly.

Cheers
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back