Daily Bonus System

Daily Bonus System

Postby Leeizazombie » 01 Feb 2014, 23:10

Hey guys, I've decided to make a Daily bonus system that gives a player 30 coins for every day they join, this will not count as server joining, just days. I'm sure it's not the best way, I'm sure some coders could criticise like how it will make a lot of files in the folder /extra/dailybonus/ but I suggest it gets cleared regularly ;)

Code: Select all
using System;
using System.IO;

namespace MCDzienny
{
    public class CmdBlank : Command
    {
        public override string name { get { return "dailybonus"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "other"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Use(Player p, string message)
        {
            Player.SendMessage(p, "Info: Daily Bonus System is loaded.");
        }
        public override void Init()
        {
            if (!Directory.Exists("extra/dailybonus/"))
            {
                Directory.CreateDirectory("extra/dailybonus/");
            }
            Player.Joined += (object sender, PlayerEventArgs e) =>
            {
                string date = DateTime.Now.ToShortDateString().Replace('/', '_'); // Gets current date and removes the / because filenames can't use it.
                if (!File.Exists("extra/dailybonus/" + e.Player.name + "_" + date)) // Directory looks like -> extra/dailybonus/LeeIzaZombie+_01_02_2014
                {
                    File.Create("extra/dailybonus/" + e.Player.name + "_" + date);
                    Player.SendMessage(e.Player, Server.DefaultColor + "You've earned a daily bonus of %a 30 " + Server.DefaultColor + Server.moneys);
                    e.Player.money = e.Player.money + 30;
                }
            };
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "Gives a daily bonus to players for every day they join.");
        }
    }
}
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Daily Bonus System

Postby Conor » 02 Feb 2014, 02:01

As you said yourself it could become a little less messy by maybe using just one text file or something, but it's not a big deal, that can just be your future challenge. The good thing is that you have got it working and it's a great idea :)
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Daily Bonus System

Postby Leeizazombie » 02 Feb 2014, 19:01

Thanks! But I'm not great with text files, I'd love to learn, like I have a certain problem with my /autokick command
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Daily Bonus System

Postby joppiesaus » 04 Feb 2014, 19:43

Leeizazombie wrote:Thanks! But I'm not great with text files, I'd love to learn, like I have a certain problem with my /autokick command

StreamReader to read files. StreamWriter to write files. Ismellike has good examples of it in his commands.

For example(this is not full code of course, that's your business.):
Code: Select all
using (StreamWriter write = new StreamWriter(path))
{
   write.Write(stuffalreadyreaded);
   write.WriteLine(e.Player.name + " " + date);
}

// And here the code for getting stuff

string[] lines;
using (StreamReader read = new StreamReader(path))
{
   lines = read.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); // Split per newline
}

foreach (string s in lines)
{
   string[] words = s.Split(' ');
   if (s.Length < 2) continue;
   if (s[0] == e.Player.Name && s[1] == date) return;
}
e.Player.money += 30; // Give the player money


Of course, this file is not self-maintaining, it keeps growing and growing. But it's at least something.
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!

Re: Daily Bonus System

Postby _Retaliate_ » 17 Feb 2014, 15:25

I would recommend using Conor's PlayerExtra class to do this, it would make it much simpler and less space-consuming
Image
_Retaliate_
 
Posts: 68
Joined: 26 Sep 2013, 11:16

Re: Daily Bonus System

Postby Conor » 19 Feb 2014, 17:56

_Retaliate_ wrote:I would recommend using Conor's PlayerExtra class to do this, it would make it much simpler and less space-consuming


The variables associated with the players (and in the PlayerExtra class) are not permanent unlike data storage. This makes it unreliable for keeping track of time. But you are right that it would maybe save time for short term applications as oppose to data storage <ok>
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 8 guests

cron