Method FindNearestItem
FindNearestItem(string, string, string, float)
Finds the nearest item on the ground that matches the specified name criteria.
public static ItemBehaviour FindNearestItem(string name1 = "", string name2 = null, string name3 = null, float maxDistance = 15)
Parameters
name1stringPrimary name to search for. Item name must contain this string. If empty, matches any name.
name2stringOptional secondary name to search for. If provided, item name must contain either this or name1.
name3stringOptional tertiary name to search for. If provided, item name must contain either this, name2, or name1.
maxDistancefloatMaximum search distance from the hero. Defaults to 15 units.
Returns
- ItemBehaviour
The nearest ItemBehaviour that matches the criteria, or null if no matching item is found.
Remarks
The method searches for items in a box-shaped area around the hero. Items must be:
- Within the specified maxDistance
- Not already in an inventory
- Not currently equipped
- Not being carried by a player
- Reachable by the hero's navigation system
var potion = Hero.FindNearestItem("Vial of Hero.Health");
if (potion != null)
{
Hero.PickUp(potion);
}var weapon = Hero.FindNearestItem("sword", "axe");
if (weapon != null)
{
Hero.Say($"Found a {weapon.name}!");
}