Method FindNearestItem
FindNearestItem(string, string, string, float)
Finds the nearest item on the ground that matches the specified name criteria.
public ItemBehaviour FindNearestItem(string name1 = "", string name2 = null, string name3 = null, float maxDistance = 15)
Parameters
name1
stringPrimary name to search for. Item name must contain this string. If empty, matches any name.
name2
stringOptional secondary name to search for. If provided, item name must contain either this or name1.
name3
stringOptional tertiary name to search for. If provided, item name must contain either this, name2, or name1.
maxDistance
floatMaximum 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 = FindNearestItem("Vial of Health");
if (potion != null)
{
PickUp(potion);
}
var weapon = FindNearestItem("sword", "axe");
if (weapon != null)
{
Say($"Found a {weapon.name}!");
}