Example #1
0
        private void CMDinvsee(CommandArgs args)
        {
            if (!TShock.Config.ServerSideCharacter)
            {
                args.Player.SendErrorMessage("Server Side Character must be enabled.");
                return;
            }
            if (args.Parameters.Count < 1)
            {
                args.Player.SendErrorMessage("Usage: /invsee <player name / -restore>");
                return;
            }
            var ePly = esPlayers[args.Player.Index];
            if (args.Parameters.Count == 1 && args.Parameters[0].ToLower() == "-restore")
            {
                if (ePly.InvSee == null)
                {
                    args.Player.SendErrorMessage("You are not viewing another player's inventory.");
                    return;
                }
                ePly.InvSee.RestoreCharacter(args.Player);
                ePly.InvSee = null;
                args.Player.SendSuccessMessage("Restored your inventory.");
                return;
            }
            var PlayersFound = TShock.Utils.FindPlayer(string.Join(" ", args.Parameters));
            if (PlayersFound.Count != 1)
            {
                args.Player.SendErrorMessage(PlayersFound.Count < 1 ? "No Players matched." : "More than one player matched.");
                return;
            }

            var PlayerChar = new PlayerData(args.Player);
            PlayerChar.CopyCharacter(args.Player);
            if (ePly.InvSee == null)
            {
                ePly.InvSee = PlayerChar;
            }

            var CopyChar = new PlayerData(PlayersFound[0]);
            CopyChar.CopyCharacter(PlayersFound[0]);
            CopyChar.health = PlayerChar.health;
            CopyChar.maxHealth = PlayerChar.maxHealth;
            CopyChar.mana = PlayerChar.mana;
            CopyChar.maxMana = PlayerChar.maxMana;
            CopyChar.spawnX = PlayerChar.spawnX;
            CopyChar.spawnY = PlayerChar.spawnY;
            CopyChar.RestoreCharacter(args.Player);

            args.Player.SendSuccessMessage("Copied {0}'s inventory", PlayersFound[0].Name);
        }
Example #2
0
        public static bool CheckInventory(TSPlayer player)
        {
            PlayerData playerData = player.PlayerData;
            bool       check      = true;

            if (player.TPlayer.statLifeMax > playerData.maxHealth)
            {
                player.SendMessage("Error: Your max health exceeded (" + playerData.maxHealth + ") which is stored on server", Color.Cyan);
                check = false;
            }

            Item[] inventory = player.TPlayer.inventory;
            Item[] armor     = player.TPlayer.armor;
            for (int i = 0; i < NetItem.maxNetInventory; i++)
            {
                if (i < 49)
                {
                    Item item       = new Item();
                    Item serverItem = new Item();
                    if (inventory[i] != null && inventory[i].netID != 0)
                    {
                        if (playerData.inventory[i].netID != inventory[i].netID)
                        {
                            item.netDefaults(inventory[i].netID);
                            item.Prefix(inventory[i].prefix);
                            item.AffixName();
                            player.SendMessage(player.IgnoreActionsForInventory = "Your item (" + item.name + ") needs to be deleted.", Color.Cyan);
                            check = false;
                        }
                        else if (playerData.inventory[i].prefix != inventory[i].prefix)
                        {
                            item.netDefaults(inventory[i].netID);
                            item.Prefix(inventory[i].prefix);
                            item.AffixName();
                            player.SendMessage(player.IgnoreActionsForInventory = "Your item (" + item.name + ") needs to be deleted.", Color.Cyan);
                            check = false;
                        }
                        else if (inventory[i].stack > playerData.inventory[i].stack)
                        {
                            item.netDefaults(inventory[i].netID);
                            item.Prefix(inventory[i].prefix);
                            item.AffixName();
                            player.SendMessage(player.IgnoreActionsForInventory = "Your item (" + item.name + ") (" + inventory[i].stack + ") needs to have it's stack decreased to (" + playerData.inventory[i].stack + ").", Color.Cyan);
                            check = false;
                        }
                    }
                }
                else
                {
                    Item item       = new Item();
                    Item serverItem = new Item();
                    if (armor[i - 48] != null && armor[i - 48].netID != 0)
                    {
                        if (playerData.inventory[i].netID != armor[i - 48].netID)
                        {
                            item.netDefaults(armor[i - 48].netID);
                            item.Prefix(armor[i - 48].prefix);
                            item.AffixName();
                            player.SendMessage(player.IgnoreActionsForInventory = "Your armor (" + item.name + ") needs to be deleted.", Color.Cyan);
                            check = false;
                        }
                        else if (playerData.inventory[i].prefix != armor[i - 48].prefix)
                        {
                            item.netDefaults(armor[i - 48].netID);
                            item.Prefix(armor[i - 48].prefix);
                            item.AffixName();
                            player.SendMessage(player.IgnoreActionsForInventory = "Your armor (" + item.name + ") needs to be deleted.", Color.Cyan);
                            check = false;
                        }
                        else if (armor[i - 48].stack > playerData.inventory[i].stack)
                        {
                            item.netDefaults(armor[i - 48].netID);
                            item.Prefix(armor[i - 48].prefix);
                            item.AffixName();
                            player.SendMessage(player.IgnoreActionsForInventory = "Your armor (" + item.name + ") (" + inventory[i].stack + ") needs to have it's stack decreased to (" + playerData.inventory[i].stack + ").", Color.Cyan);
                            check = false;
                        }
                    }
                }
            }

            return(check);
        }