public override void Initialize()
{
Commands.ChatCommands.Add(new Command("mycommand", Cmd, "cmd2"));
//Command()中第一个参数是权限名,第二个参数是回调函数,第三个参数是命令名
}
public override void Initialize()
{
Commands.ChatCommands.Add(new Command("mycommand", Cmd, "cmd2"));
}
private void Cmd(CommandArgs args)
{
args.Player.SendSuccessMessage("你使用了cmd2命令!");
}
public override void Initialize()
{
Commands.ChatCommands.Add(new Command(Cmd, "cmd1")); //不设置权限
Commands.ChatCommands.Add(new Command("mycommand", Cmd, "cmd2")); //设置一个权限
Commands.ChatCommands.Add(new Command(new List<string> { "mycommand","mycommand2" }, Cmd, "cmd3")); //设置多个权限
}
命令 | 权限 |
---|---|
/cmd1 | 无权限限制 |
/cmd2 | 玩家需要拥有mycommand权限 |
/cmd3 | 玩家需要拥有mycommand或者mycommand2权限 |
public override void Initialize()
{
Commands.ChatCommands.Add(new Command("cancanneed", Vme, "vme50", "v我50"));
}
private void Vme(CommandArgs args)
{
args.Player.GiveItem(74, 50, 0); //给玩家50个铂金币
}
public override void Initialize()
{
Commands.ChatCommands.Add(new Command(Vme, "giveme50", "送我50"));
Commands.ChatCommands.Add(new Command("cancanneed", Vme, "vme50", "V我50"));
Commands.ChatCommands.Add(new Command(new List<string> { "乞丐" , "beggar" } , Vme, "begme50", "乞讨50"));
}
public override void Initialize()
{
Commands.ChatCommands.Add(new Command(Vme, "giveme50", "送我50")
{ AllowServer = false,DoLog=true, HelpDesc = new string[]{ "帮助文档","这是第一行"}, HelpText= "帮助文本"});
}
//代码来自Cai的SSC管理器
private void CommandHandler(CommandArgs args)
{
if (args.Parameters.Count == 0)
{
args.Player.SendErrorMessage("无效的SSC管理器子命令!有效命令如下:\n" +
"ssc save [ID]--保存SSC\n" +
"ssc del [ID]--删除SSC\n" +
"ssc list --列出SSC\n" +
"ssc restore --复原SSC");
return;
}
int sscid = -1;
switch (args.Parameters[0].ToLower())
{
case "保存":
case "save":
if (args.Parameters.Count != 2 || !int.TryParse(args.Parameters[1], out sscid))
{
args.Player.SendErrorMessage("用法错误!正确用法:ssc save [ID]");
return;
}
if (SSCDB.InsertPlayerData(args.Player, sscid))
{
args.Player.SendSuccessMessage("保存成功!");
return;
}
args.Player.SendErrorMessage("保存失败!");
break;
case "删除":
case "del":
if (args.Parameters.Count != 2 || !int.TryParse(args.Parameters[1], out sscid))
{
args.Player.SendErrorMessage("用法错误!正确用法:ssc del [ID]");
return;
}
if (!SSCDB.GetPlayerData(sscid).exists)
{
args.Player.SendErrorMessage("你输入的SSC背包ID不存在!");
return;
}
if (SSCDB.DeletePlayerData(sscid))
{
args.Player.SendSuccessMessage("删除成功!");
return;
}
args.Player.SendErrorMessage("删除失败!");
break;
case "列出":
case "list":
args.Player.SendSuccessMessage("有效的SSC背包列表:" + string.Join(',', SSCDB.GetAllSSCId()));
break;
case "还原背包":
case "restore":
if (args.Parameters.Count != 2 || !int.TryParse(args.Parameters[1], out sscid))
{
args.Player.SendErrorMessage("用法错误!正确用法:ssc restore [ID]");
return;
}
if (!SSCDB.GetPlayerData(sscid).exists)
{
args.Player.SendErrorMessage("你输入的SSC背包ID不存在!");
return;
}
args.Player.PlayerData = SSCDB.GetPlayerData(sscid);
args.Player.PlayerData.RestoreCharacter(args.Player);
args.Player.Heal(args.Player.PlayerData.maxHealth);
args.Player.SendSuccessMessage("背包已还原!");
break;
default:
args.Player.SendErrorMessage("无效的SSC管理器子命令!有效命令如下:\n" +
"ssc save [ID]--保存SSC\n" +
"ssc del [ID]--删除SSC\n" +
"ssc list --列出SSC\n" +
"ssc restore --复原SSC");
break;
}
}
args.Player.SendData(PacketTypes.WorldInfo); //发送数据包,根据NetMessage发送数据包
args.Player.SendRawData(new byte[] { }); //发送原始数据,即手搓数据包
args.Player.SendErrorMessage("这是一个错误信息"); //发送错误信息(红色)
args.Player.SendInfoMessage("这是一个信息"); //发送信息(黄色)
args.Player.SendSuccessMessage("这是一个成功信息"); //发送成功信息(绿色)
args.Player.SendWarningMessage("这是一个警告信息"); //发送警告信息(橙色)
args.Player.Kick("这是一个踢出信息",true,true,"Cai",false);
//踢出玩家(踢出理由,强制踢出,不发送广播,踢出用户名,保存玩家的存档)
args.Player.Ban("这是一个封禁信息","Cai"); //封禁玩家(封禁理由,封禁用户名)
args.Player.SetTeam(1); //设置玩家队伍,无队伍0,红队1,绿队2,蓝队3,黄队4,粉队5
args.Player.SetBuff(1, 1); //添加玩家Buff (BuffID,Buff持续时间(单位1/60s))
args.Player.Teleport(1, 1); //传送玩家到坐标(X,Y)
args.Player.Disconnect("这是一个断开信息"); //断开玩家的连接(断开理由)(也算是踢出玩家的一种)
protected override void Dispose(bool disposing)
{
if (disposing)
{
//移除所有由本插件添加的所有指令
var asm = Assembly.GetExecutingAssembly();
Commands.ChatCommands.RemoveAll(c => c.CommandDelegate.Method?.DeclaringType?.Assembly == asm);
}
base.Dispose(disposing);
}