当前位置: 首页>>代码示例>>C#>>正文


C# ArgumentList.GetOnlinePlayer方法代码示例

本文整理汇总了C#中ArgumentList.GetOnlinePlayer方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentList.GetOnlinePlayer方法的具体用法?C# ArgumentList.GetOnlinePlayer怎么用?C# ArgumentList.GetOnlinePlayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArgumentList的用法示例。


在下文中一共展示了ArgumentList.GetOnlinePlayer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrivateMessageSend

        public void PrivateMessageSend(ISender sender, ArgumentList args)
        {
            var playerFrom = sender as Player;
            if (playerFrom == null)
            {
                sender.SendMessage("This is a player command.", G: 0, B: 0);
                return;
            }

            var playerTo = args.GetOnlinePlayer(0);
            var msg = string.Join(" ", args.Skip(1).ToArray());

            playerTo.Message(255, Color.Orange, $"[PM] {sender.SenderName}: {msg}");

            playerFrom.SetPluginData("LastPM", playerTo.name);
        }
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:16,代码来源:PrivateMessageCommand.cs

示例2: SpawnNPC

        /// <summary>
        /// Spawns specified NPC type.
        /// </summary>
        /// <param name="server">Current Server instance</param>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public static void SpawnNPC(Server server, ISender sender, ArgumentList args)
        {
            Player player = sender as Player;
            if (args.Count > 3)
            {
                throw new CommandError("Too many arguments. NPC and player names with spaces require quotes.");
            }
            else if (sender is ConsoleSender && args.Count <= 2)
            {
                throw new CommandError("As console you need to specify the player to spawn near.");
            }
            else if (args.Count == 3)
            {
                player = args.GetOnlinePlayer(2);
            }

            String npcName = args.GetString(1).ToLower().Trim();

            // Get the class id of the npc
            Int32 realNPCId = 0;
            NPC fclass = Registries.NPC.FindClass(npcName);
            if (fclass.type != Registries.NPC.Default.type)
            {
                realNPCId = fclass.Type;
            }
            else
            {
                try
                {
                    realNPCId = Int32.Parse(npcName);
                }
                catch
                {
                    throw new CommandError("Specified NPC does not exist");
                }
            }

            int NPCAmount = 0;

            try
            {
                NPCAmount = Int32.Parse(args[0]);
                if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player)
                {
                    (sender as Player).Kick ("Don't spawn that many.");
                    return;
                }
            }
            catch
            {
                throw new CommandError("Expected integer for number to spawn.");
            }

            String realNPCName = "";
            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);
                //Registries.NPC.Alter(Main.npcs[npcIndex], fclass.Name);
                realNPCName = Main.npcs[npcIndex].Name;
            }
            Program.server.notifyOps("Spawned " + NPCAmount.ToString() + " of " +
                    realNPCName + " {" + player.Name + "}", true);
        }
开发者ID:Dyrian,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:70,代码来源:Commands.cs

示例3: SpawnNPC

        /// <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);
        }
开发者ID:carriercomm,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:80,代码来源:SpawnNpcCommand.cs

示例4: Give

        /// <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");
                }
            }
        }
开发者ID:rakiru,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:48,代码来源:Commands.cs

示例5: Give

        /// <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"));
                }
            }
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:72,代码来源:Commands.cs

示例6: SpawnNPC

        /// <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);
        }
开发者ID:jason14747,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:67,代码来源:Commands.cs

示例7: Give

        /// <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));
        }
开发者ID:Stickiler,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:35,代码来源:Commands.cs

示例8: SpawnNPC

        /// <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)
                //{
//.........这里部分代码省略.........
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:101,代码来源:SpawnNpcCommand.cs

示例9: MessagePlayer

        public static void MessagePlayer(ISender sender, ArgumentList args)
        {
            var Player = args.GetOnlinePlayer(0);
            var Message = args.GetString(1);

            Player.sendMessage(String.Format("[{0}] PM: {1}", sender.Name, Message), ChatColor.DarkGray);
            Server.notifyOps(String.Format("PM {0} => {1}: {2}", sender.Name, Player.Name, Message));
        }
开发者ID:TimeBomb,项目名称:Essentials-TDSM,代码行数:8,代码来源:Commands.cs

示例10: Slay

        public static void Slay(ISender sender, ArgumentList args)
        {
            var player = args.GetOnlinePlayer(0);

            NetMessage.SendData(26, -1, -1, " died of unknown causes...", player.whoAmi, 0, (float)9999, (float)0);
            sender.sendMessage("You killed " + player.Name + "!", 255, 0f, 255f, 255f);
            Essentials.Log("Player " + player + " used /slay on " + player.Name);
        }
开发者ID:TimeBomb,项目名称:Essentials-TDSM,代码行数:8,代码来源:Commands.cs

示例11: Kit

        public static void Kit(ISender sender, ArgumentList args)
        {
            Essentials Plugin = (Essentials)args.Plugin;

            Player player = args.GetOnlinePlayer(0);

            if (args.Count > 0)
            {
                if (KitManager.ContainsKit(args[0]))
                {
                    Kit kit = KitManager.GetKit(args[0]);
                    if (kit.ItemList != null && kit.ItemList.Count > 0)
                    {
                        foreach (KeyValuePair<Int32, Int32> ItemID in kit.ItemList)
                            Item.NewItem((int)player.Position.X, (int)player.Position.Y, player.Width, player.Height, ItemID.Key, ItemID.Value, false);

                        player.sendMessage("Recived the '" + kit.Name + "' Kit.");
                    }
                    else
                        player.sendMessage("Issue with null kit/list");
                }

                //Help ::: Shows what kits there are
                else if (args[0].Equals("help"))
                {
                    String Kits = "";
                    foreach (Kit kit in KitManager.KitList)
                    {
                        if (kit.Name.Trim().Length > 0)
                            Kits = Kits + ", " + kit.Name;
                    }
                    if (Kits.StartsWith(","))
                        Kits = Kits.Remove(0, 1).Trim();

                    if (Kits.Length > 0)
                        player.sendMessage("Available Kits: " + Kits);

                }

                //If kit does not exist
                else
                    player.sendMessage("Error: specified kit " + args[0] + " does not exist. Please do /kit help");
            }
            //Error message
            else
                player.sendMessage("Error: You did not specify a kit! Do /kit help!");
        }
开发者ID:TimeBomb,项目名称:Essentials-TDSM,代码行数:47,代码来源:Commands.cs

示例12: GodMode

        public static void GodMode(ISender sender, ArgumentList args)
        {
            Essentials Plugin = (Essentials)args.Plugin;

            Player player = args.GetOnlinePlayer(0);
            //if (!(sender is Player))
            //{
            //    if (!args.TryGetOnlinePlayer(1, out player))
            //    {
            //        sender.sendMessage("As a non player, Please specify one!");
            //        return;
            //    }
            //}

            if (player.HasClientMod)
            {
                //Tell the client to use God.
                bool On;
                if (Plugin.essentialsRPGPlayerList.TryGetValue(player.whoAmi, out On))
                {
                    NetMessage.SendData((int)Packets.CLIENT_MOD_GOD, player.whoAmi, -1, "", 0);
                    if (!Server.AllowTDCMRPG)
                        Plugin.essentialsRPGPlayerList.Remove(player.whoAmi);
                }
                else
                {
                    NetMessage.SendData((int)Packets.CLIENT_MOD_GOD, player.whoAmi, -1, "", 1);
                    if (!Server.AllowTDCMRPG)
                        Plugin.essentialsRPGPlayerList.Add(player.whoAmi, true);
                }

                return;
            }

            bool found = false;
            bool godModeStatus = false;
            for (int i = 0; i < Plugin.essentialsPlayerList.Count; i++)
            {
                int PlayerID = Plugin.essentialsPlayerList.Keys.ElementAt(i);
                Player eplayer = Main.players[PlayerID];
                if (eplayer.Name.Equals(player.Name))
                {
                    bool GodMode = !Plugin.essentialsPlayerList.Values.ElementAt(i);
                    Plugin.essentialsPlayerList.Remove(PlayerID);
                    Plugin.essentialsPlayerList.Add(PlayerID, GodMode);
                    godModeStatus = GodMode;
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                godModeStatus = true;
                Plugin.essentialsPlayerList.Add(player.whoAmi, godModeStatus);
            }

            player.sendMessage("God Mode Status: " + godModeStatus.ToString());
        }
开发者ID:TimeBomb,项目名称:Essentials-TDSM,代码行数:58,代码来源:Commands.cs

示例13: Give

        /// <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));
        }
开发者ID:skylord123,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:46,代码来源:Commands.cs

示例14: Give

        /// <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));
        }
开发者ID:Narkun,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:38,代码来源:Commands.cs

示例15: SpawnNPC

        /// <summary>
        /// Spawns specified NPC type.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        public static void SpawnNPC(ISender sender, ArgumentList args)
        {
            Player player = sender as Player;
            if (args.Count > 3)
            {
                throw new CommandError("Too many arguments. NPC and player names with spaces require quotes.");
            }
            else if (sender is ConsoleSender && args.Count <= 2)
            {
                throw new CommandError("As console you need to specify the player to spawn near.");
            }
            else if (args.Count == 3)
            {
                player = args.GetOnlinePlayer(2);
            }

            string npcName = args.GetString(1).ToLower().Trim();

            // Get the class id of the npc
            int realNPCId = 0;
            NPC fclass = Registries.NPC.FindClass(npcName);
            if (fclass.type != Registries.NPC.Default.type)
            {
                realNPCId = fclass.Type;
            }
            else
            {
                try
                {
                    realNPCId = Int32.Parse(npcName);
                }
                catch
                {
                    throw new CommandError("Specified NPC does not exist");
                }
            }

            int NPCAmount = 0;

            try
            {
                NPCAmount = Int32.Parse(args[0]);
                if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player)
                {
                    (sender as Player).Kick ("Don't spawn that many.");
                    return;
                }
            }
            catch
            {
                throw new CommandError("Expected integer for number to spawn.");
            }

            string realNPCName = "";
            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);
                //Registries.NPC.Alter(Main.npcs[npcIndex], fclass.Name);
                realNPCName = Main.npcs[npcIndex].Name;
            //				var npc = Main.npcs[npcIndex];
            //				Console.WriteLine ("Name: {0}, Type: {1}, NetID: {2}, Scale: {3}, Height: {4}, Width: {5}, Ghost: {6}, Flying: {7}, Life: {8}/{9}, Debuffs: {10}/{11}",
            //					npc.Name, npc.Type, npc.NetID, npc.scale, npc.Height, npc.Width, npc.noTileCollide, npc.noGravity, npc.life, npc.lifeMax, string.Join(",", npc.buffType), string.Join(",", npc.buffTime));
            }
            Server.notifyOps("Spawned " + NPCAmount.ToString() + " of " +
                    realNPCName + " {" + player.Name + "}", true);
        }
开发者ID:jocull,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:72,代码来源:Commands.cs


注:本文中的ArgumentList.GetOnlinePlayer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。