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
Code: Select all
#region Modreq
static readonly CommandDescriptor CdModreq = new CommandDescriptor
{
Name = "Modreq",
Aliases = new[] { "mod" },
Category = CommandCategory.Chat | CommandCategory.Moderation,
Permissions = new[] { Permission.SendModreq },
NotRepeatable = true,
IsConsoleSafe = false,
DisableLogging = true,
Usage = "/Modreq Request",
Help = "Call a Mod",
Handler = ModreqHandler
};
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);
}
Chat.SendModreq(player, message);
}
}
#endregion
In Permission.cs:
Show
Code: Select all
/// <summary> Ability to send a Modrequest </summary>
SendModreq,
/// <summary> Ability to read Modrequests </summary>
ReadModreq,
In Chat.cs:
Show
Code: Select all
/// <summary> Sends a Mod request (/Modreq). </summary>
/// <param name="player"> Player writing the message. </param>
/// <param name="rawMessage"> Message text. </param>
/// <returns> True if message was sent, false if it was cancelled by an event callback. </returns>
public static bool SendModreq([NotNull] Player player, [NotNull] string rawMessage)
{
if (player == null) throw new ArgumentNullException("player");
if (rawMessage == null) throw new ArgumentNullException("rawMessage");
var recepientList = Server.Players.Can(Permission.ReadModreq)
.NotIgnoring(player)
.Union(player);
string formattedMessage = String.Format("&P(Modreq){0}&P: {1}",
player.ClassyName,
rawMessage);
var e = new ChatSendingEventArgs(player,
rawMessage,
formattedMessage,
ChatMessageType.Staff,
recepientList);
if (!SendInternal(e)) return false;
Logger.Log(LogType.GlobalChat,
"(Modreq){0}: {1}", player.Name, rawMessage);
return true;
}
I have copied a lot of fCraft "templates", and all is tested. Works fine.
To do:
- Add ability for players with permission ReadModreq: /Modreq list - Displays all written Modreqs with an ID sorted numerically
- 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
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
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
.
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
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);
}
Chat.SendModreq(player, message);
ModRequests.Add(player.ClassyName + "&P: " + message);
if (player.Can(Permission.UseColorCodes) && message.Contains("%"))
{
message = Color.ReplacePercentCodes(message);
}
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;
}
//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.SendModreq(player, message);
ModRequests.Add(player.ClassyName + "&P: " + message);
//and the list adder should be under the chat sender
}
}
/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:
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
Code: Select all
if (message.ToLower() == "list")
{
if (player.Can(Permission.ReadModreq))
{
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;
}
else
player.Message("You are not allowed to read ModRequests!");
}
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
Code: Select all
public static List<string> ModRequests = new List<string>();
#region Modreq
static readonly CommandDescriptor CdModreq = new CommandDescriptor
{
Name = "Modreq",
Aliases = new[] { "mod" },
Category = CommandCategory.Chat | CommandCategory.Moderation,
NotRepeatable = true,
IsConsoleSafe = false,
DisableLogging = false,
Usage = "/Modreq [Request]",
Help = "Request help from a staff member",
Handler = ModreqHandler
};
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().StartsWith("done ") )
{
string ID = message.Substring(7).Trim();
if (ID != null)
{
if (player.Can(Permission.ReadModreq))
{
double Num; //number vs text checker
bool isNum = double.TryParse(ID, out Num);
if (isNum)
{
int ReqID = Convert.ToInt16(ID);
if (ReqID < ModRequests.Count && ReqID > 0 && ModRequests[ReqID] != null)
{
ModRequests.RemoveAt(ReqID);
Server.Message("&SModRequest &C{0}&S was done by {1}", ReqID.ToString(), player.ClassyName);
return;
}
else
{
player.Message("&SID not found! &H/ModReq list");
return;
}
}
else
{
player.Message("&SYou need to enter a valid ID. &H/Modreq List");
return;
}
}
else
{
player.Message("&SYou are not allowed to read ModRequests!");
return;
}
}
else
{
player.Message("&SYou need to enter an ID");
}
}
if (message.ToLower().StartsWith("clear"))
{
if (player.Can(Permission.ClearModreq))
{
ModRequests.Clear();
player.Message("The ModRequest list was emptied");
return;
}
else
{
player.Message("You are not allowed to clear the list of ModRequests!");
return;
}
}
if (message.ToLower().StartsWith("list"))
{
if (player.Can(Permission.ReadModreq))
{
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;
}
else
{
player.Message("You are not allowed to read ModRequests!");
return;
}
}
if (player.Can(Permission.SendModreq))
{
if (message != "list" | message != "remove" | message != "clear")
{
Chat.SendModreq(player, message);
}
ModRequests.Add(player.ClassyName + "&P: " + message);
}
else
{
player.Message("You are not allowed to send ModRequests!");
return;
}
}
}
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.