| CODE |
using System; using Server; using Server.Items; using Server.Mobiles; using Server.Misc; namespace Server.Misc { public class MotCle { //ça permet d'ajouter de nouveaux évènements (ici Speech). public static void Initialize() { //EventSink : Gèrent les différents évènements. (cf docs : Server/EventSink) EventSink.Speech += new SpeechEventHandler( EventSink_MotCle ); //Fait un lien vers EventSink_MotCle. } public static void EventSink_MotCle( SpeechEventArgs args ) { Mobile from = args.Mobile; //Importe le Mobile string keywords = args.Speech;//Importe ce que dit le joueur. (ici, il ne sert à rien) PlayerMobile m = ((PlayerMobile )from ); switch ( keywords ) { case "test": //Mot qu'il faut prononcer. (attention : Majuscule & Minuscule) { if ( m is PlayerMobile) //vérifie si c'est un joueur. { MonTimer timer = new MonTimer(from); //Crée un objet timer et on lui transmet les info de "from"(Mobile). timer.Start(); //Lance timer. On peut aussi ecrire : MonTimer timer = new MonTimer(from).Start(); from.SendMessage("MonTimer est créer!!!"); } break; } } } } public class MonTimer : Timer { private Mobile mobile;//On précise qu'on vas utiliser une variable de type : Mobile private PlayerMobile m; // On precise qu'on vas utiliser une variable de type : PlayerMobile private int t_Nbr; // On précise qu'on va utilise une variable de type : int (un nombre) public MonTimer(Mobile from ) : base ( TimeSpan.FromSeconds (5.0), TimeSpan.FromSeconds (5.0) ) // ici je sais pas pourquoi on met 2x TimeSpan, c'est le temps entre chaques OnTick() { mobile = from; // On importe l'objet(Mobile) nommer "from" dans la variable mobile. m = ((PlayerMobile) mobile); // "m" est égal à la sous-classe "PlayerMobile" de l'objet mobile(Mobile) mobile.SendMessage("MonTimer vient de commencer"); } protected override void OnTick() //Chaque fois que le Timer passe le TimeSpan ça active le OnTick(). { t_Nbr++; // A chaque OnTick() on rajoute 1 à t_Nbr m.Str += 1; mobile.SendMessage("ceci est un test de timer!"); mobile.SendMessage("MonTimer Numero : {0}", t_Nbr); if (t_Nbr == 5) // Si t_Nbr arrive à 5. Si vous mettez Stop() sans une petite vérification de ce genre, le script s'arretera au premier OnTick(). { mobile.SendMessage("MonTimer vient de finir!"); Stop(); // Si vous ne mettez pas de Stop() le timer tournera toujours. } } } } |
| CODE |
using System; using Server; using Server.Items; using Server.Mobiles; using Server.Misc; namespace Server.Misc { public class MotCle { public static void Initialize() { EventSink.Speech += new SpeechEventHandler( EventSink_MotCle ); } public static void EventSink_MotCle( SpeechEventArgs args ) { Mobile from = args.Mobile; string keywords = args.Speech; PlayerMobile m = ((PlayerMobile )from ); switch ( keywords ) { case "teSt": { if ( m is PlayerMobile) { MonTimer timer = new MonTimer(from); timer.Start(); from.SendMessage("MonTimer est créer!!!"); } break; } } } } public class MonTimer : Timer { private Mobile mobile; private PlayerMobile m; private int t_Nbr; public MonTimer(Mobile from ) : base ( TimeSpan.FromSeconds (5.0), TimeSpan.FromSeconds (5.0) ) { mobile = from; m = ((PlayerMobile) mobile); mobile.SendMessage("MonTimer vient de commencer"); } protected override void OnTick() { t_Nbr++; m.Str += 1; mobile.SendMessage("ceci est un test de timer!"); mobile.SendMessage("MonTimer Numero : {0}", t_Nbr); if (t_Nbr == 5) { mobile.SendMessage("MonTimer vient de finir!"); Stop(); } } } } |
| CODE |
string keywords = args.Speech; |
| CODE |
string keywords = args.Speech.ToLower(); |