Full Version : PlayerRangeSensitiveMod
xmlspawner >>Scripts >>PlayerRangeSensitiveMod


<< Prev | Next >>

ArteGordon- 08-25-2006
PlayerRangeSensitiveMod
v2.0
RunUO 2.0 version
updated 8/25/06
ArteGordon


Summary:

AI mod that provides most of the benefits of having PlayerRangeSensitive=false (continuously active AI) with virtually none of the server load.


Recent Updates:

New to version 2.0
updated 8/25/06

- Greatly simplified the overall mod.
- installation instructions updated for RunUO 2.0

Description:

This mod resulted from a great idea by KillerBeez to allow servers to set PlayerRangeSensitive=true (AI shuts off when no players are around) but still have mobs to behave as though it were false (AI runs continuously) for some period of time even when players are out of range.
What this mod does is to allow creature AI to remain active for a delay period (set by the DeactivationDelay property, default is 2 minutes) after AI deactivation is triggered (when players go out of range). This essentially allows mob AI to behave as though PlayerRangeSensitive=false when players have been around but then move well beyond the normal range sensitivity (e.g. to other maps, or outside of dungeons), while leaving it true (hence no cpu load) for the vast majority of areas without any recent player activity.

This is particularly effective on shards with low player counts since it provides most of the benefits of PlayerRangeSensitive=false with virtually none of the load.
One thing that I especially like is that with the mod, mobs will no longer collect at dungeon entrances!

I would estimate that shards that are currently running with PlayerRangeSensitive=false, could set it to true, put the delay at something like 10-20 minutes and get behavior that was essentially indistinguishable from PlayerRangeSensitive=false but with 50-90% reduction in overall cpu load. Even at longer delay settings (hours) I would estimate significant reductions in overall cpu load given that significant fractions of each facet are likely to be unvisited over the course of an hour or two and the cpu load reduction will be esentially proportional to this fraction.

Commands:

- the "[setdeactivation [minutes]" command allows an admin to change the default deactivation delay in-game.

Note, setting it to zero will essentially disable the mod returning to the normal PlayerRangeSensitive=true behavior.
Also, changed values in-game will not be restored on server restarts. For permanent change of the deactivation delay, set the DefaultDeactivationDelay static variable in setdeactivation.cs


Installation:

see the installation notes in the PlayerRangeSensitiveMod.txt file for details.

Greystar- 03-13-2008
I have a question for you about this mod. I just applied it, however I want to make one type of mobile an exception to this so their AI never turns off. I have modded my Guards to be killable/not instakill/spawnable and I don't want their AI's to ever shut off. They are designed now to keep wandering mobiles (that are hostile) out of town and to keep criminals out of town. So I did the following:


CODE

   if( m_Owner.m_Mobile.Deleted )
   {
    Stop();
    return;
   }
   else if( m_Owner.m_Mobile.Map == null || m_Owner.m_Mobile.Map == Map.Internal )
   {
                   // ARTEGORDONMOD
                   // no need to run the AI if not on a map
                   Stop();
                   return;
   }
   else if( m_Owner.m_Mobile.PlayerRangeSensitive && !(m_Owner.m_Mobile is BaseGuard) )//have to check this in the timer....
   {
    Sector sect = m_Owner.m_Mobile.Map.GetSector( m_Owner.m_Mobile );
                   // ARTEGORDONMOD
                   // begin PlayerRangeSensitiveMod delayed inactivation
                   if (!sect.Active)
                   {
                       if (DateTime.Now > m_Owner.m_DeactivationTime)
                       {
                           m_Owner.Deactivate();
                           return;
                       }
                   }
                   else
                   {
                       m_Owner.m_DeactivationTime = DateTime.Now + TimeSpan.FromMinutes(m_Owner.DeactivationDelay);
                   }
                   // end PlayerRangeSensitiveMod    
   }


ArteGordon- 03-13-2008
You dont need to make any changes to the mod for that. Just set PlayerRangeSensitive to false for those mobs that you want to remain active.

To do that, add this override your guard script

CODE

       public override bool PlayerRangeSensitive { get{ return false; } }


You can also make a mod to basecreature.cs that will allow you to flip the AI of any creature on and off on the fly using attachments

CODE

       public virtual bool PlayerRangeSensitive
       {
           get
           {
               // ARTEGORDONMOD
               // allow creatures player range sensitivity to be disabled by
               /// attaching an xmldata attachment named EnableAI
               if (XmlAttach.FindAttachment(this, typeof(XmlData), "EnableAI") != null) return false;

               return true;
           }
       }


and then if you spawn them like

orc/ATTACH/xmldata,EnableAI

then their AI will stay on for as long as the attachment is there. That lets you toggle the AI of any creature.

Of course, you can make the basecreature.cs mod and also add the override in your specific creature to force it to be active all the time.

Greystar- 03-13-2008
QUOTE (ArteGordon @ March 13, 2008 02:43 pm)
You dont need to make any changes to the mod for that. Just set PlayerRangeSensitive to false for those mobs that you want to remain active.

To do that, add this override your guard script

CODE

       public override bool PlayerRangeSensitive { get{ return false; } }


You can also make a mod to basecreature.cs that will allow you to flip the AI of any creature on and off on the fly using attachments

CODE

       public virtual bool PlayerRangeSensitive
       {
           get
           {
               // ARTEGORDONMOD
               // allow creatures player range sensitivity to be disabled by
               /// attaching an xmldata attachment named EnableAI
               if (XmlAttach.FindAttachment(this, typeof(XmlData), "EnableAI") != null) return false;

               return true;
           }
       }


and then if you spawn them like

orc/ATTACH/xmldata,EnableAI

then their AI will stay on for as long as the attachment is there. That lets you toggle the AI of any creature.

Of course, you can make the basecreature.cs mod and also add the override in your specific creature to force it to be active all the time.

Thanks, Glad your always helpful.