Guest User

Untitled

a guest
Jul 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. using Server.Commands;
  2. using System;
  3. using System.Collections;
  4. using Server;
  5. using Server.Commands.Generic;
  6. using Server.Network;
  7. using Server.Misc;
  8.  
  9. namespace Server.Commands
  10. {
  11. public class AFK : Timer
  12. {
  13. private static Hashtable m_AFK = new Hashtable();
  14. private Mobile who;
  15. private Point3D where;
  16. private DateTime when;
  17. public string what="";
  18.  
  19. public static void Initialize()
  20. {
  21. CommandSystem.Register( "afk", AccessLevel.Player, new CommandEventHandler( AFK_OnCommand ) );
  22. EventSink.Logout += new LogoutEventHandler( OnLogout );
  23. EventSink.Speech += new SpeechEventHandler( OnSpeech );
  24. EventSink.PlayerDeath += new PlayerDeathEventHandler( OnDeath);
  25. }
  26.  
  27. [Usage( "afk" )]
  28. [Description( "sets you afk for others to see." )]
  29. public static void AFK_OnCommand( CommandEventArgs e )
  30. {
  31. if ( m_AFK.Contains( e.Mobile.Serial.Value ) )
  32. {
  33. AFK afk=(AFK)m_AFK[e.Mobile.Serial.Value];
  34. if (afk==null)
  35. {
  36. e.Mobile.SendMessage("Afk object missing!");
  37. return;
  38. }
  39. afk.wakeUp();
  40. }
  41. else
  42. {
  43. m_AFK.Add( e.Mobile.Serial.Value,new AFK(e.Mobile,e.ArgString.Trim()) );
  44. e.Mobile.SendMessage( "AFK enabled." );
  45. }
  46. }
  47.  
  48. public static void OnDeath( PlayerDeathEventArgs e )
  49. {
  50. if ( m_AFK.Contains( e.Mobile.Serial.Value ) )
  51. {
  52. AFK afk=(AFK)m_AFK[e.Mobile.Serial.Value];
  53. if (afk==null)
  54. {
  55. e.Mobile.SendMessage("Afk object missing!");
  56. return;
  57. }
  58. e.Mobile.PlaySound( e.Mobile.Female ? 814 : 1088 );
  59. afk.wakeUp();
  60. }
  61. }
  62. public static void OnLogout( LogoutEventArgs e )
  63. {
  64. if ( m_AFK.Contains( e.Mobile.Serial.Value ) )
  65. {
  66. AFK afk=(AFK)m_AFK[e.Mobile.Serial.Value];
  67. if (afk==null)
  68. {
  69. e.Mobile.SendMessage("Afk object missing!");
  70. return;
  71. }
  72. afk.wakeUp();
  73. }
  74. }
  75. public static void OnSpeech( SpeechEventArgs e )
  76. {
  77. if ( m_AFK.Contains( e.Mobile.Serial.Value ) )
  78. {
  79. AFK afk=(AFK)m_AFK[e.Mobile.Serial.Value];
  80. if (afk==null)
  81. {
  82. e.Mobile.SendMessage("Afk object missing!");
  83. return;
  84. }
  85. afk.wakeUp();
  86. }
  87. }
  88.  
  89. public void wakeUp()
  90. {
  91. m_AFK.Remove( who.Serial.Value );
  92. who.Emote("*is no longer AFK*");
  93. who.SendMessage( "AFK deactivated." );
  94. this.Stop();
  95. }
  96. public AFK(Mobile afker, string message) : base(TimeSpan.FromSeconds(30),TimeSpan.FromSeconds (30))
  97. {
  98. if ((message==null)||(message=="")) message="is AFK";
  99. what=message;
  100. who=afker;
  101. when=DateTime.Now;
  102. where=who.Location;
  103. this.Start();
  104. }
  105. protected override void OnTick()
  106. {
  107. if (!(who.Location==where) )
  108. {
  109. this.wakeUp();
  110. return;
  111. }
  112. who.Say("afk zZz");
  113. TimeSpan ts=DateTime.Now.Subtract(when);
  114. who.Emote("*{0} ({1}:{2}:{3})*",what,ts.Hours,ts.Minutes,ts.Seconds);
  115. who.PlaySound( who.Female ? 819 : 1093);
  116. }
  117. }
  118. }
Add Comment
Please, Sign In to add comment