Plugin mathtest

Plugin mathtest

Postby wendylorenzo » 21 May 2013, 21:44

Can some one make me a plugin that every 10 min there is a math question like "5/4/3" then the player who answers as first the correct answer gets 10 coins or something
wendylorenzo
 
Posts: 6
Joined: 26 Aug 2012, 23:11

Re: Plugin mathtest

Postby ismellike » 22 May 2013, 00:49

Ok here you go, it will create a text file when you load it up in your text folder called math.txt.
Add your answers and questions there and it will just pick a random one.
Format for adding questions/answers:

Question#Answer

The # is important to have, it is the indicator and seperator.

Code: Select all
using System;
using System.Collections.Generic;
using System.Threading;
using System.IO;

namespace MCDzienny
{
    public class CmdAnswer : Command
    {
        public List<int> done = new List<int>();
        public bool on = true;
        public bool answered = false;
        public int lines = 0;
        public string path = "text/math.txt";
        public int count = 74;
        public string question = "";
        public string answer = "";
        public override string name { get { return "answer"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "information"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Init()
        {
            if (!File.Exists(path))
            {
                File.WriteAllText(path, "No questions added yet!");
            }
            Thread lesslag = new Thread(new ThreadStart(delegate
                {
                    while (on)
                    {
                        Thread.Sleep(8000);
                        count += 1;
                        if (count == 75)
                        {
                            newquestion();
                            Player.GlobalMessage("%a[New Question] " + Server.DefaultColor + question);
                            answered = false;
                            count = 0;
                        }
                    }
                }));
            lesslag.Start();
        }
        public override void Use(Player p, string message)
        {
            if (message == "info")
            {
                Player.SendMessage(p, "%a[Question] " + Server.DefaultColor + question);
            }
            else if (answered==true)
            {
                Player.SendMessage(p, "Someone has already answered!");
            }
            else if (message == answer)
            {
                Player.SendMessage(p, "Nice! %c+10");
                Player.GlobalMessage(p.PublicName + " answered " + question);
                p.money += 10;
                answered = true;
            }
            else
            {
                Player.SendMessage(p, "Wrong");
            }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/answer [answer] -- answers the current question");
            Player.SendMessage(p, "/answer info -- gets the current question");
        }
        public void newquestion()
        {
            Random ran = new Random();
            foreach (string line in File.ReadAllLines(path))
            {
                lines += 1;
            }
            int which;
            int count = 0;
            do
            {
                which = ran.Next(1, lines);
                count += 1;
                if (count == lines)
                {
                    done.Clear();
                }
            }
            while (done.Contains(which));
            lines = 0;
            using (var sr = new StreamReader(path))
            {
                string line = sr.ReadLine();
                for (int x = 0; x <= which; ++x)
                {
                    sr.ReadLine();
                }
                try
                {
                    question = line.Split('#')[0];
                    answer = line.Split('#')[1];
                }
                catch
                {
                    Server.s.Log("text/math.txt file is corrupt at line "+which.ToString(), true);
                }
            }
        }
    }
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Plugin mathtest

Postby wendylorenzo » 22 May 2013, 12:02


ismellike wrote:Ok here you go, it will create a text file when you load it up in your text folder called math.txt.
Add your answers and questions there and it will just pick a random one.
Format for adding questions/answers:

Question#Answer

The # is important to have, it is the indicator and seperator.

Code: Select all
using System;
using System.Collections.Generic;
using System.Threading;
using System.IO;

namespace MCDzienny
{
    public class CmdAnswer : Command
    {
        public List<int> done = new List<int>();
        public bool on = true;
        public bool answered = false;
        public int lines = 0;
        public string path = "text/math.txt";
        public int count = 74;
        public string question = "";
        public string answer = "";
        public override string name { get { return "answer"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "information"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Init()
        {
            if (!File.Exists(path))
            {
                File.WriteAllText(path, "No questions added yet!");
            }
            Thread lesslag = new Thread(new ThreadStart(delegate
                {
                    while (on)
                    {
                        Thread.Sleep(8000);
                        count += 1;
                        if (count == 75)
                        {
                            newquestion();
                            Player.GlobalMessage("%a[New Question] " + Server.DefaultColor + question);
                            answered = false;
                            count = 0;
                        }
                    }
                }));
            lesslag.Start();
        }
        public override void Use(Player p, string message)
        {
            if (message == "info")
            {
                Player.SendMessage(p, "%a[Question] " + Server.DefaultColor + question);
            }
            else if (answered==true)
            {
                Player.SendMessage(p, "Someone has already answered!");
            }
            else if (message == answer)
            {
                Player.SendMessage(p, "Nice! %c+10");
                Player.GlobalMessage(p.PublicName + " answered " + question);
                p.money += 10;
                answered = true;
            }
            else
            {
                Player.SendMessage(p, "Wrong");
            }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/answer [answer] -- answers the current question");
            Player.SendMessage(p, "/answer info -- gets the current question");
        }
        public void newquestion()
        {
            Random ran = new Random();
            foreach (string line in File.ReadAllLines(path))
            {
                lines += 1;
            }
            int which;
            int count = 0;
            do
            {
                which = ran.Next(1, lines);
                count += 1;
                if (count == lines)
                {
                    done.Clear();
                }
            }
            while (done.Contains(which));
            lines = 0;
            using (var sr = new StreamReader(path))
            {
                string line = sr.ReadLine();
                for (int x = 0; x <= which; ++x)
                {
                    sr.ReadLine();
                }
                try
                {
                    question = line.Split('#')[0];
                    answer = line.Split('#')[1];
                }
                catch
                {
                    Server.s.Log("text/math.txt file is corrupt at line "+which.ToString(), true);
                }
            }
        }
    }
}

Thanks!!!!!! but is it possible to do this without /answer and just in the normal chat?
wendylorenzo
 
Posts: 6
Joined: 26 Aug 2012, 23:11

Re: Plugin mathtest

Postby wendylorenzo » 22 May 2013, 12:18

ismellike wrote:Ok here you go, it will create a text file when you load it up in your text folder called math.txt.
Add your answers and questions there and it will just pick a random one.
Format for adding questions/answers:

Question#Answer

The # is important to have, it is the indicator and seperator.

Code: Select all
using System;
using System.Collections.Generic;
using System.Threading;
using System.IO;

namespace MCDzienny
{
    public class CmdAnswer : Command
    {
        public List<int> done = new List<int>();
        public bool on = true;
        public bool answered = false;
        public int lines = 0;
        public string path = "text/math.txt";
        public int count = 74;
        public string question = "";
        public string answer = "";
        public override string name { get { return "answer"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "information"; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override void Init()
        {
            if (!File.Exists(path))
            {
                File.WriteAllText(path, "No questions added yet!");
            }
            Thread lesslag = new Thread(new ThreadStart(delegate
                {
                    while (on)
                    {
                        Thread.Sleep(8000);
                        count += 1;
                        if (count == 75)
                        {
                            newquestion();
                            Player.GlobalMessage("%a[New Question] " + Server.DefaultColor + question);
                            answered = false;
                            count = 0;
                        }
                    }
                }));
            lesslag.Start();
        }
        public override void Use(Player p, string message)
        {
            if (message == "info")
            {
                Player.SendMessage(p, "%a[Question] " + Server.DefaultColor + question);
            }
            else if (answered==true)
            {
                Player.SendMessage(p, "Someone has already answered!");
            }
            else if (message == answer)
            {
                Player.SendMessage(p, "Nice! %c+10");
                Player.GlobalMessage(p.PublicName + " answered " + question);
                p.money += 10;
                answered = true;
            }
            else
            {
                Player.SendMessage(p, "Wrong");
            }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/answer [answer] -- answers the current question");
            Player.SendMessage(p, "/answer info -- gets the current question");
        }
        public void newquestion()
        {
            Random ran = new Random();
            foreach (string line in File.ReadAllLines(path))
            {
                lines += 1;
            }
            int which;
            int count = 0;
            do
            {
                which = ran.Next(1, lines);
                count += 1;
                if (count == lines)
                {
                    done.Clear();
                }
            }
            while (done.Contains(which));
            lines = 0;
            using (var sr = new StreamReader(path))
            {
                string line = sr.ReadLine();
                for (int x = 0; x <= which; ++x)
                {
                    sr.ReadLine();
                }
                try
                {
                    question = line.Split('#')[0];
                    answer = line.Split('#')[1];
                }
                catch
                {
                    Server.s.Log("text/math.txt file is corrupt at line "+which.ToString(), true);
                }
            }
        }
    }
}

And when it is answered, it doenst say anything in the chat of ... answered? and also change the questions to 10 min untill there is another? thanks!
wendylorenzo
 
Posts: 6
Joined: 26 Aug 2012, 23:11


Return to Requests for Addon

Who is online

Users browsing this forum: No registered users and 6 guests

cron