|
||
|
|||||||
| FAQ Forum A place to find answers to the most frequently asked questions, and a place to post said answers. Do NOT use this forum to ask questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Expert
Join Date: Oct 2004
Location: Chesterton, IN
Age: 29
Posts: 288
|
Well, I've seen several people lately ask about how they can do things when players login, etc, so, I've decided to put together a very quick tutorial on using EventSink.
Q: What is the EventSink Class? A: The EventSink Class is a class that gives you the ability to "subscribe" to specific events that happen in the game. Q: Subscribe? Huh? A: Think of it as subscribing to your local newspaper. Every morning (or whenever the newspaper is delivered), you get a newspaper at your door. In effect, you are "informed" of this "event", and can take action on it. This may sound strange, but It'll make sense later. Q: OK, enough talk, show me! A: Alright, scroll down below for a sample EventSink class. Code:
using Server;
namespace Server.Misc
{
public class EventSinkTest
{
public static void Initialize()
{
EventSink.Login += new LoginEventHandler(EventSink_Login);
EventSink.PlayerDeath += new PlayerDeathEventHandler(EventSink_PlayerDeath);
EventSink.Logout += new LogoutEventHandler(EventSink_Logout);
}
public static void EventSink_Login(LoginEventArgs e)
{
//Broadcast a message to everyone
World.Broadcast(0x35, true, string.Format("{0} just logged in.", e.Mobile.Name));
}
public static void EventSink_Logout(LogoutEventArgs e)
{
//Broadcast a message to everyone
World.Broadcast(0x35, true, string.Format("{0} just logged out.", e.Mobile.Name));
}
public static void EventSink_PlayerDeath(PlayerDeathEventArgs e)
{
//Auto resurrect
e.Mobile.Resurrect();
e.Mobile.Hits = e.Mobile.HitsMax;
e.Mobile.Stam = e.Mobile.StamMax;
e.Mobile.Mana = e.Mobile.ManaMax;
}
}
}
Code:
public static void Initialize() Code:
EventSink.Login += new LoginEventHandler(EventSink_Login); Now that you have the subscription setup, you need the procedure call: Code:
public static void EventSink_Login(LoginEventArgs e)
{
}
That is the end of this tutorial...yes it's small, but I wanted to try and make this as easy as possible. Poke around the EventSink class to find out other events that you can subscribe to. Also, take a look at the other 2 EventSinks that I use in this class. Good luck, and happy coding! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|