Help me out on report?

Help me out on report?

Postby ismellike » 08 Mar 2013, 01:01

I needed some help on the code below.

Is there any way to make the message.Split(' ')[1/2] optional?

http://pastie.org/6417158

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

namespace MCDzienny
{
    public class CmdReport : Command
    {
        public bool pending = false;
        public override string name { get { return "report"; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return "mod"; } }
        public override bool museumUsable { get { return true; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
        public CmdReport() { }

        public override void Use(Player p, string message)
        {
            string level = null;
            int x =0;
            int y=0;
            int z=0;
            string type = message.Split(' ')[0];
            Player noob = Player.Find(message.Split(' ')[1]);
            string reason = message.Split(' ')[2];
            if (reason == "check")
            {
                pending = false;
                Player.GlobalMessage(p.color + p.name + Server.DefaultColor + " has checked the crime scene out.");
            }

            else if (message.Split(' ').Length >= 3)
            {
 
                    if (!File.Exists("extra/report.txt"))
                    {
                        File.CreateText("extra/report.txt");
                    }
                    else
                    {
                        Player.GlobalMessage(p.color + p.name + Server.DefaultColor + " has reported " + noob.color + noob.name);
                        Player.GlobalMessage(Server.DefaultColor + "Reason: " + reason);
                        File.AppendAllText("extra/report.txt", Environment.NewLine + noob.name + " was reported by " + p.name + ". Reason: " + reason);
                        pending = true;
                        x = p.pos[0]/32;
                        y = p.pos[1]/32;
                        z = p.pos[2]/32;
                        level = p.level.name;
                    }
                    while (pending)
                    {
                        Player.players.ForEach(delegate(Player who)
                        {
                            if (who.group.Permission >= LevelPermission.Operator)
                            {
                                Player.SendMessage(who, "There is a report stationed at " + x.ToString() + " " + y.ToString() + " " + z.ToString() + ".");
                                Player.SendMessage(who, "It is in the map " + level + ".");

                            }
                        });
                        Thread.Sleep(5000);
                    }
                }
           
           
       

        }

        public override void Help(Player p)
        {
            Player.SendMessage(p, "/report [type] [name] [reason]");
            Player.SendMessage(p, "[type] can be check or make");
        }
    }
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Help me out on report?

Postby Conor » 08 Mar 2013, 01:07

Maybe this example can be at help?

Code: Select all
        public override void Use(Player p, string message)
        {
            if (String.IsNullOrEmpty(message))
            {
                Help(p);
            }
            else if (message.IndexOf(' ') == -1)
            {
                Player who = Player.Find(message);
                // No reason given.
            }
            else
            {
                Player who = Player.Find(message.Split(' ')[0]);
                string reason = message.Substring(message.IndexOf(' ') + 1);
            }
        }


I can help you more if you explain what you need better.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Help me out on report?

Postby ismellike » 08 Mar 2013, 01:25

Ive got everything layed out, I just cant get the Player noob to work because it says...

"Message: The name 'noob' does not exist in the current context"

who=noob
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Help me out on report?

Postby Conor » 08 Mar 2013, 01:28

ismellike wrote:Ive got everything layed out, I just cant get the Player noob to work because it says...

"Message: The name 'noob' does not exist in the current context"

who=noob


Well firstly make sure you check the player exists, which you forgot;

Code: Select all
if (noob != null && !noob.hidden)
{
   //code
}
else
{
   Player.SendMessage(p, "Player could not be found.");
}


Other than that its still unclear what you need help with, paste the actual error here. Also take note of the line, find it, and see how you can combat it.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Help me out on report?

Postby ismellike » 08 Mar 2013, 01:39

Oh actually it would have worked the first time lol, I just needed to extend the else all the way to the bottom of the use.

Also other question, How do make global integers?

kinda like the public bool.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: Help me out on report?

Postby Stuwie » 05 Jun 2013, 21:42

This command doesn't work for me?. It says ''an error occured when using this command!''
Image
User avatar
Stuwie
 
Posts: 78
Joined: 27 Nov 2011, 23:49

Re: Help me out on report?

Postby ismellike » 05 Jun 2013, 21:43

Check the finished product on your request for commands post.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 9 guests

cron