You only need to add the following;
- Code: Select all
using System.IO;
Then you can use the 'File' class from this library, simply like;
- Code: Select all
File.WriteAllText("path", "content");
However, for your command - which reads from an online text file, you will not need this library anyway. The library you need is
System.Net. However, I used it directly in the code when I gave you that example, so you do not need to reference this library at the top.
So, I'll code it for you to look at
If you were to read from an online text file, you could do this.
- Code: Select all
using System;
namespace MCDzienny
{
public class CmdNews : Command
{
public override string name { get { return "news"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "information"; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public override void Use(Player p, string message)
{
string URL = "www.leestorage.99k.org/news.txt";
string content = new System.Net.WebClient().DownloadString(URL);
Player.SendMessage(p, "Current server news:");
Player.SendMessage(p, content);
}
public override void Help(Player p)
{
Player.SendMessage(p, "/news - View the server news");
}
}
}
More reliably, you probably want to just store your news in a text file on your PC. So, you could do the following.
- Code: Select all
using System;
using System.IO;
namespace MCDzienny
{
public class CmdNews : Command
{
public override string name { get { return "news"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "information"; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
private static string newsPath = "extra/news.txt";
public override void Init()
{
if (!File.Exists(newsPath))
{
File.WriteAllText(newsPath, "No news.");
}
}
public override void Use(Player p, string message)
{
string content = File.ReadAllText(newsPath);
Player.SendMessage(p, "Current server news:");
Player.SendMessage(p, content);
}
public override void Help(Player p)
{
Player.SendMessage(p, "/news - View the server news");
}
}
}
You can also display a better looking news feed. You can use the
File.ReadAllLines method and a foreach loop, to display lines specifically. I'll let you try and work this out yourself if you fancy a challenge