Question

Question

Postby Conor » 26 Jan 2013, 17:19

Hey Dzienny,

Do you have an event which is triggered when a round ends and rewards begin? I was hoping to make a lottery command, and this would be extremely helpful as I would know when to draw the lottery to a close. Otherwise my only idea is to make a timer which checks when all players have changed map, concluding that is the end of the round, but it isn't the true end of the round so it would be a bit of a fail.

Also, would you be able to do me a huge favor and list as many events which could be helpful when making custom commands as possible? Just from the top of your head.

Thanks.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Question

Postby dzienny » 07 Feb 2013, 23:20

These are some good questions. Actually, there is a public event that you can use for the lottery command, but its name will change in the upcoming release. So, I will give the event name and an example of use after releasing the new version. Also, I will add some more events soon.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Question

Postby Conor » 08 Feb 2013, 00:25

Awesome, thank you.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Question

Postby dzienny » 15 Feb 2013, 18:37

Here comes the example:

Code: Select all
using System;
using MCDzienny.InfectionSystem;

namespace MCDzienny
{
   public class CmdOnInfectionRoundEnds : Command
   {
      // Don't change the following statements.
      public override string name { get { return ""; } }
      public override string shortcut { get { return ""; } }
      public override string type { get { return ""; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

      // Init is executed once when the code is loaded.
      public override void Init()
      {
         // Hook up InectionRoundEnded(object, EventArgs) method
         // to the event that is triggered when the infection round ends.
         InfectionSystem.AnnounceWinners += InfectionRoundEnded;
      }

      private void InfectionRoundEnded(object sender, InfectionSystem.AnnounceWinnersEventArgs e)
      {
           // In this place write the code that is to be executed when the round ends.
      }

      // Don't change the following statements.
      public override void Help(Player p) { }
      public override void Use(Player p, string message) { }
   }
}


Also, the structure of AnnounceWinnersEventArgs:
Code: Select all
using System;
using System.Collections.Generic;

namespace MCDzienny.InfectionSystem
{
    public class AnnounceWinnersEventArgs : EventArgs
    {
        public List<Player> NotInfected { get; set; }
        public List<Player> Infected { get; set; }
        public Level CurrentInfectionLevel { get; set; }
    }
}


So, you can for example use e.CurrentInfectionLevel to send a message that will be only visible on the current infection level etc.
Code: Select all
Player.GlobalMessageLevel(e.CurrentInfectionLevel, "This message is only displayed on the current infection level.");


Alternatively you can use:
Code: Select all
using System;
using MCDzienny.InfectionSystem;

namespace MCDzienny
{
   public class CmdOnInfectionRoundEnds : Command
   {
      // Don't change the following statements.
      public override string name { get { return ""; } }
      public override string shortcut { get { return ""; } }
      public override string type { get { return ""; } }
      public override bool museumUsable { get { return false; } }
      public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

      // Init is executed once when the code is loaded.
      public override void Init()
      {
         // Hook up InectionRoundEnded(object, EventArgs) method
         // to the event that is triggered when the infection round ends.
         InfectionSystem.PayReward += InfectionRoundEnded;
      }

      private void InfectionRoundEnded(object sender, InfectionSystem.PayRewardEventArgs e)
      {
           // In this place write the code that is to be executed when the round ends.
      }

      // Don't change the following statements.
      public override void Help(Player p) { }
      public override void Use(Player p, string message) { }
   }
}


You can view PayRewardEventArgs member using Visual C# intelisense.
Also, it's possible to remove the default algorithms for paying the reward to winners and announcing the winners.
In order to remove default behaviour:
Code: Select all
InfectionSystem.PayReward -= InfectionSystem.PayRewardDefault;
InfectionSystem.AnnounceWinners -= InfectionSystem.AnnounceWinnersDefault;
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Question

Postby ismellike » 15 Feb 2013, 19:00

Could you give an example for an event on round start?
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Question

Postby dzienny » 16 Feb 2013, 17:52

ismellike wrote:Could you give an example for an event on round start?

Currently there's no such event. But I will add it soon.
Also, write the events that you may find useful, so I will start from adding these.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Question

Postby ismellike » 16 Feb 2013, 19:13

._> dzienny could you please explain how to add the class, my first time dealing with them.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Question

Postby dzienny » 16 Feb 2013, 19:27

ismellike wrote:._> dzienny could you please explain how to add the class, my first time dealing with them.


The examples are just a variation of a custom command. The procedure of adding them is the same as with the custom commands. So, inspite of the comment "don't change the following" you can implement Use and Help methods and set name, shortcut etc.

Other way round you can just add
Code: Select all
      // Init is executed once when the code is loaded.
      public override void Init()
      {
         // Hook up InectionRoundEnded(object, EventArgs) method
         // to the event that is triggered when the infection round ends.
         InfectionSystem.PayReward += InfectionRoundEnded;
      }

      private void InfectionRoundEnded(object sender, InfectionSystem.PayRewardEventArgs e)
      {
           // In this place write the code that is to be executed when the round ends.
      }

to your existing command.

If you need further explanation just ask.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Question

Postby ismellike » 16 Feb 2013, 23:04

Ok one last question, how do I call a command from the Object Sender?

Is it like Player.SendMessage(Sender,"hi");?
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Question

Postby dzienny » 16 Feb 2013, 23:24

ismellike wrote:Ok one last question, how do I call a command from the Object Sender?

Is it like Player.SendMessage(Sender,"hi");?


sender object is always null in those cases. You may wonder why it is even there if it is always null. Well, it's about the recommended convention of how to handle events in C#. Anyway, if you want to send a message to players you can for example:
1. Iterate over all players on the server with
Code: Select all
Player.players.ForEach(p =>
{
    Player.SendMessage(p, "Msg");
});

2. Iterate over the infected players: e.Infected.ForEach()
3. Iterate over the humans: e.NotInfected.ForEach()
and so on.
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Next

Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 3 guests

cron