Player player = // get player object Item item = player.Items.FindItemByType(typeof(Weapon)); // find a weapon in the player's inventory
ListIn this example, the FindItemByType method is not used directly. Instead, a foreach loop iterates through all the items in the game world container. The is operator is used to check if each item is a Weapon, and if so, it is added to a list of all the weapons in the world. The FindItemByType method is a built-in function in the Server.Items namespace in C#. No external library is required.- weaponsInWorld = new List
- (); Container worldContainer = // get game world container object foreach (Item item in worldContainer.Items) { if (item is Weapon) // check if item is a weapon { weaponsInWorld.Add(item); // add the weapon to the list } }