/** * Returns true if the given player has any of the given item types in thier inventory. * index : Is set to the index of the item found. If it isn't found, it is set to -1. * counts : the minimum stack per item needed for HasItem to return true. * includeAmmo : true if you wish to include the ammo slots. * includeCoins : true if you wish to include the coin slots. */ public static bool HasItem(Player player, int[] types, ref int index, int[] counts = default(int[]), bool includeAmmo = false, bool includeCoins = false) { if (types == null || types.Length == 0) { return(false); //no types to check! } if (counts == null || counts.Length == 0) { counts = BaseUtility.FillArray(new int[types.Length], 1); } int countIndex = -1; if (includeCoins) { for (int m = 50; m < 54; m++) { Item item = player.inventory[m]; if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex]) { index = m; return(true); } } } if (includeAmmo) { for (int m = 54; m < 58; m++) { Item item = player.inventory[m]; if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex]) { index = m; return(true); } } } for (int m = 0; m < 50; m++) { Item item = player.inventory[m]; if (item != null && BaseUtility.InArray(types, item.type, ref countIndex) && item.stack >= counts[countIndex]) { index = m; return(true); } } return(false); }
/* * Returns the total itemstack sum of a specific item in the player's inventory. * * typeIsAmmo : If true, types are considered ammo types. Else, types are considered item types. */ public static int GetItemstackSum(Player player, int[] types, bool typeIsAmmo = false, bool includeAmmo = false, bool includeCoins = false) { int stackCount = 0; if (includeCoins) { for (int m = 50; m < 54; m++) { Item item = player.inventory[m]; if (item != null && (typeIsAmmo ? BaseUtility.InArray(types, item.ammo) : BaseUtility.InArray(types, item.type))) { stackCount += item.stack; } } } if (includeAmmo) { for (int m = 54; m < 58; m++) { Item item = player.inventory[m]; if (item != null && (typeIsAmmo ? BaseUtility.InArray(types, item.ammo) : BaseUtility.InArray(types, item.type))) { stackCount += item.stack; } } } for (int m = 0; m < 50; m++) { Item item = player.inventory[m]; if (item != null && (typeIsAmmo ? BaseUtility.InArray(types, item.ammo) : BaseUtility.InArray(types, item.type))) { stackCount += item.stack; } } return(stackCount); }