Help please(plz answer)

Help please(plz answer)

Postby djrico » 24 Aug 2013, 17:27

Hello,i want to add 2 commands to my server
Cmd's i want to know:
1./clan
2./upgrade
djrico
 
Posts: 7
Joined: 07 Aug 2013, 09:57

Re: Help please(plz answer)

Postby Conor » 24 Aug 2013, 19:09

/Clan - written by Ismellike:

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

namespace MCDzienny
{
    public class CmdClan : Command
    {
        public bool kick = false;
        List<Player> sure = new List<Player>();
        public override string name { get { return "clan"; } }
        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 CmdClan() { }
        public override void Init()
        {
            if (!Directory.Exists("clans"))
            {
                Directory.CreateDirectory("clans");
            }
            if (!File.Exists("clans/clanlist.txt"))
            {
                File.Create("clans/clanlist.txt");
            }
            if (!File.Exists("clans/playerinfo.txt"))
            {
                File.WriteAllText("clans/playerinfo.txt", "This is the info for the clans of each player; The format is player : clan name");
            }
            Player.Joined += new EventHandler<PlayerEventArgs>(Player_Joined);
        }
        public void Player_Joined(object sender, PlayerEventArgs e)
        {
            e.Player.ExtraData.Add("clan", "");
            try
            {
                if (e.Player.ExtraData["clan"] == "")
                {
                    string line;
                    using (var sr = new StreamReader("clans/playerinfo.txt"))
                    {
                        while (!(line = sr.ReadLine()).Contains(e.Player.name))
                        {
                            sr.ReadLine();
                        }
                    }
                    e.Player.ExtraData["clan"] = line.Split(':')[1];
                }
            }
            catch
            {
            }
        }
        public override void Use(Player p, string message)
        {
            string[] split = message.Trim().Split(' ');
            try
            {
                if (p.ExtraData["clan"] == "")
                {
                    string line;
                    using (var sr = new StreamReader("clans/playerinfo.txt"))
                    {
                        while (!(line = sr.ReadLine()).Contains(p.PublicName))
                        {
                            sr.ReadLine();
                        }
                    }
                    p.ExtraData["clan"] = line.Split(':')[1];
                }
            }
            catch
            {
            }
            switch (split[0])
            {
                case "info":
                    if (p.ExtraData["clan"] != "")
                    {
                        Player.SendMessage(p, "Your clan is " + p.ExtraData["clan"]);
                    }
                    else
                    {
                        Player.SendMessage(p, "You are not in a clan.");
                    }
                    return;
                case "join":
                    string which;
                    try
                    {
                        which = split[1];
                    }
                    catch
                    {
                        Player.SendMessage(p, "Please specify which clan you want to join.");
                        return;
                    }
                    if ((string)p.ExtraData["clan"] != "")
                    {
                        Player.SendMessage(p, "You are already in a clan!");
                    }
                    else if (!Directory.Exists("clans/" + split[1]))
                    {
                        Player.SendMessage(p, "The clan " + split[1] + " does not exist");
                    }
                    else if (p.money < 25)
                    {
                        Player.SendMessage(p, "You dont have enough money to join a clan.");
                    }
                    else
                    {
                        p.money -= 25;
                        Player.SendMessage(p, "-25");
                        File.AppendAllText("clans/playerinfo.txt", Environment.NewLine + p.PublicName + ":" + which);
                        Command.all.Find("settitle").Use(null, p.PublicName + " " + which);
                        Player.GlobalMessage(p.PublicName + " has joined the clan " + which + "!");
                    }
                    return;
                case "members":
                    string person;
                    try
                    {
                        string text;
                        using (var sr = new StreamReader("clans/clanlist.txt"))
                        {
                            text = sr.ReadToEnd();
                        }
                        if (text.Contains(message.Split(' ')[1]))
                        {
                            Player.SendMessage(p, "Members of " + p.ExtraData["clan"] + " %c---");
                            using (var sr = new StreamReader("clans/playerinfo.txt"))
                            {
                                while ((person = sr.ReadLine()) != null)
                                {
                                    if (person.Split(':')[1] == (string)p.ExtraData["clan"])
                                    {
                                        Player.SendMessage(p, person.Split(':')[0]);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Player.SendMessage(p, message.Split(' ')[1] + " is not a valid clan.");
                        }
                    }
                    catch
                    {
                        Player.SendMessage(p, "Members of " + p.ExtraData["clan"] + " %c---");
                        using (var sr = new StreamReader("clans/playerinfo.txt"))
                        {
                            while ((person = sr.ReadLine()) != null)
                            {
                                if (person.Split(':')[1] == (string)p.ExtraData["clan"])
                                {
                                    Player.SendMessage(p, person.Split(':')[0]);
                                }
                            }
                        }
                    }
                    Player.SendMessage(p, "%c-------");
                    return;
                case "list":
                    Player.SendMessage(p, "%a-------");
                    foreach (string line in File.ReadAllLines("clans/clanlist.txt"))
                    {
                        Player.SendMessage(p, line);
                    }
                    Player.SendMessage(p, "%a-------");
                    return;
                case "leave":
                    if ((string)p.ExtraData["clan"] == "")
                    {
                        Player.SendMessage(p, "You are not in a clan.");
                    }
                    else
                    {
                        if (kick == false)
                        {
                            Player.GlobalMessage(p.PublicName + " has just left the clan " + p.ExtraData["clan"] + "!");
                        }
                        else
                        {
                            Player.GlobalMessage(p.PublicName + " was kicked out of his clan.");
                            kick = false;
                        }
                        using (var sw = new StreamWriter("clans/temp.txt"))
                        {
                            foreach (string line in File.ReadAllLines("clans/playerinfo.txt"))
                            {
                                if (!line.Contains(p.PublicName))
                                {
                                    sw.WriteLine(line);
                                }
                            }
                        }
                        File.Delete("clans/playerinfo.txt");
                        File.Move("clans/temp.txt", "clans/playerinfo.txt");
                        Command.all.Find("settitle").Use(null, p.PublicName);
                        p.ExtraData["clan"] = "";
                    }
                    return;
                case "create":
                    string clan;
                    try
                    {
                        clan = split[1];
                    }
                    catch
                    {
                        Player.SendMessage(p, "Please specify the name of your clan.");
                        return;
                    }
                    if (Directory.Exists("clans/" + clan))
                    {
                        Player.SendMessage(p, clan + " is already a clan.");
                    }
                    else if ((string)p.ExtraData["clan"] != "")
                    {
                        Player.SendMessage(p, "You are currently in a clan, please leave it first.");
                    }
                    else if (p.money < 200)
                    {
                        Player.SendMessage(p, "You do not have enough money to make a clan.");
                    }
                    else
                    {
                        p.money -= 200;
                        Player.SendMessage(p, "-200");
                        Player.GlobalMessage("The clan " + clan + " has just been created!");
                        p.ExtraData["clan"] = clan;
                        Command.all.Find("settitle").Use(null, p.PublicName + " " + clan);
                        Directory.CreateDirectory("clans/" + clan);
                        File.WriteAllText("clans/" + clan + "/spawn.txt", "63 63 63");
                        File.AppendAllText("clans/playerinfo.txt", Environment.NewLine + p.PublicName + ":" + clan + ":owner");
                        File.AppendAllText("clans/clanlist.txt", Environment.NewLine + clan);
                    }
                    return;
                case "home":
                    if ((string)p.ExtraData["clan"] == "")
                    {
                        Player.SendMessage(p, "You are not even in a clan!");
                    }
                    else
                    {
                        string level = (string)p.ExtraData["clan"];
                        if (!File.Exists("levels/" + level + ".lvl"))
                        {

                            Command.all.Find("newlvl").Use(null, level + " 128 64 128 flat");
                            Level.Load(level, true);
                            Command.all.Find("goto").Use(p, level);
                            while (p.mapLoading) { }
                            for (int z = -1; z <= 1; ++z)
                                for (int y = -1; y <= 1; ++y)
                                    for (int x = -1; x <= 1; ++x)
                                    {
                                        p.level.Blockchange((ushort)(1 + x), (ushort)(2 + y), (ushort)(1 + z), Block.op_air, true, "");
                                    }
                            p.level.spawnx = 0; p.level.spawny = 1; p.level.spawnz = 0;
                            Group oldgroup = p.group;
                            p.group = Group.findPerm(LevelPermission.Admin);
                            Command.all.Find("replace").Use(p, "dirt adminium");
                            Command.all.Find("click").Use(p, "0 4 3");
                            Command.all.Find("click").Use(p, "3 0 0");
                            p.group = oldgroup;
                        }
                        else
                        {
                            if (Level.IsLevelLoaded(level) == false)
                            {
                                Level.Load(level, true);
                            }
                            if (p.level.name != level)
                            {
                                Command.all.Find("goto").Use(p, level);
                            }
                            while (p.mapLoading == true) { }
                            foreach (string line in File.ReadAllLines("clans/" + level + "/spawn.txt"))
                            {
                                Group pgroup = p.group;
                                p.group = Group.findPerm(LevelPermission.Admin);
                                Command.all.Find("move").Use(p, p.PublicName + " " + line);
                                p.group = pgroup;
                            }
                        }
                    }

                    return;
                case "spawn":
                    if (p.level.name == (string)p.ExtraData["clan"])
                    {
                        using (var sw = new StreamWriter("clans/" + p.level.name + "/spawn.txt"))
                        {
                            sw.WriteLine((p.pos[0] / 32) + " " + (p.pos[1] / 32 - 1) + " " + (p.pos[2] / 32));
                        }
                        Player.SendMessage(p, "Spawn changed.");
                    }
                    return;
                case "kick":
                    Player who = null;
                    try
                    {
                        who = Player.Find(split[1]);
                    }
                    catch
                    {
                        Player.SendMessage(p, "Please specify who to remove.");
                    }
                    if (who == null)
                    {
                        Player.SendMessage(p, split[1] + " is not online right now.");
                        return;
                    }
                    string realowner = "notch";
                    foreach (string line in File.ReadAllLines("clans/playerinfo.txt"))
                    {
                        if (line == p.PublicName + ":" + who.ExtraData["clan"] + ":owner")
                        {
                            realowner = p.PublicName;
                            break;
                        }
                    }
                    if (p.PublicName != realowner)
                    {
                        Player.SendMessage(p, "You are not the owner of the clan, " + (string)who.ExtraData["clan"]);
                    }
                    else
                    {
                        kick = true;
                        Command.all.Find("clan").Use(who, "leave");
                    }
                    return;
                case "chat":
                    Player.players.ForEach(pl =>
                    {
                        if (pl.ExtraData.ContainsKey("clan"))
                        {
                            if ((string)pl.ExtraData["clan"] == (string)p.ExtraData["clan"])
                            {
                                Player.SendMessage(pl, message.Replace("chat", "%0[%aClan%0] " + p.color + p.PublicName + ":%e"));
                            }
                        }
                    });
                    return;
                case "del":
                    string clanowner = "notch";
                    foreach (string line in File.ReadAllLines("clans/playerinfo.txt"))
                    {
                        if (line == p.PublicName + ":" + p.ExtraData["clan"] + ":owner")
                        {
                            clanowner = p.PublicName;
                            break;
                        }
                    }
                    if (clanowner == p.PublicName && !sure.Contains(p))
                    {
                        Player.SendMessage(p, "Are you absolutely sure you want to delete your clan?");
                        Player.SendMessage(p, "Do /m to proceed.");
                        sure.Add(p);
                    }
                    else if (clanowner == p.PublicName && sure.Contains(p))
                    {
                        Player.GlobalMessage(p.ExtraData["clan"] + " has been removed.");
                        using (var sr = new StreamReader("clans/clanlist.txt"))
                        using (var sw = new StreamWriter("clans/clanlist1.txt"))
                        {
                            string line;
                            while ((line = sr.ReadLine()) != null)
                            {
                                if (!line.Contains((string)p.ExtraData["clan"]))
                                {
                                    sw.WriteLine();
                                }
                            }
                        }
                        File.Delete("clans/clanlist.txt");
                        File.Move("clans/clanlist1.txt", "clans/clanlist.txt");
                        Directory.Delete("clans/" + p.ExtraData["clan"]);
                        p.ExtraData["clan"] = "";
                    }
                    else
                    {
                        Player.SendMessage(p, "You are not the owner of " + p.ExtraData["clan"]);
                    }
                    return;
            }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/clan home -- sends you to home sweet home");
            Player.SendMessage(p, "/clan spawn -- sets your clan home's spawn");
            Player.SendMessage(p, "/clan chat <message> -- chat to your clan");
            Player.SendMessage(p, "/clan list/info -- see clan info");
            Player.SendMessage(p, "/clan kick -- kick someone from your clan");
            Player.SendMessage(p, "/clan del -- delete your clan");
            Player.SendMessage(p, "/clan leave -- leave your clan");
            Player.SendMessage(p, "/clan join/leave -- leave/join a clan");
        }
    }
}


Can you explain what /upgrade is meant to do? I've never heard of it before..
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Help please(plz answer)

Postby HETAL » 24 Aug 2013, 19:57

YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: Help please(plz answer)

Postby djrico » 25 Aug 2013, 08:05



ty but i cant use it,theres errors,it shows like this:
Error #CS0246
Message: The type or namespace name 'Command' could not be found (are you missing a using directive or an assembly reference?)
Line: 4

-------------------------

Error #CS0246
Message: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)
Line: 6

-------------------------

Error #CS0246
Message: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)
Line: 7

-------------------------

Error #CS0246
Message: The type or namespace name 'LevelPermission' could not be found (are you missing a using directive or an assembly reference?)
Line: 52
djrico
 
Posts: 7
Joined: 07 Aug 2013, 09:57

Re: Help please(plz answer)

Postby djrico » 25 Aug 2013, 09:29

djrico wrote:


ty but i cant use it,theres errors,it shows like this:
Error #CS0246
Message: The type or namespace name 'Command' could not be found (are you missing a using directive or an assembly reference?)
Line: 4

-------------------------

Error #CS0246
Message: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)
Line: 6

-------------------------

Error #CS0246
Message: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)
Line: 7

-------------------------

Error #CS0246
Message: The type or namespace name 'LevelPermission' could not be found (are you missing a using directive or an assembly reference?)
Line: 52





and tha cmd i typed like this:



Code: Select all
namespace MCLawl
{
    using System;
    public class CmdUpgrade : Command
    {
        public override void Help(Player p) { Player.SendMessage(p, "/upgrade <password> - Upgrades your rank. If you have the correct password, of course."); }
        public override void Use(Player p, string message)
        {
            if (p != null)
            {
                Player from = Player.Find(p.name);
                Group group = Group.Find("builder");
                if (group.Permission <= p.group.Permission)
                {
                    Player.SendMessage(p, "You cannot upgrade yourself any higher");
                    return;
                }
                else
                {
                    string password = "A83L32";
                    if (message == password)
                    {
                        from.group.playerList.Remove(from.name);
                        from.group.playerList.Save();
                        group.playerList.Add(from.name);
                        group.playerList.Save();
                        Player.GlobalChat(from, string.Concat((string[])new string[] { from.color, from.name, Server.DefaultColor, " set his/her own rank to ", group.color, group.name, Server.DefaultColor, ". Isn't it amazing?" }), false);
                        from.group = group;
                        from.color = from.group.color;
                        Player.GlobalDie(from, false);
                        from.SendMessage(string.Concat((string[])new string[] { "You are now ranked ", group.color, group.name, Server.DefaultColor, ", type /help for your new set of commands." }));
                        Player.GlobalSpawn(from, from.pos[0], from.pos[1], from.pos[2], from.rot[0], from.rot[1], false, "");
                    }
                    else
                    {
                        if (message == "")
                        {
                            Player.SendMessage(p, "You must type a password");
                        }
                        else
                        {
                            Player.SendMessage(p, "Incorrect password.");
                        }
                    }
                }
            }
            else
            {
                Player.SendMessage(p, "The console is already awesome. You do not need to upgrade it.");
            }
        }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override bool museumUsable { get { return true; } }
        public override string name { get { return "upgrade"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "other"; } }
    }
}
djrico
 
Posts: 7
Joined: 07 Aug 2013, 09:57

Re: Help please(plz answer)

Postby joppiesaus » 25 Aug 2013, 14:13

djrico wrote:
djrico wrote:


ty but i cant use it,theres errors,it shows like this:
Error #CS0246
Message: The type or namespace name 'Command' could not be found (are you missing a using directive or an assembly reference?)
Line: 4

-------------------------

Error #CS0246
Message: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)
Line: 6

-------------------------

Error #CS0246
Message: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)
Line: 7

-------------------------

Error #CS0246
Message: The type or namespace name 'LevelPermission' could not be found (are you missing a using directive or an assembly reference?)
Line: 52





and tha cmd i typed like this:



Code: Select all
namespace MCLawl
{
    using System;
    public class CmdUpgrade : Command
    {
        public override void Help(Player p) { Player.SendMessage(p, "/upgrade <password> - Upgrades your rank. If you have the correct password, of course."); }
        public override void Use(Player p, string message)
        {
            if (p != null)
            {
                Player from = Player.Find(p.name);
                Group group = Group.Find("builder");
                if (group.Permission <= p.group.Permission)
                {
                    Player.SendMessage(p, "You cannot upgrade yourself any higher");
                    return;
                }
                else
                {
                    string password = "A83L32";
                    if (message == password)
                    {
                        from.group.playerList.Remove(from.name);
                        from.group.playerList.Save();
                        group.playerList.Add(from.name);
                        group.playerList.Save();
                        Player.GlobalChat(from, string.Concat((string[])new string[] { from.color, from.name, Server.DefaultColor, " set his/her own rank to ", group.color, group.name, Server.DefaultColor, ". Isn't it amazing?" }), false);
                        from.group = group;
                        from.color = from.group.color;
                        Player.GlobalDie(from, false);
                        from.SendMessage(string.Concat((string[])new string[] { "You are now ranked ", group.color, group.name, Server.DefaultColor, ", type /help for your new set of commands." }));
                        Player.GlobalSpawn(from, from.pos[0], from.pos[1], from.pos[2], from.rot[0], from.rot[1], false, "");
                    }
                    else
                    {
                        if (message == "")
                        {
                            Player.SendMessage(p, "You must type a password");
                        }
                        else
                        {
                            Player.SendMessage(p, "Incorrect password.");
                        }
                    }
                }
            }
            else
            {
                Player.SendMessage(p, "The console is already awesome. You do not need to upgrade it.");
            }
        }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public override bool museumUsable { get { return true; } }
        public override string name { get { return "upgrade"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "other"; } }
    }
}


This is from the MCLAWL source.
This wont work unless someone modifys it for MCDzienny.
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: Help please(plz answer)

Postby HETAL » 25 Aug 2013, 22:49

This came from my phone so it might not work but it has the general stuff
Code: Select all
   //Made by Hetal
    using System;
    namespace MCDzienny
    {
       public class CmdUpgrade : Command
       {
          public override string name { get { return "upgrade"; } }
          public override string shortcut { get { return "up"; } }
          public override string type { get { return "other"; } }
          public override bool museumUsable { get { return false; } }
          public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
          public override void Use(Player p, string message)
          {
                     if (message == "") { Help(p); return; }

             Player who = Player.Find(message.Split(' ')[0]);
                            if (who == null)
    {
       Player.SendMessage(p, "Player is not online.");
       return;
    }
            else if (message == "changethis")
          {
                  string advbuilderRank = Group.findPerm(LevelPermission.Advbuilder).name;
                    Command.all.Find("setrank").Use(p, who.PublicName + " " +advbuilderRank);
                    Player.GlobalMessage(who.color + who.name + Server.DefaultColor + " upgraded his rank!!!");
                    }
                 
                }             
    else
       Player.SendMessage(p, "Wrong password :P.");
       return;
          public override void Help(Player p)
          {
             Player.SendMessage(p, "/upgrade (password) - Upgrade your rank!.");
          }
       }
    }
YOU HAVENT SEEN THE LAST OF ME ISMELLIKE
HETAL
 
Posts: 397
Joined: 24 May 2013, 12:10

Re: Help please(plz answer)

Postby Conor » 26 Aug 2013, 13:51

The original should work, just change the namespace to MCDzienny.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron