Help with /Modreq.

For all mod-related questions and custom code.
Post Reply
BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Help with /Modreq.

Post 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

User avatar
Loading...
Offline
Posts: 41
Joined: December 21st, 2011, 5:57 pm

Re: Help with /Modreq.

Post by Loading... »

wow :o

VERY GOOD WORK !

i like iit

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post by BobKare »

Also added default for ranks via Config.cs:

owner: ReadModreq, SendModreq

op: ReadModreq, SendModreq

builder: SendModreq

guest: SendModreq

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Help with /Modreq.

Post 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;
                }
Last edited by Jonty800 on January 20th, 2012, 5:42 pm, edited 1 time in total.
You cannot use certain BBCodes: [img].

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post by BobKare »

All under Modreq in ChatCommands.cs, except the first one, put in Chat.cs?
btw it's Modreq, not ModReq.
Last edited by BobKare on January 20th, 2012, 5:27 pm, edited 1 time in total.

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Help with /Modreq.

Post 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?
Last edited by Jonty800 on January 20th, 2012, 5:55 pm, edited 3 times in total.
You cannot use certain BBCodes: [img].

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post 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

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Help with /Modreq.

Post 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
            }
Last edited by Jonty800 on January 20th, 2012, 5:43 pm, edited 2 times in total.
You cannot use certain BBCodes: [img].

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post by BobKare »

Thanks.

*testing...*

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post 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

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Help with /Modreq.

Post 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?
Last edited by Jonty800 on January 20th, 2012, 6:26 pm, edited 1 time in total.
You cannot use certain BBCodes: [img].

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post 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.

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: Help with /Modreq.

Post 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();
    ...

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post by BobKare »

Thanks for your help!
Now it all works fine.

Finished code might be posted later on!

User avatar
Sanjar Khan
Trustee
Offline
Posts: 1766
Joined: May 24th, 2011, 1:40 pm
Location: Leiden, Zuid Holland

Re: Help with /Modreq.

Post by Sanjar Khan »

I don't understand, isn't this just /staff?
Ferrisbuler2: i will stay but i might not post cus of ollieboy

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post 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

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post 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

BobKare
Offline
Posts: 279
Joined: May 26th, 2011, 2:15 pm

Re: Help with /Modreq.

Post by BobKare »

All bugs solved.
Thanks to Hellenion for help.

Post Reply