Going through Inventory

Hi all,
I want to check whether an unspecified object (identifiable by, say, OfClass) is in the inventory of the player (including bags), and I want to be able to do something to that object. So I’d want to have a routine that I can call and that returns the object if it exists, or zero. How can I achieve that?

(Achievements:
All-Rounder: The routine lets me specify the class so that I can use it for multiple purposes, e.g. obj=invsearch(classname)
Lord of the Strings: The routine lets me search for “IDs” by passing a string which is among the names of the object, e.g. I have 10 objects which have the names ‘fruit’ and ‘(individual fruit name’), and I search it with obj=invsearch(“fruit”).

Thanks a lot, and kind regards,
Grues

1 Like

All-Rounder:

[FindOwnedObjectOfClass classId actorId  o x;
	objectloop(o in actorId) {
		if(o ofclass classId) return o;
		if(child(o)) {
			x = FindOwnedObjectOfClass(classId, o);
			if(x) return x;
		}
	}
	return 0;
];

Call with a classId and an actor (typically player).

3 Likes

It works!!! Thanks Fredrik! And I can use this for so many things now… I’m super happy. :slight_smile: :slight_smile: :slight_smile:

2 Likes