/// <summary> /// Gives specified item to the specified player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void Give(ISender sender, ArgumentList args) { // /give <stack> <item> [prefix] [player] var index = 0; int stack = args.GetInt(index++); string name = args.GetString(index++); // var max = Tools.AvailableItemSlots; //Perhaps remove a few incase of new drops // if (stack > max) // { // stack = max; // Set to Tools.AvailableItemSlots because number given was larger than this. // } int id; var results = Int32.TryParse(name, out id) ? DefinitionManager.FindItem(id) : DefinitionManager.FindItem(name); if (results != null && results.Length > 0) { if (results.Length > 1) throw new CommandError(String.Format("More than 1 item found, total is: {0}", results.Length)); var item = results[0]; string prefix; if (args.TryGetString(index, out prefix)) { try { Affix afx; if (Enum.TryParse(prefix, out afx)) { item.Prefix = (int)afx; index++; } } catch (ArgumentException) { throw new CommandError(String.Format("Error, the Prefix you entered was not found: {0}", args.GetString(3))); } } Player receiver; if (!args.TryGetOnlinePlayer(index, out receiver)) { if (sender is Player) receiver = sender as Player; else throw new CommandError("Expected an online player"); } receiver.GiveItem(item.Id, stack, item.MaxStack, sender, item.NetId, true, item.Prefix); } else throw new CommandError(String.Format("No item known by: {0}", name)); }
internal static void MaxPlayersCommand(ISender sender, ArgumentList args) { if (MaxPlayersDisabled) { sender.Message(255, "This command has been disabled."); return; } int maxp = -1; int overl = -1; if (args.TryGetInt(0, out maxp) && (maxp < 1 || maxp > MAX_SLOTS)) { sender.Message(255, "Max numbers of players must be in range 1 .. {0}", MAX_SLOTS); return; } if (args.Count > 1) { overl = args.GetInt(1); if (overl < 0 || overl > maxp) { sender.Message(255, "Number of overlimit slots must be in range 0 .. <max player count>"); return; } } int oldmax = maxSlots; int oldover = overlimitSlots; int result = maxSlots; if (maxp >= 0 || overl >= 0) { result = ChangeLimits(maxp < 0 ? maxSlots : maxp, overl < 0 ? overlimitSlots : overl); Tools.NotifyAllOps( String.Format("Max player slots changed to {0}+{1}. [{2}]", result, overlimitSlots, sender.SenderName) ); } sender.Message(255, Color.SteelBlue, "Max player slots: {0}, overlimit slots: {1}", result, overlimitSlots); if (oldmax != maxSlots || oldover != overlimitSlots) { Main.maxNetPlayers = maxSlots; //Program.properties.MaxPlayers = maxSlots; //Program.properties.OverlimitSlots = overlimitSlots; //Program.properties.Save (true); } }
public static void ListWarp(ISender sender, ArgumentList args) { if (WarpManager.WarpList.Count < 1) { throw new CommandError("There are no warps."); } int maxPages = WarpManager.WarpList.Count / 5; int page = args.GetInt(0); if (maxPages > 0 && page > maxPages - 1 || page < 1) { throw new CommandError("Pages: 1 => {0}", maxPages); } page *= 5; if (page >= WarpManager.WarpList.Count) { page = WarpManager.WarpList.Count; } int start = page - 5; if (page < 4) { start = 0; } for (int i = start; i < page; i++) { Warp warp = WarpManager.WarpList.ToArray()[i]; if (warp.IsUserAccessible(sender.Name) || !(sender is Player) || sender.Op) //!player's = OP ?? { sender.Message("Warp: {0}", warp.Name); } else { sender.Message("<PRIVATE>"); } } }
/// <summary> /// Gives specified item to the specified player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public static void Give(ISender sender, ArgumentList args) { // /give <player> <stack> <name> string _prefix; args.TryPopAny("-prefix", out _prefix); byte prefix; if (!Byte.TryParse(_prefix, out prefix)) { Affix affix; if (!AffixExtensions.Parse(_prefix ?? String.Empty, out affix, true)) prefix = 0; else prefix = (byte)affix; } Player receiver = args.GetOnlinePlayer(0); int stack = args.GetInt(1); string NameOrId = args.GetString(2); List<ItemInfo> itemlist; if (Server.TryFindItemByName(NameOrId, out itemlist) && itemlist.Count > 0) { if (itemlist.Count > 1) throw new CommandError(String.Format(Languages.MoreThanOneItemFoundNameId, itemlist.Count)); var item = itemlist[0]; var index = receiver.GiveItem(item.Type, stack, sender, item.NetID, true, prefix); if (item.NetID < 0) Main.item[index] = Item.netDefaults(item.NetID); Main.item[index].Prefix = prefix; } else { int Id = -1; try { Id = Int32.Parse(NameOrId); } catch { throw new CommandError(String.Format(Languages.MoreThanOneItemFoundNameId, itemlist.Count)); } if (Server.TryFindItemByType(Id, out itemlist) && itemlist.Count > 0) { if (itemlist.Count > 1) throw new CommandError(String.Format(Languages.MoreThanOneItemFoundType, itemlist.Count)); //receiver.GiveItem(itemlist[0].Type, stack, sender); var item = itemlist[0]; var index = receiver.GiveItem(item.Type, stack, sender, item.NetID, true, prefix); if (item.NetID < 0) Main.item[index] = Item.netDefaults(item.NetID); Main.item[index].Prefix = prefix; } else { throw new CommandError(String.Format(Languages.MoreThanOneItemFoundNameId, "no")); } } }
/// <summary> /// Gives specified item to the specified player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public static void Give(ISender sender, ArgumentList args) { // /give <player> <stack> <name> Player receiver = args.GetOnlinePlayer(0); int stack = args.GetInt(1); string NameOrId = args.GetString(2); List<Int32> itemlist; if (Server.TryFindItemByName(NameOrId, out itemlist) && itemlist.Count > 0) { if (itemlist.Count > 1) throw new CommandError("There were {0} Items found regarding the specified name", itemlist.Count); foreach (int id in itemlist) receiver.GiveItem(id, stack, sender); } else { int Id = -1; try { Id = Int32.Parse(NameOrId); } catch { throw new CommandError("There were {0} Items found regarding the specified Item Id/Name", itemlist.Count); } if (Server.TryFindItemByType(Id, out itemlist) && itemlist.Count > 0) { if (itemlist.Count > 1) throw new CommandError("There were {0} Items found regarding the specified Type Id", itemlist.Count); foreach (int id in itemlist) receiver.GiveItem(id, stack, sender); } else { throw new CommandError("There were no Items found regarding the specified Item Id/Name"); } } }
/// <summary> /// Summon a Boss /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void SummonBoss(ISender sender, ArgumentList args) { var bossName = args.GetString(0).ToLower(); var count = args.GetInt(1); Player target; if (!args.TryGetOnlinePlayer(2, out target)) { if (sender is Player) { target = sender as Player; } else throw new CommandError("Expected a player"); } var position = World.GetRandomClearTile(target.position.X / 16f, target.position.X / 16f); int type = -1, type1 = -1; string name = null; switch (bossName) { case "wyvern": type = 87; break; case "brain": case "brain of cthulhu": type = 266; break; case "crimson mimic": type = 474; break; case "corrupt mimic": type = 473; break; case "hallowed mimic": type = 475; break; case "duke fishron": case "duke": case "fishron": type = 370; break; case "everscream": type = 344; break; case "eye of cthulhu": type = 4; break; case "dutchman": case "flying dutchman": type = 491; break; case "golem": type = 245; break; case "gobin summoner": type = 471; break; case "king": case "king slime": type = 50; break; case "ice golem": type = 243; break; case "ice queen": type = 345; break; case "lunatic": case "cultist": case "lunatic cultist": type = 439; break; case "saucer": case "martian saucer": type = 395; break; case "moon": case "moon lord": type = 398; break; case "mothron": type = 477; break; case "wood": case "mourning wood": type = 325; break; case "paladin": type = 290; break; case "captain": case "pirate": case "pirate captain": type = 216; break; case "plantera": type = 262; break; case "pumpking": type = 327; break; case "queen": case "queen bee": type = 222; break; case "santa": case "santa nk1": case "santa-nk1": type = 346; break; case "skeletron": type = 35; break; case "prime": case "skeletron prime": type = 127; break; case "nebula": case "nebula pillar": type = 507; break; case "solar": case "solar pillar": type = 517; break; case "stardust": case "stardust pillar": type = 493; break; case "vortex": case "vortex pillar": type = 422; break; case "destroyer": case "the destroyer": type = 134; break; case "twins": case "the twins": type = 125; type1 = 126; break; case "eater": case "eater of worlds": type = 13; break; case "wall": case "flesh": case "wall of flesh": if (Main.wof > 0 && Main.npc[Main.wof].active) throw new CommandError("The Wall Of Flesh is already active"); if (target.position.Y / 16 < (float)(Main.maxTilesY - 205)) //As per NPC.SpawnWOF throw new CommandError("Player must be in The Underworld to spawn the Eater Of Worlds"); type = 113; break; default: throw new CommandError("Unknown boss: " + bossName); } while (count-- > 0) { var id = NPC.NewNPC((int)position.X, (int)position.Y, type); if (name != null) { Main.npc[id].SetDefaults(name); } if (type1 > 0) { id = NPC.NewNPC((int)position.X, (int)position.Y, type1); } if (count == 0) { var tms = String.Empty; if (count > 1) { tms = " " + count + " times"; } Tools.NotifyAllPlayers(Main.npc[id].name + " summoned by " + sender.SenderName + tms, Color.Purple, true); } } }
/// <summary> /// Spawns specified NPC type. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> /// <remarks>This function also allows NPC custom health.</remarks> public static void SpawnNPC(ISender sender, ArgumentList args) { if (Main.stopSpawns && !Program.properties.NPCSpawnsOverride) throw new CommandError("NPC Spawing is disabled."); var health = -1; var customHealth = args.TryPopAny<Int32>("-health", out health); Player player = sender as Player; int NPCAmount; if (args.Count > 3) throw new CommandError(Languages.TooManyArguments); else if (sender is ConsoleSender && args.Count <= 2) { if (!NetPlay.anyClients || !Server.TryGetFirstOnlinePlayer(out player)) throw new CommandError(Languages.NobodyOnline); } else if (args.Count == 3) player = args.GetOnlinePlayer(2); var npcName = args.GetString(1).ToLower().Trim(); // Get the class id of the npc int realNPCId = 0; NPC fclass = Registries.NPC.FindClass(npcName); if (fclass.Name != String.Empty) realNPCId = fclass.Type; else throw new CommandError(Languages.NPCDoesntExist); try { NPCAmount = args.GetInt(0); if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player) { (sender as Player).Kick(Languages.DontSpawnThatMany); return; } } catch { throw new CommandError(Languages.ExpectedSpawnInteger); } string realNPCName = String.Empty; for (int i = 0; i < NPCAmount; i++) { Vector2 location = World.GetRandomClearTile(((int)player.Position.X / 16), ((int)player.Position.Y / 16), 100, true, 100, 50); int npcIndex = NPC.NewNPC(((int)location.X * 16), ((int)location.Y * 16), fclass.Name, 0, Main.SpawnsOverride); if (customHealth) { Main.npcs[npcIndex].life = health; Main.npcs[npcIndex].lifeMax = health; } realNPCName = Main.npcs[npcIndex].Name; } Server.notifyOps("Spawned " + NPCAmount.ToString() + " of " + realNPCName + " [" + player.Name + "]", true); }
/// <summary> /// Gives specified item to the specified player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void Give(ISender sender, ArgumentList args) { // /give <stack> <item> [prefix] [player] var index = 0; int stack = args.GetInt(index++); string name = args.GetString(index++); // var max = Tools.AvailableItemSlots; //Perhaps remove a few incase of new drops // if (stack > max) // { // stack = max; // Set to Tools.AvailableItemSlots because number given was larger than this. // } int id; var results = Int32.TryParse(name, out id) ? DefinitionManager.FindItem(id) : DefinitionManager.FindItem(name); if (results != null && results.Length > 0) { if (results.Length > 1) { throw new CommandError(String.Format("More than 1 item found, total is: {0}", results.Length)); } var item = results[0]; string prefix; if (args.TryGetString(index, out prefix)) { try { Affix afx; if (Enum.TryParse(prefix, out afx)) { item.Prefix = (int)afx; index++; } } catch (ArgumentException) { throw new CommandError(String.Format("Error, the Prefix you entered was not found: {0}", args.GetString(3))); } } Player receiver; if (!args.TryGetOnlinePlayer(index, out receiver)) { if (sender is Player) { receiver = sender as Player; } else { throw new CommandError("Expected an online player"); } } receiver.GiveItem(item.Id, stack, item.MaxStack, item.NetId, item.Prefix); } else { throw new CommandError(String.Format("No item known by: {0}", name)); } }
/// <summary> /// Spawns specified NPC type. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> /// <remarks>This function also allows NPC custom health.</remarks> public void SpawnNPC(ISender sender, ArgumentList args) { //if (Main.stopSpawns && !Program.properties.NPCSpawnsOverride) // throw new CommandError("NPC Spawing is disabled."); //var health = -1; //var customHealth = args.TryPopAny<Int32>("-health", out health); Player player = sender as Player; int amount, offset = -1; if (args.Count > 5) throw new CommandError("Too many arguments"); else if (sender is ConsoleSender && args.Count <= 2) { if (!Netplay.anyClients || !Tools.TryGetFirstOnlinePlayer(out player)) throw new CommandError("No players online."); } else if (args.Count == 3) player = args.GetOnlinePlayer(2); else if (args.Count >= 4) { player = args.GetOnlinePlayer(2); args.TryPopAny<Int32>("-item", out offset); } var npcName = args.GetString(1).ToLower().Trim(); // Get the class id of the npc var npcs = DefinitionManager.FindNPC(npcName); if (npcs == null || npcs.Length == 0) { int npcId; if (Int32.TryParse(npcName, out npcId)) { npcs = DefinitionManager.FindNPC(npcId); if (npcs == null || npcs.Length == 0) { throw new CommandError("No npc exists by type {0}", npcId); } } else throw new CommandError("No npc exists {0}", npcName); } npcs = npcs.OrderBy(x => x.Name).ToArray(); if (npcs.Length > 1) { if (offset == -1) { sender.SendMessage("Npcs matching " + npcName + ':'); for (var x = 0; x < npcs.Length; x++) { if (sender is ConsoleSender) { sender.SendMessage($"\t{x}\t- {npcs[x].Name}"); } else { sender.SendMessage($"{x} - {npcs[x].Name}"); } } return; } } else offset = 0; var npc = npcs[offset]; if (npc.Boss.HasValue && npc.Boss == true) throw new CommandError("This NPC can only be summoned by the SPAWNBOSS command."); try { amount = args.GetInt(0); //if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player) //{ // (sender as Player).Kick("Don't spawn that many."); // return; //} } catch { throw new CommandError("Expected amount to spawn"); } var max = Tools.AvailableNPCSlots; //Perhaps remove a few incase of spawns if (amount > max) throw new CommandError("Cannot spawn that many, available slots: {0}", max); string realNPCName = String.Empty; for (int i = 0; i < amount; i++) { Vector2 location = World.GetRandomClearTile(((int)player.position.X / 16), ((int)player.position.Y / 16), 100, 100, 50); int npcIndex = NPC.NewNPC(((int)location.X * 16), ((int)location.Y * 16), npc.Id, 0); //if (customHealth) //{ // Main.npc[npcIndex].life = health; // Main.npc[npcIndex].lifeMax = health; //} Main.npc[npcIndex].netDefaults(npc.NetId); realNPCName = Main.npc[npcIndex].name; } Utils.NotifyAllOps("Spawned " + amount.ToString() + " of " + realNPCName + " [" + player.name + "]", true); }
/// <summary> /// Summon a Boss /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void SummonBoss(ISender sender, ArgumentList args) { var count = args.GetInt(0); var bossName = args.GetString(1).ToLower(); Player target; if (!args.TryGetOnlinePlayer(2, out target)) { if (sender is Player) { target = sender as Player; } else { target = Main.player.Where(x => x.active).Random(); if (null == target) { throw new CommandError("No players online"); } } } // int type = -1, type1 = -1; // string name = null; var queue = new Queue<Boss>(); switch (bossName) { case "wyvern": // type = 87; queue.Enqueue(new Boss() { type = 87 }); break; case "brain": case "brain of cthulhu": // type = 266; queue.Enqueue(new Boss() { type = 266 }); break; // case "crimson mimic": // type = 474; // break; case "corrupt mimic": // type = 473; queue.Enqueue(new Boss() { type = 473 }); break; // case "hallowed mimic": // type = 475; // break; case "duke fishron": case "duke": case "fishron": // type = 370; queue.Enqueue(new Boss() { type = 370 }); break; case "everscream": World.SetTime(16200.0, false); // type = 344; queue.Enqueue(new Boss() { type = 344 }); break; case "eye": case "cthulhu": case "eye of cthulhu": World.SetTime(16200.0, false); // type = 4; queue.Enqueue(new Boss() { type = 4 }); break; case "dutchman": case "flying dutchman": // type = 491; queue.Enqueue(new Boss() { type = 491 }); break; case "golem": // type = 245; queue.Enqueue(new Boss() { type = 245 }); break; case "goblin summoner": // type = 471; queue.Enqueue(new Boss() { type = 471 }); break; case "king": case "king slime": // type = 50; queue.Enqueue(new Boss() { type = 50 }); break; case "ice golem": // type = 243; queue.Enqueue(new Boss() { type = 243 }); break; case "ice queen": World.SetTime(16200.0, false); // type = 345; queue.Enqueue(new Boss() { type = 345 }); break; case "lunatic": case "cultist": case "lunatic cultist": // type = 439; queue.Enqueue(new Boss() { type = 439 }); break; case "saucer": case "martian saucer": // type = 395; queue.Enqueue(new Boss() { type = 395 }); break; case "moon": case "moon lord": // type = 398; queue.Enqueue(new Boss() { type = 398 }); break; case "mothron": if (!Main.eclipse) throw new CommandError("Mothron can only be spawned during a solar eclipse. See the worldevent command."); // type = 477; queue.Enqueue(new Boss() { type = 477 }); break; case "wood": case "mourning wood": World.SetTime(16200.0, false); // type = 325; queue.Enqueue(new Boss() { type = 325 }); break; case "paladin": // type = 290; queue.Enqueue(new Boss() { type = 290 }); break; case "captain": case "pirate": case "pirate captain": World.SetTime(16200.0, false); // type = 216; queue.Enqueue(new Boss() { type = 216 }); break; case "plantera": // type = 262; queue.Enqueue(new Boss() { type = 262 }); break; case "pumpking": World.SetTime(16200.0, false); // type = 327; queue.Enqueue(new Boss() { type = 327 }); break; case "queen": case "queen bee": // type = 222; queue.Enqueue(new Boss() { type = 222 }); break; case "santa": case "santa nk1": case "santa-nk1": World.SetTime(16200.0, false); // type = 346; queue.Enqueue(new Boss() { type = 346 }); break; case "skeletron": World.SetTime(16200.0, false); // type = 35; queue.Enqueue(new Boss() { type = 35 }); break; case "prime": case "skeletron prime": // type = 127; queue.Enqueue(new Boss() { type = 127 }); break; case "nebula": case "nebula pillar": // type = 507; queue.Enqueue(new Boss() { type = 507 }); break; case "solar": case "solar pillar": // type = 517; queue.Enqueue(new Boss() { type = 517 }); break; case "stardust": case "stardust pillar": // type = 493; queue.Enqueue(new Boss() { type = 493 }); break; case "vortex": case "vortex pillar": // type = 422; queue.Enqueue(new Boss() { type = 422 }); break; case "destroyer": case "the destroyer": World.SetTime(16200.0, false); // type = 134; queue.Enqueue(new Boss() { type = 134 }); break; case "twins": case "the twins": World.SetTime(16200.0, false); // type = 125; // type1 = 126; queue.Enqueue(new Boss() { type = 125, name = "The Twins" }); queue.Enqueue(new Boss() { type = 126, ignore = true }); break; case "eater": case "eater of worlds": // type = 13; queue.Enqueue(new Boss() { type = 13 }); break; case "wall": case "flesh": case "wall of flesh": if (Main.wof > 0 && Main.npc[Main.wof].active) throw new CommandError("The Wall Of Flesh is already active"); if (target.position.Y / 16 < (float)(Main.maxTilesY - 205)) //As per NPC.SpawnWOF throw new CommandError("Player must be in The Underworld to spawn the Eater Of Worlds"); // type = 113; queue.Enqueue(new Boss() { type = 113 }); break; case "deathcradle": count = 1; var items = new int[] { 87, 266, 473, 370, 344, 4, 491, 245, 471, 50, 243, 345, 439, 395, 398, 477, 325, 290, 216, 262, 327, 222, 346, 35, 127, 507, 517, 493, 422, 134, 125, 126, 13 }; World.SetTime(16200.0, false); foreach (var item in items) { queue.Enqueue(new Boss() { type = item, ignore = true }); } Core._likeABoss = true; Tools.NotifyAllPlayers("Easter egg found: Like a boss mini game!", Color.Purple, true); break; default: throw new CommandError("Unknown boss: " + bossName); } while (count-- > 0) { while (queue.Count > 0) { var boss = queue.Dequeue(); var position = World.GetRandomClearTile(target.position.X / 16f, target.position.Y / 16f); var id = NPC.NewNPC((int)(position.X * 16f), (int)(position.Y * 16f), boss.type); Main.npc[id].SetDefaults(boss.type); Main.npc[id].SetDefaults(Main.npc[id].name); if (count == 0 && !boss.ignore) { var tms = String.Empty; if (count > 1) tms = " " + count + " times"; Tools.NotifyAllPlayers((boss.name ?? Main.npc[id].name) + " [" + boss.type + "]" + " summoned by " + sender.SenderName + tms, Color.Purple, true); } } } }
/// <summary> /// Gives specified item to the specified player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void Give(ISender sender, ArgumentList args) { // /give <player> <stack> <name> Player receiver = args.GetOnlinePlayer(0); int stack = args.GetInt(1); string name = args.GetString(2); var max = Tools.AvailableItemSlots; //Perhaps remove a few incase of new drops if (stack > max) { stack = max; // Set to Tools.AvailableItemSlots because number given was larger than this. } var results = DefinitionManager.FindItem(name); if (results != null && results.Length > 0) { if (results.Length > 1) throw new CommandError(String.Format("More than 1 item found, total is: {0}", results.Length)); var item = results[0]; var index = receiver.GiveItem(item.Id, stack, sender, item.NetId, true, item.Prefix); if (item.NetId < 0) Main.item[index].netDefaults(item.NetId); Main.item[index].Prefix(item.Prefix); } else throw new CommandError(String.Format("No item known by: {0}", name)); }
/// <summary> /// Allows on the fly variable modifications /// </summary> /// <param name="sender">Sender.</param> /// <param name="args">Arguments.</param> public void VariableMan(ISender sender, ArgumentList args) { // var <exec|field> // var field <namespace.type> <fieldname> // var field <namespace.type> <fieldname> <valuetobeset> // var exec <namespace.type> <methodname> //No arguments supported yet var cmd = args.GetString(0); if (cmd == "field" || cmd == "arr") { var type = args.GetString(1); var mem = args.GetString(2); //Find the type var at = Type.GetType(type); if (at == null) { at = System.Reflection.Assembly.GetEntryAssembly().GetType(type); } if (at == null) { at = System.Reflection.Assembly.GetCallingAssembly().GetType(type); } if (at == null) { at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type); } if (at == null) { at = typeof(Terraria.Main).Assembly.GetType(type); } if (at == null) { throw new CommandError("Invalid type: " + type); } //Find the field var am = at.GetField(mem); if (am == null) { throw new CommandError("Invalid field: " + mem); } string val = null; if (cmd != "arr" && args.TryGetString(3, out val)) { object data = GetDataValue(am.FieldType, val); am.SetValue(null, data); var v = am.GetValue(null); if (v != null) { val = v.ToString(); } else { val = "null"; } sender.Message("Value is now: " + val); } else { var v = am.GetValue(null); if (v != null) { if (v.GetType().IsArray) { var index = args.GetInt(3); var obj = (v as Array).GetValue(index); if (obj is Terraria.RemoteClient) { val = ""; var rc = obj as Terraria.RemoteClient; val += $"Id: {rc.Id}\n"; val += $"IsActive: {rc.IsActive}\n"; val += $"IsAnnouncementCompleted: {rc.IsAnnouncementCompleted}\n"; val += $"IsConnected(): {rc.IsConnected()}\n"; val += $"IsReading: {rc.IsReading}\n"; val += $"Name: {rc.Name}\n"; val += $"PendingTermination: {rc.PendingTermination}\n"; val += $"SpamAddBlock: {rc.SpamAddBlock}\n"; val += $"SpamAddBlockMax: {rc.SpamAddBlockMax}\n"; val += $"SpamDeleteBlock: {rc.SpamDeleteBlock}\n"; val += $"SpamDeleteBlockMax: {rc.SpamDeleteBlockMax}\n"; val += $"SpamProjectile: {rc.SpamProjectile}\n"; val += $"SpamProjectileMax: {rc.SpamProjectileMax}\n"; val += $"SpamWater: {rc.SpamWater}\n"; val += $"SpamWaterMax: {rc.SpamWaterMax}\n"; val += $"State: {rc.State}\n"; val += $"StatusCount: {rc.StatusCount}\n"; val += $"StatusMax: {rc.StatusMax}\n"; val += $"StatusText: {rc.StatusText}\n"; val += $"StatusText2: {rc.StatusText2}\n"; val += $"TimeOutTimer: {rc.TimeOutTimer}\n"; #if CUSTOM_SOCKETS if (rc.Socket is OTA.Sockets.ClientConnection) { val += "\n=======================\nClientConnection\n"; var cc = rc.Socket as OTA.Sockets.ClientConnection; val += $"Active: {cc.Active}\n"; val += $"BytesReceived: {cc.BytesReceived}\n"; val += $"BytesSent: {cc.BytesSent}\n"; val += $"IsOTAClient: {cc.IsOTAClient}\n"; val += $"QueueLength: {cc.QueueLength}\n"; val += $"QueueSize: {cc.QueueSize}\n"; //val += $"RemoteAddress: {cc.RemoteAddress}\n"; val += $"SlotId: {cc.SlotId}\n"; } #endif } else { val = obj.ToString(); } } else { val = v.ToString(); } } else { val = "null"; } sender.Message("Value: " + val); } } else if (cmd == "prop") { var type = args.GetString(1); var prop = args.GetString(2); //Find the type var at = Type.GetType(type); if (at == null) { at = System.Reflection.Assembly.GetEntryAssembly().GetType(type); } if (at == null) { at = System.Reflection.Assembly.GetCallingAssembly().GetType(type); } if (at == null) { at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type); } if (at == null) { throw new CommandError("Invalid type: " + type); } //Find the field var am = at.GetProperty(prop); if (am == null) { throw new CommandError("Invalid property: " + prop); } string val = null; if (args.TryGetString(3, out val)) { object data = GetDataValue(am.PropertyType, val); am.SetValue(null, data, null); var v = am.GetValue(null, null); if (v != null) { val = v.ToString(); } else { val = "null"; } sender.Message("Value is now: " + val); } else { var v = am.GetValue(null, null); if (v != null) { val = v.ToString(); } else { val = "null"; } sender.Message("Value: " + val); } } else if (cmd == "exec") { var type = args.GetString(1); var mthd = args.GetString(2); //Find the type var at = Type.GetType(type); if (at == null) { at = System.Reflection.Assembly.GetEntryAssembly().GetType(type); } if (at == null) { at = System.Reflection.Assembly.GetCallingAssembly().GetType(type); } if (at == null) { at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type); } if (at == null) { throw new CommandError("Invalid type: " + type); } //Find the field var am = at.GetMethod(mthd); if (am == null) { throw new CommandError("Invalid method: " + mthd); } var prms = am.GetParameters(); if (prms.Length == 0) { var res = am.Invoke(null, null); var result = res == null ? "null" : res.ToString(); sender.Message("Result: " + result); } else { sender.Message("Arguments are not yet supported for exec"); } } else { sender.Message("Unsupported var command: " + cmd); } }
/// <summary> /// Spawns specified NPC type. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> /// <remarks>This function also allows NPC custom health.</remarks> public void SpawnNPC(ISender sender, ArgumentList args) { //if (Main.stopSpawns && !Program.properties.NPCSpawnsOverride) // throw new CommandError("NPC Spawing is disabled."); //var health = -1; //var customHealth = args.TryPopAny<Int32>("-health", out health); Player player = sender as Player; int amount; if (args.Count > 4) throw new CommandError("Too many arguments"); else if (sender is ConsoleSender && args.Count <= 2) { if (!Netplay.anyClients || !Tools.TryGetFirstOnlinePlayer(out player)) throw new CommandError("No players online."); } else if (args.Count >= 3) player = args.GetOnlinePlayer(2); var npcName = args.GetString(1).ToLower().Trim(); // Get the class id of the npc var npcs = DefinitionManager.FindNPC(npcName); if (npcs.Length == 0) throw new CommandError("No npc exists by the name {0}", npcName); else if (npcs.Length > 1) { bool first; args.TryGetBool(3, out first); if (!first) throw new CommandError("Too many results for {0}, total count {1}", npcName, npcs.Length); } var npc = npcs[0]; if (npc.Boss.HasValue && npc.Boss == true) throw new CommandError("This NPC can only be summoned by the SPAWNBOSS command."); try { amount = args.GetInt(0); //if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player) //{ // (sender as Player).Kick("Don't spawn that many."); // return; //} } catch { throw new CommandError("Expected amount to spawn"); } var max = Tools.AvailableNPCSlots; //Perhaps remove a few incase of spawns if (amount > max) throw new CommandError("Cannot spawn that many, available slots: {0}", max); string realNPCName = String.Empty; for (int i = 0; i < amount; i++) { Vector2 location = World.GetRandomClearTile(((int)player.position.X / 16), ((int)player.position.Y / 16), 100, 100, 50); int npcIndex = NPC.NewNPC(((int)location.X * 16), ((int)location.Y * 16), npc.Id, 0); //if (customHealth) //{ // Main.npc[npcIndex].life = health; // Main.npc[npcIndex].lifeMax = health; //} Main.npc[npcIndex].netDefaults(npc.NetId); realNPCName = Main.npc[npcIndex].name; } Tools.NotifyAllOps("Spawned " + amount.ToString() + " of " + realNPCName + " [" + player.name + "]", true); }
/// <summary> /// Spawns specified NPC type. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> /// <remarks>This function also allows NPC custom health.</remarks> public void SpawnNPC(ISender sender, ArgumentList args) { //if (Main.stopSpawns && !Program.properties.NPCSpawnsOverride) // throw new CommandError("NPC Spawing is disabled."); //var health = -1; //var customHealth = args.TryPopAny<Int32>("-health", out health); Player player = sender as Player; int amount, offset = -1; if (args.Count > 5) { throw new CommandError("Too many arguments"); } else if (sender is ConsoleSender && args.Count <= 2) { if (!Netplay.anyClients || !Tools.TryGetFirstOnlinePlayer(out player)) { throw new CommandError("No players online."); } } else if (args.Count == 3) { player = args.GetOnlinePlayer(2); } else if (args.Count >= 4) { player = args.GetOnlinePlayer(2); args.TryPopAny <Int32>("-item", out offset); } var npcName = args.GetString(1).ToLower().Trim(); // Get the class id of the npc var npcs = DefinitionManager.FindNPC(npcName); if (npcs == null || npcs.Length == 0) { int npcId; if (Int32.TryParse(npcName, out npcId)) { npcs = DefinitionManager.FindNPC(npcId); if (npcs == null || npcs.Length == 0) { throw new CommandError("No npc exists by type {0}", npcId); } } else { throw new CommandError("No npc exists {0}", npcName); } } npcs = npcs.OrderBy(x => x.Name).ToArray(); if (npcs.Length > 1) { if (offset == -1) { sender.SendMessage("Npcs matching " + npcName + ':'); for (var x = 0; x < npcs.Length; x++) { if (sender is ConsoleSender) { sender.SendMessage($"\t{x}\t- {npcs[x].Name}"); } else { sender.SendMessage($"{x} - {npcs[x].Name}"); } } return; } } else { offset = 0; } var npc = npcs[offset]; if (npc.Boss.HasValue && npc.Boss == true) { throw new CommandError("This NPC can only be summoned by the SPAWNBOSS command."); } try { amount = args.GetInt(0); //if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player) //{ // (sender as Player).Kick("Don't spawn that many."); // return; //} } catch { throw new CommandError("Expected amount to spawn"); } var max = Tools.AvailableNPCSlots; //Perhaps remove a few incase of spawns if (amount > max) { throw new CommandError("Cannot spawn that many, available slots: {0}", max); } string realNPCName = String.Empty; for (int i = 0; i < amount; i++) { Vector2 location = World.GetRandomClearTile(((int)player.position.X / 16), ((int)player.position.Y / 16), 100, 100, 50); int npcIndex = NPC.NewNPC(((int)location.X * 16), ((int)location.Y * 16), npc.Id, 0); //if (customHealth) //{ // Main.npc[npcIndex].life = health; // Main.npc[npcIndex].lifeMax = health; //} Main.npc[npcIndex].netDefaults(npc.NetId); realNPCName = Main.npc[npcIndex].name; } Utils.NotifyAllOps("Spawned " + amount.ToString() + " of " + realNPCName + " [" + player.name + "]", true); }
/// <summary> /// Summon a Boss /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void SummonBoss(ISender sender, ArgumentList args) { var count = args.GetInt(0); var bossName = args.GetString(1).ToLower(); Player target; if (!args.TryGetOnlinePlayer(2, out target)) { if (sender is Player) { target = sender as Player; } else { target = Main.player.Where(x => x.active).Random(); if (null == target) { throw new CommandError("No players online"); } } } // int type = -1, type1 = -1; // string name = null; var queue = new Queue <Boss>(); switch (bossName) { case "wyvern": // type = 87; queue.Enqueue(new Boss() { type = 87 }); break; case "brain": case "brain of cthulhu": // type = 266; queue.Enqueue(new Boss() { type = 266 }); break; // case "crimson mimic": // type = 474; // break; case "corrupt mimic": // type = 473; queue.Enqueue(new Boss() { type = 473 }); break; // case "hallowed mimic": // type = 475; // break; case "duke fishron": case "duke": case "fishron": // type = 370; queue.Enqueue(new Boss() { type = 370 }); break; case "everscream": World.SetTime(16200.0, false); // type = 344; queue.Enqueue(new Boss() { type = 344 }); break; case "eye": case "cthulhu": case "eye of cthulhu": World.SetTime(16200.0, false); // type = 4; queue.Enqueue(new Boss() { type = 4 }); break; case "dutchman": case "flying dutchman": // type = 491; queue.Enqueue(new Boss() { type = 491 }); break; case "golem": // type = 245; queue.Enqueue(new Boss() { type = 245 }); break; case "goblin summoner": // type = 471; queue.Enqueue(new Boss() { type = 471 }); break; case "king": case "king slime": // type = 50; queue.Enqueue(new Boss() { type = 50 }); break; case "ice golem": // type = 243; queue.Enqueue(new Boss() { type = 243 }); break; case "ice queen": World.SetTime(16200.0, false); // type = 345; queue.Enqueue(new Boss() { type = 345 }); break; case "lunatic": case "cultist": case "lunatic cultist": // type = 439; queue.Enqueue(new Boss() { type = 439 }); break; case "saucer": case "martian saucer": // type = 395; queue.Enqueue(new Boss() { type = 395 }); break; case "moon": case "moon lord": // type = 398; queue.Enqueue(new Boss() { type = 398 }); break; case "mothron": if (!Main.eclipse) { throw new CommandError("Mothron can only be spawned during a solar eclipse. See the worldevent command."); } // type = 477; queue.Enqueue(new Boss() { type = 477 }); break; case "wood": case "mourning wood": World.SetTime(16200.0, false); // type = 325; queue.Enqueue(new Boss() { type = 325 }); break; case "paladin": // type = 290; queue.Enqueue(new Boss() { type = 290 }); break; case "captain": case "pirate": case "pirate captain": World.SetTime(16200.0, false); // type = 216; queue.Enqueue(new Boss() { type = 216 }); break; case "plantera": // type = 262; queue.Enqueue(new Boss() { type = 262 }); break; case "pumpking": World.SetTime(16200.0, false); // type = 327; queue.Enqueue(new Boss() { type = 327 }); break; case "queen": case "queen bee": // type = 222; queue.Enqueue(new Boss() { type = 222 }); break; case "santa": case "santa nk1": case "santa-nk1": World.SetTime(16200.0, false); // type = 346; queue.Enqueue(new Boss() { type = 346 }); break; case "skeletron": World.SetTime(16200.0, false); // type = 35; queue.Enqueue(new Boss() { type = 35 }); break; case "prime": case "skeletron prime": // type = 127; queue.Enqueue(new Boss() { type = 127 }); break; case "nebula": case "nebula pillar": // type = 507; queue.Enqueue(new Boss() { type = 507 }); break; case "solar": case "solar pillar": // type = 517; queue.Enqueue(new Boss() { type = 517 }); break; case "stardust": case "stardust pillar": // type = 493; queue.Enqueue(new Boss() { type = 493 }); break; case "vortex": case "vortex pillar": // type = 422; queue.Enqueue(new Boss() { type = 422 }); break; case "destroyer": case "the destroyer": World.SetTime(16200.0, false); // type = 134; queue.Enqueue(new Boss() { type = 134 }); break; case "twins": case "the twins": World.SetTime(16200.0, false); // type = 125; // type1 = 126; queue.Enqueue(new Boss() { type = 125, name = "The Twins" }); queue.Enqueue(new Boss() { type = 126, ignore = true }); break; case "eater": case "eater of worlds": // type = 13; queue.Enqueue(new Boss() { type = 13 }); break; case "wall": case "flesh": case "wall of flesh": if (Main.wof > 0 && Main.npc[Main.wof].active) { throw new CommandError("The Wall Of Flesh is already active"); } if (target.position.Y / 16 < (float)(Main.maxTilesY - 205)) //As per NPC.SpawnWOF { throw new CommandError("Player must be in The Underworld to spawn the Eater Of Worlds"); } // type = 113; queue.Enqueue(new Boss() { type = 113 }); break; case "deathcradle": count = 1; var items = new int[] { 87, 266, 473, 370, 344, 4, 491, 245, 471, 50, 243, 345, 439, 395, 398, 477, 325, 290, 216, 262, 327, 222, 346, 35, 127, 507, 517, 493, 422, 134, 125, 126, 13 }; World.SetTime(16200.0, false); foreach (var item in items) { queue.Enqueue(new Boss() { type = item, ignore = true }); } Core._likeABoss = true; Tools.NotifyAllPlayers("Easter egg found: Like a boss mini game!", Color.Purple, true); break; default: throw new CommandError("Unknown boss: " + bossName); } while (count-- > 0) { while (queue.Count > 0) { var boss = queue.Dequeue(); var position = World.GetRandomClearTile(target.position.X / 16f, target.position.Y / 16f); var id = NPC.NewNPC((int)(position.X * 16f), (int)(position.Y * 16f), boss.type); Main.npc[id].SetDefaults(boss.type); Main.npc[id].SetDefaults(Main.npc[id].name); if (count == 0 && !boss.ignore) { var tms = String.Empty; if (count > 1) { tms = " " + count + " times"; } Tools.NotifyAllPlayers((boss.name ?? Main.npc[id].name) + " [" + boss.type + "]" + " summoned by " + sender.SenderName + tms, Color.Purple, true); } } } }
/// <summary> /// Allows on the fly variable modifications /// </summary> /// <param name="sender">Sender.</param> /// <param name="args">Arguments.</param> public void VariableMan(ISender sender, ArgumentList args) { // var <exec|field> // var field <namespace.type> <fieldname> // var field <namespace.type> <fieldname> <valuetobeset> // var exec <namespace.type> <methodname> //No arguments supported yet var cmd = args.GetString(0); if (cmd == "field" || cmd == "arr") { var type = args.GetString(1); var mem = args.GetString(2); //Find the type var at = Type.GetType(type); if (at == null) at = System.Reflection.Assembly.GetEntryAssembly().GetType(type); if (at == null) at = System.Reflection.Assembly.GetCallingAssembly().GetType(type); if (at == null) at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type); if (at == null) at = typeof(Terraria.Main).Assembly.GetType(type); if (at == null) throw new CommandError("Invalid type: " + type); //Find the field var am = at.GetField(mem); if (am == null) throw new CommandError("Invalid field: " + mem); string val = null; if (cmd != "arr" && args.TryGetString(3, out val)) { object data = GetDataValue(am.FieldType, val); am.SetValue(null, data); var v = am.GetValue(null); if (v != null) val = v.ToString(); else val = "null"; sender.Message("Value is now: " + val); } else { var v = am.GetValue(null); if (v != null) { if (v.GetType().IsArray) { var index = args.GetInt(3); var obj = (v as Array).GetValue(index); if (obj is Terraria.RemoteClient) { val = ""; var rc = obj as Terraria.RemoteClient; val += $"Id: {rc.Id}\n"; val += $"IsActive: {rc.IsActive}\n"; val += $"IsAnnouncementCompleted: {rc.IsAnnouncementCompleted}\n"; val += $"IsConnected(): {rc.IsConnected()}\n"; val += $"IsReading: {rc.IsReading}\n"; val += $"Name: {rc.Name}\n"; val += $"PendingTermination: {rc.PendingTermination}\n"; val += $"SpamAddBlock: {rc.SpamAddBlock}\n"; val += $"SpamAddBlockMax: {rc.SpamAddBlockMax}\n"; val += $"SpamDeleteBlock: {rc.SpamDeleteBlock}\n"; val += $"SpamDeleteBlockMax: {rc.SpamDeleteBlockMax}\n"; val += $"SpamProjectile: {rc.SpamProjectile}\n"; val += $"SpamProjectileMax: {rc.SpamProjectileMax}\n"; val += $"SpamWater: {rc.SpamWater}\n"; val += $"SpamWaterMax: {rc.SpamWaterMax}\n"; val += $"State: {rc.State}\n"; val += $"StatusCount: {rc.StatusCount}\n"; val += $"StatusMax: {rc.StatusMax}\n"; val += $"StatusText: {rc.StatusText}\n"; val += $"StatusText2: {rc.StatusText2}\n"; val += $"TimeOutTimer: {rc.TimeOutTimer}\n"; #if CUSTOM_SOCKETS if (rc.Socket is OTA.Sockets.ClientConnection) { val += "\n=======================\nClientConnection\n"; var cc = rc.Socket as OTA.Sockets.ClientConnection; val += $"Active: {cc.Active}\n"; val += $"BytesReceived: {cc.BytesReceived}\n"; val += $"BytesSent: {cc.BytesSent}\n"; val += $"IsOTAClient: {cc.IsOTAClient}\n"; val += $"QueueLength: {cc.QueueLength}\n"; val += $"QueueSize: {cc.QueueSize}\n"; //val += $"RemoteAddress: {cc.RemoteAddress}\n"; val += $"SlotId: {cc.SlotId}\n"; } #endif } else val = obj.ToString(); } else val = v.ToString(); } else val = "null"; sender.Message("Value: " + val); } } else if (cmd == "prop") { var type = args.GetString(1); var prop = args.GetString(2); //Find the type var at = Type.GetType(type); if (at == null) at = System.Reflection.Assembly.GetEntryAssembly().GetType(type); if (at == null) at = System.Reflection.Assembly.GetCallingAssembly().GetType(type); if (at == null) at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type); if (at == null) throw new CommandError("Invalid type: " + type); //Find the field var am = at.GetProperty(prop); if (am == null) throw new CommandError("Invalid property: " + prop); string val = null; if (args.TryGetString(3, out val)) { object data = GetDataValue(am.PropertyType, val); am.SetValue(null, data, null); var v = am.GetValue(null, null); if (v != null) val = v.ToString(); else val = "null"; sender.Message("Value is now: " + val); } else { var v = am.GetValue(null, null); if (v != null) val = v.ToString(); else val = "null"; sender.Message("Value: " + val); } } else if (cmd == "exec") { var type = args.GetString(1); var mthd = args.GetString(2); //Find the type var at = Type.GetType(type); if (at == null) at = System.Reflection.Assembly.GetEntryAssembly().GetType(type); if (at == null) at = System.Reflection.Assembly.GetCallingAssembly().GetType(type); if (at == null) at = System.Reflection.Assembly.GetExecutingAssembly().GetType(type); if (at == null) throw new CommandError("Invalid type: " + type); //Find the field var am = at.GetMethod(mthd); if (am == null) throw new CommandError("Invalid method: " + mthd); var prms = am.GetParameters(); if (prms.Length == 0) { var res = am.Invoke(null, null); var result = res == null ? "null" : res.ToString(); sender.Message("Result: " + result); } else sender.Message("Arguments are not yet supported for exec"); } else sender.Message("Unsupported var command: " + cmd); }
public static void ListWarp(ISender sender, ArgumentList args) { if (WarpManager.WarpList.Count < 1) throw new CommandError("There are no warps."); int maxPages = WarpManager.WarpList.Count / 5; int page = args.GetInt(0); if (maxPages > 0 && page > maxPages - 1 || page < 1) { throw new CommandError("Pages: 1 => {0}", maxPages); } page *= 5; if (page >= WarpManager.WarpList.Count) page = WarpManager.WarpList.Count; int start = page - 5; if (page < 4) start = 0; for (int i = start; i < page; i++) { Warp warp = WarpManager.WarpList.ToArray()[i]; if (warp.IsUserAccessible(sender.Name) || !(sender is Player) || sender.Op) //!player's = OP ?? { sender.Message("Warp: {0}", warp.Name); } else { sender.Message("<PRIVATE>"); } } }
/// <summary> /// Gives specified item to the specified player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void Give(ISender sender, ArgumentList args) { // /give <player> <stack> <name> Player receiver = args.GetOnlinePlayer(0); int stack = args.GetInt(1); string name = args.GetString(2); var max = Tools.AvailableItemSlots; //Perhaps remove a few incase of new drops if (stack > max) { stack = max; // Set to Tools.AvailableItemSlots because number given was larger than this. } int id; var results = int.TryParse(name, out id) ? DefinitionManager.FindItem(id) : DefinitionManager.FindItem(name); if (results != null && results.Length > 0) { if (results.Length > 1) throw new CommandError(String.Format("More than 1 item found, total is: {0}", results.Length)); var item = results[0]; try { item.Prefix = (int)(Affix)Enum.Parse(typeof(Affix), args.GetString(3), true); } catch (CommandError) { }catch (ArgumentException) { throw new CommandError(String.Format("Error, the Prefix you entered was not found: {0}", args.GetString(3))); } var index = receiver.GiveItem(item.Id, stack, sender, item.NetId, true, item.Prefix); if (item.NetId < 0) Main.item[index].netDefaults(item.NetId); Main.item[index].Prefix(item.Prefix); } else throw new CommandError(String.Format("No item known by: {0}", name)); }
internal static void MaxPlayersCommand(ISender sender, ArgumentList args) { if (MaxPlayersDisabled) { sender.Message (255, "This command has been disabled."); return; } int maxp = -1; int overl = -1; if (args.TryGetInt (0, out maxp) && (maxp < 1 || maxp > MAX_SLOTS)) { sender.Message (255, "Max numbers of players must be in range 1 .. {0}", MAX_SLOTS); return; } if (args.Count > 1) { overl = args.GetInt (1); if (overl < 0 || overl > maxp) { sender.Message (255, "Number of overlimit slots must be in range 0 .. <max player count>"); return; } } int oldmax = maxSlots; int oldover = overlimitSlots; int result = maxSlots; if (maxp >= 0 || overl >= 0) { result = ChangeLimits (maxp < 0 ? maxSlots : maxp, overl < 0 ? overlimitSlots : overl); Server.notifyOps( String.Format("Max player slots changed to {0}+{1}. [{2}]", result, overlimitSlots, sender.Name) ); } sender.Message (255, ChatColor.SteelBlue, "Max player slots: {0}, overlimit slots: {1}", result, overlimitSlots); if (oldmax != maxSlots || oldover != overlimitSlots) { Program.properties.MaxPlayers = maxSlots; Program.properties.OverlimitSlots = overlimitSlots; Program.properties.Save (true); } }
/// <summary> /// Gives specified item to the specified player. /// </summary> /// <param name="sender">Sending player</param> /// <param name="args">Arguments sent with command</param> public void Give(ISender sender, ArgumentList args) { // /give <player> <stack> <name> Player receiver = args.GetOnlinePlayer(0); int stack = args.GetInt(1); string name = args.GetString(2); int id; var results = Int32.TryParse(name, out id) ? DefinitionManager.FindItem(id) : DefinitionManager.FindItem(name); if (results != null && results.Length > 0) { if (results.Length > 1) throw new CommandError(String.Format("More than 1 item found, total is: {0}", results.Length)); var item = results[0]; string prefix; if (args.TryGetString(3, out prefix)) { try { item.Prefix = (int)(Affix)Enum.Parse(typeof(Affix), prefix, true); } catch (ArgumentException) { throw new CommandError(String.Format("Error, the Prefix you entered was not found: {0}", args.GetString(3))); } } receiver.GiveItem(item.Id, stack, item.MaxStack, sender, item.NetId, true, item.Prefix); } else throw new CommandError(String.Format("No item known by: {0}", name)); }