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);
}
}
}
}
}
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);
}
}
}
}
}
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);
}
}
}
}
}
Users browsing this forum: No registered users and 10 guests