It is currently January 21st, 2018, 10:13 am


All times are UTC




Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: Help with /Modreq.
PostPosted: January 20th, 2012, 4:34 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 4:52 pm 
User avatar

Joined: December 21st, 2011, 5:57 pm
Posts: 41
wow :o

VERY GOOD WORK !

i like iit

_________________
[url][soundcloud]<iframe width="580" height="170" frameborder="0" src="http://now.in/radio_player/myhubba?bg_color=%23FFC552"></iframe>[/soundcloud][/url]


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 5:03 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
Also added default for ranks via Config.cs:

owner: ReadModreq, SendModreq

op: ReadModreq, SendModreq

builder: SendModreq

guest: SendModreq


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 5:20 pm 

Joined: August 21st, 2011, 6:31 am
Posts: 280
Location: United Kingdom
List
Show
At the top of any page (probably chat.cs or chatcommands.cs
Code:
public static List<string> ModRequests = new List<string>();

in the command
Code:
Chat.SendModReq(player, message);
                ModRequests.Add(player.ClassyName + "&P: " + message);

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

put
Code:
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;
                }

_________________
You cannot use certain BBCodes: [img].


Last edited by Jonty800 on January 20th, 2012, 5:42 pm, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 5:26 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
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.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 5:27 pm 

Joined: August 21st, 2011, 6:31 am
Posts: 280
Location: United Kingdom
^Yeah but I used Staff Chat to make this.
If you put the list in chat.cs, make it
Code:
Chat.ModRequests.Add();

For the remove, maybe add something like this:
Show
Code:
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:
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?

_________________
You cannot use certain BBCodes: [img].


Last edited by Jonty800 on January 20th, 2012, 5:55 pm, edited 3 times in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 5:32 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 5:36 pm 

Joined: August 21st, 2011, 6:31 am
Posts: 280
Location: United Kingdom
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
Show
Code:
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
            }

_________________
You cannot use certain BBCodes: [img].


Last edited by Jonty800 on January 20th, 2012, 5:43 pm, edited 2 times in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 5:39 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
Thanks.

*testing...*


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 6:03 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 6:17 pm 

Joined: August 21st, 2011, 6:31 am
Posts: 280
Location: United Kingdom
Show
Code:
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?

_________________
You cannot use certain BBCodes: [img].


Last edited by Jonty800 on January 20th, 2012, 6:26 pm, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 6:19 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
Copied yours, then, at the bottom: Changed to:

Code:
        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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 7:42 pm 
fCraft Developer
User avatar

Joined: May 21st, 2011, 10:53 pm
Posts: 1386
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:
if( message.ToLower().StartsWith("remove ") ){
    string nameToRemove = message.Substring(7).Trim();
    ...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 20th, 2012, 10:37 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
Thanks for your help!
Now it all works fine.

Finished code might be posted later on!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 21st, 2012, 12:43 am 
Trustee
User avatar

Joined: May 24th, 2011, 1:40 pm
Posts: 1766
Location: Leiden, Zuid Holland
I don't understand, isn't this just /staff?

_________________
Ferrisbuler2: i will stay but i might not post cus of ollieboy


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 21st, 2012, 10:17 am 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 29th, 2012, 6:50 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Help with /Modreq.
PostPosted: January 29th, 2012, 7:59 pm 

Joined: May 26th, 2011, 2:15 pm
Posts: 279
All bugs solved.
Thanks to Hellenion for help.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net