RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

[RunUO 2.0 RC1] Shivan Spawneable Guards

mhantra

Sorceror
ok i need an help... i would like to let the guards attack monsters, RED players and GREY players ( for example who failed stealing ) BUT NOT players with negative karma with blu "name", as a necro can be or a thief.

How should i proceed? i tried
Code:
public override void OnMovement(Mobile m, Point3D oldLocation)
        {
            if (base.Combatant == null)
            {
                base.Warmode = false;
                if (InRange(m, base.RangePerception) && InRange(oldLocation, base.RangePerception) && InLOS(m))
                {
                    if (base.CanSee(m) && (m is BaseEvilGuard) || !(m.Hidden) && (m.Criminal) && (m.Karma <= -5000) && m.AccessLevel == AccessLevel.Player)
                    {
                        base.Combatant = m;
                        base.Warmode = true;
                    }
                }
            }
        }

or
Code:
    public override bool IsEnemy(Mobile m)
        {   
            if (m.Criminal == true && !(m is BaseVendor) || (m.Karma <= -5000) && !(m is BaseVendor) && (m is BaseCreature && !this.Controlled && CanBeHarmful(m)))
                return true;
            else
                return base.IsEnemy(m);
        }

but is not working... any suggestion? thx guys
 

shivan

Sorceror
Right, the fightmode is what make them to attack a negative karma player.
public BaseGoodGuard(AIType aiType): base(aiType,FightMode.Evil, 10, 1, 0.175, 0.350)
change it to "FightMode.Aggressor" in order to stop that, but them in order to make them attack pks you need to manually set that in "OnMovement".

Im do not remember right now how to detect pks, but i think they have negative Fame...

(base.CanSee(m) && (m is BaseEvilGuard) || !(m.Hidden) && (m.Criminal) && m.AccessLevel == AccessLevel.Player) || !(m.Hidden) && (m.fame <= -100) && m.AccessLevel == AccessLevel.Player)
Or something like that.
 

Gosmann

Sorceror
Right, the fightmode is what make them to attack a negative karma player.

change it to "FightMode.Aggressor" in order to stop that, but them in order to make them attack pks you need to manually set that in "OnMovement".

Im do not remember right now how to detect pks, but i think they have negative Fame...

(base.CanSee(m) && (m is BaseEvilGuard) || !(m.Hidden) && (m.Criminal) && m.AccessLevel == AccessLevel.Player) || !(m.Hidden) && (m.fame <= -100) && m.AccessLevel == AccessLevel.Player)
Or something like that.

any solutions now how to add pks?
fame doesnt work
 

Sythen

Sorceror
you do it by number of kills... (if number of player kills >= 5)

not fame because you can have blue characters with really bad karma levels
 

Acta Zenir

Wanderer
Hi, I'm new at RunUO and C# .


I'm using the Script (thx is great!) but I need to delete the NPC after he have been killed by the Guard.

Any tip ?

(sorry my English)
 

jpmythic

Sorceror
I havent posted in ages, but here is an addition/mod to this to allow Spawned guards in some regions
while disabling just the Spawned guards in other regions WITHOUT having to disable the guarded regions:

GuardedRegion.cs : (several areas of change here)

1:) Change the following section to match:
Code:
public class GuardedRegion : BaseRegion
    {
        private static readonly object[] m_GuardParams = new object[1];
        private readonly Type m_GuardType;
 
//Mythic DEBUG ADD Changes
        private readonly Dictionary<Mobile, GuardTimer> m_GuardCandidates = new Dictionary<Mobile, GuardTimer>();
        private bool m_Disabled;
 
        private bool m_SpawnGuards;
 
        public GuardedRegion(string name, Map map, int priority, params Rectangle3D[] area)
            : this(name, map, priority, false, area)
        { }
 
        public GuardedRegion(string name, Map map, int priority, bool spawnGuards, params Rectangle3D[] area)
            : base(name, map, priority, area)
        {
            this.m_GuardType = this.DefaultGuardType;
            this.m_SpawnGuards = spawnGuards;
        }
 
        public GuardedRegion(string name, Map map, int priority, params Rectangle2D[] area)
            : this(name, map, priority, false, area)
        { }
 
        public GuardedRegion(string name, Map map, int priority, bool spawnGuards, params Rectangle2D[] area)
            : base(name, map, priority, area)
        {
            this.m_GuardType = this.DefaultGuardType;
            this.m_SpawnGuards = spawnGuards;
        }
//Mythic DEBUG END Changes
...
...
        public GuardedRegion(XmlElement xml, Map map, Region parent)
            : base(xml, map, parent)
        {

2:) Modify this function and add to the end of it
Code:
        public GuardedRegion(XmlElement xml, Map map, Region parent)
            : base(xml, map, parent)
        {
            XmlElement el = xml["guards"];
 
...
...
            bool disabled = false;
            if (ReadBoolean(el, "disabled", ref disabled, false))
                this.Disabled = disabled;
 
...#ADD HERE
...Remove the ending } for this function and replace
...

this
Code:
//Mythic DEBUG Begin
            bool spawnGuards = false;
            if (ReadBoolean(el, "SpawnGuards", ref spawnGuards, false))
                this.SpawnGuards = spawnGuards;
        }
 
        public bool SpawnGuards
        {
            get
            {
                return this.m_SpawnGuards;
            }
            set
            {
                this.m_SpawnGuards = value;
            }
        }
 
        public virtual bool IsSpawnGuards()
        {
            return this.m_SpawnGuards;
        }
//Mythic DEBUG End

3:) Modify this function
Code:
        public override void MakeGuard(Mobile focus)
        {
 
//Mythic DEBUG Begin
            if (!this.IsSpawnGuards())
                return;
//Mythic DEBUG End
 
            BaseGuard useGuard = null;

4:) Modify this function
Code:
        public override void OnSpeech(SpeechEventArgs args)
        {
            base.OnSpeech(args);
 
            if (this.IsDisabled())
                return;
 
//Mythic DEBUG Begin
            if (!this.IsSpawnGuards())
                return;
//Mythic DEBUG End

5:) Modify this function
Code:
        public void CheckGuardCandidate(Mobile m)
        {
            if (this.IsDisabled())
                return;
 
            if (this.IsGuardCandidate(m))
            {
                GuardTimer timer = null;
                this.m_GuardCandidates.TryGetValue(m, out timer);
 
                if (timer == null)
                {
                    timer = new GuardTimer(m, this.m_GuardCandidates);
                    timer.Start();
 
                    this.m_GuardCandidates[m] = timer;
                    m.SendLocalizedMessage(502275); // Guards can now be called on you!
 
//Mythic DEBUG Begin
                    if (!this.IsSpawnGuards())
                        return;
//Mythic DEBUG End
 
                    Map map = m.Map;

6:) Modify this function
Code:
      public void CallGuards(Point3D p)
        {
            if (this.IsDisabled())
                return;
 
//Mythic DEBUG Begin
            if (!this.IsSpawnGuards())
                return;
//Mythic DEBUG End

7:) Add this just before the Last Function in file...
Code:
//Mythic DEBUG Begin
        [Usage("SetSpawnGuards <true|false>")]
        [Description("Enables or disables Spawning Guards for the current region.")]
        private static void SetSpawnGuards_OnCommand(CommandEventArgs e)
        {
            Mobile from = e.Mobile;
 
            if (e.Length == 1)
            {
                GuardedRegion reg = (GuardedRegion)from.Region.GetRegion(typeof(GuardedRegion));
 
                if (reg == null)
                {
                    from.SendMessage("You are not in a guardable region.");
                }
                else
                {
                    reg.SpawnGuards = !e.GetBoolean(0);
 
                    if (reg.SpawnGuards)
                        from.SendMessage("The spawn guards in this region have been enabled.");
                    else
                        from.SendMessage("The spawn guards in this region have been disabled.");
                }
            }
            else
            {
                from.SendMessage("Format: SetSpawnGuards <true|false>");
            }
        }
//Mythic DEBUG End
 
        private class GuardTimer : Timer

8:) Almost forgot:
Code:
        public static void Initialize()
        {
            CommandSystem.Register("CheckGuarded", AccessLevel.GameMaster, new CommandEventHandler(CheckGuarded_OnCommand));
            CommandSystem.Register("SetGuarded", AccessLevel.Administrator, new CommandEventHandler(SetGuarded_OnCommand));
            CommandSystem.Register("ToggleGuarded", AccessLevel.Administrator, new CommandEventHandler(ToggleGuarded_OnCommand));
 
//Mythic DEBUG Begin
          CommandSystem.Register("SetSpawnGuards", AccessLevel.Administrator, new CommandEventHandler(SetSpawnGuards_OnCommand));
//Mythic DEBUG End

And your done... This is designed to allow you to Turn ON normal guard spawning in any region

As a GM, just goto the region you want guards to be spawned and use the command:
[SetSpawnGuards true
and normal Guards will spawn on speech...

Otherwise by Default (as it is set at top of changes), All Guarded Regions still function as guarded regions
BUT only guards you add to area like any spawn critter will do their jobs, No Auto Tele Guards will appear.

I set it to Default OFF as Spawned Guards of Old are probably only going to be wanted in certain areas.
This doesn't change the behaviour of the new guards in the main script, this only Removes the Original Guards
from being spawned.
 

seraph035

Sorceror
The dismount and mount thing is a client error, or maybe a RunUO bug, the problem is an animation. It happends with all mounted creatures.

Not so much of a bug as an oversight on the part of the original programmer: it occurs during the 'getidleanimation' phase of the basecreature.cs script, where the mounted creature shows it's idle animation ... if an additional test to filter out mounted creatures is added to this portion, mounted npc mobs will not dismount, look around, then remount.
 

AlphaDragon

Sorceror
Just wakeing up, and was also wondering how to stop the (npcs that are mounted) from (at idle or what ever - Get off mount look around and then get back on mount).
Will check getidleanimation in basecreature.cs later when have a chance. (Unless someone else already has a fix?)
 

jpmythic

Sorceror
Thats what happens when ya program late into the night :)

You only to modify this function to get these xmlspawner guards to behave similar to the Old SpawnOnPlayer Guards.
It turned out pretty simple really...
GuardedRegion.cs
Code:
        public override void MakeGuard(Mobile focus)
        {
            foreach (Mobile m in focus.GetMobilesInRange(8))
            {
                if (m is BaseGuard)
                {
                    BaseGuard g = (BaseGuard)m;
                    if (g.Focus == null) // idling
                    {
                        g.Focus = focus;
                        return;
                    }
                }
                else if( m is BaseSpawnGuard)
                {
                    BaseSpawnGuard g = (BaseSpawnGuard)m;
                    if (g.FocusMob == null) // idling
                    {
                        g.FocusMob = focus;
                        return;
                    }
                }
            }
 
            if (this.IsSpawnGuards())
            {
                m_GuardParams[0] = focus;
                try
                {
                    Activator.CreateInstance(this.m_GuardType, m_GuardParams);
                }
                catch { }
            }
        }
You still need to add the code for the Function IsSpawnGuards() which if TRUE will do Old Style Guards
Otherwise it will send a newwarriorguard if it can find one, altho I use a new modified Guard, so you would need
to check for each guard type with the original NewWarriorGuard..

Code:
                else if( m is BaseGoodGuard )
                {
                    BaseSpawnGuard g = (BaseSpawnGuard)m;
                    if (g.FocusMob == null) // idling
                    {
                        g.FocusMob = focus;
                        return;
                    }
                }
                else if( m is BaseNoCriminalGuard )
                    BaseNoCriminalGuard g = (BaseNoCriminalGuard )m;
                    if (g.FocusMob == null) // idling
                    {
                        g.FocusMob = focus;
                        return;
                    }
                }

Enjoy
 

jpmythic

Sorceror
Havn't Tried this yet, but will shortly: the Idle Animation in ForkUO seems to ba accessed this way now..

BaseCreature.cs (with my changes)
Code:
        public virtual bool CheckIdle()
        {
            if (this.Combatant != null)
                return false; // in combat.. not idling

            if (this.m_IdleReleaseTime > DateTime.MinValue)
            {
                // idling...
                if (DateTime.Now >= this.m_IdleReleaseTime)
                {
                    this.m_IdleReleaseTime = DateTime.MinValue;
                    return false; // idle is over
                }

                return true; // still idling
            }

            if (95 > Utility.Random(100))
                return false; // not idling, but don't want to enter idle state

            this.m_IdleReleaseTime = DateTime.Now + TimeSpan.FromSeconds(Utility.RandomMinMax(15, 25));

            //Mythic DEBUG
            if (this is BaseMount && ((BaseMount)this).Rider is BaseSpawnGuard)
            {
                //We WANT to enter Idle state but Not Dismount
            }
            else if (this.Body.IsHuman)
            {

Might do it...
 
Top