Page 1 of 1

Help with /Modreq.

Posted: January 20th, 2012, 4:34 pm
by BobKare
I'm currently working on my first serious fCraft command.
As I've said several times before, I'm slowly learning to mod fCraft, and this is my first real project.

The command is now working like this:
  • A player with permission SendModreq does /Modreq [Message]
    All players with permission ReadModreq will get this message:
    (Modreq)BobKare: [Message]
Codes:

In ChatCommands.cs:
Show
In Permission.cs:
Show
In Chat.cs:
Show
I have copied a lot of fCraft "templates", and all is tested. Works fine.

To do:
  1. Add ability for players with permission ReadModreq: /Modreq list - Displays all written Modreqs with an ID sorted numerically
  2. Add ability for players with permission ReadModreq: /Modreq abort [ID] - To use when you've finished a Modreq/remove spam
I would really like some help for this, even I'm looking for a method for adding this.

Thank you,

-BobKare

Re: Help with /Modreq.

Posted: January 20th, 2012, 4:52 pm
by Loading...
wow :o

VERY GOOD WORK !

i like iit

Re: Help with /Modreq.

Posted: January 20th, 2012, 5:03 pm
by BobKare
Also added default for ranks via Config.cs:

owner: ReadModreq, SendModreq

op: ReadModreq, SendModreq

builder: SendModreq

guest: SendModreq

Re: Help with /Modreq.

Posted: January 20th, 2012, 5:20 pm
by Jonty800
List
At the top of any page (probably chat.cs or chatcommands.cs

Code: Select all

public static List<string> ModRequests = new List<string>();
in the command

Code: Select all

Chat.SendModReq(player, message);
                ModRequests.Add(player.ClassyName + "&P: " + message);
underneath

Code: Select all

if (player.Can(Permission.UseColorCodes) && message.Contains("%"))
                {
                    message = Color.ReplacePercentCodes(message);
                }
put

Code: Select all

if (message.ToLower() == "list")
                {
                    if (ModRequests.Count() > 0)
                    {
                        for (int i = 0; i < ModRequests.Count; i++)
                        {
                            player.Message("{0} &S- {1}", ModRequests[i], i.ToString());
                        }
                        return;
                    }
                 else
                    player.Message("&SThe ModRequest list is empty");
                 return;
                }

Re: Help with /Modreq.

Posted: January 20th, 2012, 5:26 pm
by BobKare
All under Modreq in ChatCommands.cs, except the first one, put in Chat.cs?
btw it's Modreq, not ModReq.

Re: Help with /Modreq.

Posted: January 20th, 2012, 5:27 pm
by Jonty800
^Yeah but I used Staff Chat to make this.
If you put the list in chat.cs, make it

Code: Select all

Chat.ModRequests.Add();
For the remove, maybe add something like this:

Code: Select all

if (message.ToLower() == "remove")
                {
                    string ID = cmd.Next();
                    if (ID != null) 
                    {
                        double Num; //number vs text checker
                        bool isNum = double.TryParse(ID, out Num);
                        if (isNum)
                        {
                            int ReqID = Convert.ToInt16(ID);
                             if(ModRequests[ReqID] != null){
                            ModRequests.RemoveAt(ReqID);
                             }
                            player.Message("&SModRequest {0} has been removed", ReqID.ToString());
                            return;
                        }
                        else
                            player.Message("&SYou need to enter a valid ID. /Modreq List");
                    }
                }
removeall / clear

Code: Select all

if (message.ToLower() == "clear")
                {
                   ModRequests.Clear();
                   player.Message("The ModRequest list was emptied");
                }
Note: You may have a problem if the list saves too many messages and you try to print them. Maybe add a if(ModRequests.Count() < 50) around the List Adder?

Re: Help with /Modreq.

Posted: January 20th, 2012, 5:32 pm
by BobKare
Alright now u're just confusing me :p

How should the command region look when this is finished?
Same with Chat.cs?

Thanks for helping, anyways <3

Re: Help with /Modreq.

Posted: January 20th, 2012, 5:36 pm
by Jonty800
Lol, I just deleted all my code :P.

Put the "public static List<string>" above the first "static readonly CommandDescriptor" on the page. Understand that?

The everything else should be put in the command, right under the part where it recognizes color codes and before the part where the message is actually sent.

Edit: A bit like this

Code: Select all

string message = cmd.NextAll().Trim();
            if (message.Length > 0)
            {
                if (player.Can(Permission.UseColorCodes) && message.Contains("%"))
                {
                    message = Color.ReplacePercentCodes(message);
                }
//commands start here
                if (message.ToLower() == "remove")
                {
                    string ID = cmd.Next();
                    if (ID != null) 
                    {
                        double Num; //number vs text checker
                        bool isNum = double.TryParse(ID, out Num);
                        if (isNum)
                        {
                            int ReqID = Convert.ToInt16(ID);
                            ModRequests.RemoveAt(ReqID);
                            player.Message("&SModRequest {0} has been removed", ReqID.ToString());
                            return;
                        }
                        else
                            player.Message("&SYou need to enter a valid ID. /Modreq List");
                            return;
                    }
                }
//and end before the message is sent
                Chat.SendAdmin(player, message);
                ModRequests.Add(player.ClassyName + "&P: " + message);
//and the list adder should be under the chat sender
            }

Re: Help with /Modreq.

Posted: January 20th, 2012, 5:39 pm
by BobKare
Thanks.

*testing...*

Re: Help with /Modreq.

Posted: January 20th, 2012, 6:03 pm
by BobKare
Tested, changed SendAdmin to SendModreq, tho...

Here is the result:

Code:
Show
/Modreq list does the following:

Creates a Modreq named: list
Shows the list of Modreqs (BobKare: list - 0)

/Modreq remove 0 does the following:

Prints two Modreqs, both named: remove 0

Screenshot:
Show

Re: Help with /Modreq.

Posted: January 20th, 2012, 6:17 pm
by Jonty800

Code: Select all

static void ModreqHandler(Player player, Command cmd)
        {
            if (player.Info.IsMuted)
            {
                player.MessageMuted();
                return;
            }

            if (player.DetectChatSpam()) return;

string message = cmd.NextAll().Trim();
            if (message.Length > 0)
            {
                if (player.Can(Permission.UseColorCodes) && message.Contains("%"))
                {
                    message = Color.ReplacePercentCodes(message);
                }

if (message.ToLower() == "remove")
                {
                    string ID = cmd.Next();
                    if (ID != null) 
                    {
                        double Num; //number vs text checker
                        bool isNum = double.TryParse(ID, out Num);
                        if (isNum)
                        {
                            int ReqID = Convert.ToInt16(ID);
                             if(ModRequests[ReqID] != null){
                            ModRequests.RemoveAt(ReqID);
                             }
                            player.Message("&SModRequest {0} has been removed", ReqID.ToString());
                            return;
                        }
                        else
                            player.Message("&SYou need to enter a valid ID. /Modreq List");
                    }
                }
                if (message.ToLower() == "clear")
                {
                   ModRequests.Clear();
                   player.Message("The ModRequest list was emptied");
                   return;
                }

                if (message.ToLower() == "list")
                {
                    if (ModRequests.Count() > 0)
                    {
                        for (int i = 0; i < ModRequests.Count; i++)
                        {
                            player.Message("{0} &S- {1}", ModRequests[i], i.ToString());
                        }
                        return;
                    }
                    else
                        player.Message("&SThe ModRequest list is empty");
                    return;
                }
                Chat.SendModreq(player, message);
                ModRequests.Add(player.ClassyName + "&P: " + message);
            }
        }
Everything works but remove because the command uses cmd.NextAll();. Thinking of a solution.

Maybe have it so remove just removes the last entry?

Re: Help with /Modreq.

Posted: January 20th, 2012, 6:19 pm
by BobKare
Copied yours, then, at the bottom: Changed to:

Code: Select all

        if (message != "list" | message != "remove" | message != "clear")
                {
                    Chat.SendModreq(player, message);
                }

                ModRequests.Add(player.ClassyName + "&P: " + message);
Now everything works, but remove.

EDIT: Added permission check (ReadModreq) for list, remove, clear!

Example:
Show
EDIT2: I get several errors on other cmds in ChatCommands.cs! Most like this:
Excepted class, delegate, enum, interface or struct.

Re: Help with /Modreq.

Posted: January 20th, 2012, 7:42 pm
by fragmer
Jonty800 wrote:Everything works but remove because the command uses cmd.NextAll();. Thinking of a solution.

Maybe have it so remove just removes the last entry?
You could use String.StartsWith() to see if message starts with "remove " (with a space), and parse the rest of the string manually. For example:

Code: Select all

if( message.ToLower().StartsWith("remove ") ){
    string nameToRemove = message.Substring(7).Trim();
    ...

Re: Help with /Modreq.

Posted: January 20th, 2012, 10:37 pm
by BobKare
Thanks for your help!
Now it all works fine.

Finished code might be posted later on!

Re: Help with /Modreq.

Posted: January 21st, 2012, 12:43 am
by Sanjar Khan
I don't understand, isn't this just /staff?

Re: Help with /Modreq.

Posted: January 21st, 2012, 10:17 am
by BobKare
Summary:

/Modreq [Message] - Displays a message to everyone which can ReadModreq
/Modreq list - Displays a list of Modreqs w/ID
/Modreq remove [ID] - Removes a Modreq from the list
/Modreq clear - Clears the list

Re: Help with /Modreq.

Posted: January 29th, 2012, 6:50 pm
by BobKare
This is now the code, got some more bugs:
Show
Problem:

When doing /Modreq done [ID] it spams an error saying the index is out of range, either it's an existing ID or an ID which is invalid (not existing).

Mark that when you use /Modreq done [Negative Value], for example /Modreq done -3 it works like it should work, saying that you need to enter a valid ID.

Thanks for helping <3

Re: Help with /Modreq.

Posted: January 29th, 2012, 7:59 pm
by BobKare
All bugs solved.
Thanks to Hellenion for help.