Welcome
Welcome to <strong>SunUO</strong>.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

AFK script

Release your custom scripts to the public. By posting your scripts here it is automatically licensed under the terms of the GPL.

AFK script

Postby Maik on Mon Aug 27, 2007 9:50 pm

Subject just say it:

Code: Select all
using System;
using System.Collections;
using Server;

namespace Server.Scripts.Commands
{
   /// <summary>
   /// Summary description for AFK.
   /// </summary>
   public class AFK : Timer
   {
      private static Hashtable m_AFK = new Hashtable();
      private Mobile who;
      private Point3D where;
      private DateTime when;
      public string what="";

      public static void Initialize()
      {
         Server.Commands.Register( "afk", AccessLevel.Player, new CommandEventHandler( AFK_OnCommand ) );
         EventSink.Logout += new LogoutEventHandler( OnLogout );
         EventSink.Speech += new SpeechEventHandler( OnSpeech );
         EventSink.PlayerDeath += new PlayerDeathEventHandler( OnDeath);
      }
      public static void OnDeath( PlayerDeathEventArgs e )
      {
         if ( m_AFK.Contains( e.Mobile.Serial.Value ) )
         {
            AFK afk=(AFK)m_AFK[e.Mobile.Serial.Value];
            if (afk==null)
            {
               e.Mobile.SendMessage("Object is missing!");
               return;
            }
            e.Mobile.PlaySound(  e.Mobile.Female ? 814 : 1088 );
            afk.wakeUp();
         }
      }
      public static void OnLogout( LogoutEventArgs e )
      {
         if ( m_AFK.Contains( e.Mobile.Serial.Value ) )
         {
            AFK afk=(AFK)m_AFK[e.Mobile.Serial.Value];
            if (afk==null)
            {
               e.Mobile.SendMessage("Object is missing!");
               return;
            }
            afk.wakeUp();
         }
      }
      public static void OnSpeech( SpeechEventArgs e )
      {
         if ( m_AFK.Contains( e.Mobile.Serial.Value ) )
         {
            AFK afk=(AFK)m_AFK[e.Mobile.Serial.Value];
            if (afk==null)
            {
               e.Mobile.SendMessage("Object is missing!");
               return;
            }
            afk.wakeUp();
         }
      }
      public static void AFK_OnCommand( CommandEventArgs e )
      {
         if ( m_AFK.Contains( e.Mobile.Serial.Value ) )
         {
            AFK afk=(AFK)m_AFK[e.Mobile.Serial.Value];
            if (afk==null)
            {
               e.Mobile.SendMessage("Object is missing!");
               return;
            }
            afk.wakeUp();
         }
         else
         {
            m_AFK.Add( e.Mobile.Serial.Value,new AFK(e.Mobile,e.ArgString.Trim()) );
            e.Mobile.SendMessage( "You enter the afk mode. If you are longer than 5 minutes afk, you should logout." );
         }
      }
      public void wakeUp()
      {
         m_AFK.Remove( who.Serial.Value );
         who.Emote("*wake up*");
         who.SendMessage( "You leaving the afk mode." );
         this.Stop();
      }
      public AFK(Mobile afker, string message) : base(TimeSpan.FromSeconds(10),TimeSpan.FromSeconds  (5))
      {
         if ((message==null)||(message=="")) message="AFK time";
         what=message;
         who=afker;
         when=DateTime.Now;
         where=who.Location;
         this.Start();
      }
      protected override void OnTick()
      {
         if (!(who.Location==where) )
         {
            this.wakeUp();
            return;
         }
         who.Say("zZz");
         TimeSpan ts=DateTime.Now.Subtract(when);
         who.Emote("*{0} ({1}:{2}:{3})*",what,ts.Hours,ts.Minutes,ts.Seconds);
         who.PlaySound(  who.Female ? 819 : 1093);
      }
   }
}
User avatar
Maik
 
Posts: 30
Joined: Wed Aug 15, 2007 3:30 pm

Return to Script Releases

Who is online

Users browsing this forum: No registered users and 0 guests