> Valhalla MUD - DIL findunit()

DIL findunit() for Dummies

by Gnort

Findunit takes four arguments.

The first is typically the char that's looking for something, i.e. if Mary needs a spoon to stir the pot, she'll be the first argument.

The second argument is what you're looking for, represented by a string. In the above mentioned example, that'd be "spoon".

For the second or third argument, you have a choice, as you'll only need to use one of them, and let the other be 0 or null. For instance, if you have a pointer to Mary's kitchen utensil pot, you can use the line

findunit(mary, "spoon", 0, pot.inside);

The unitptr supplied as 4th argument must, to make sense, point to the CONTENTS of something, so you will typically use `bag.inside' to search a specific bag, `pc.inside' to search a player's inventory and so on. Look at the find_item.dil example in the Dil examples dir.

Instead of the example above, you can also let mary look around for her spoon with

findunit(mary, "spoon", FIND_UNIT_INVEN or FIND_UNIT_SURRO, null);

You can use all the FIND_UNIT_ values defined in values.h, if you want to look for something for example within the zone (FIND_UNIT_ZONE), the entire world (FIND_UNIT_WORLD) (you rarely need to do that, it's mainly for tell etc.), or just the inventory or equipment of the char in question (FIND_UNIT_INVEN and FIND_UNIT_EQUIP). Finally, as in the example above, you can look in the room of the char (FIND_UNIT_SURRO).

The flags for findunit, intuitively:

FIND_UNIT_EQUIP:
The objects you will see with `equipment' Assumes first argument to findunit is a char.

FIND_UNIT_INVEN:
The objects you will see with `inventory' or `look in bag'

FIND_UNIT_SURRO:
The objects you can see, and get with `get', or the characters you can `poke' :-)

FIND_UNIT_ZONE: As FIND_UNIT_WORLD, only more local.

FIND_UNIT_WORLD: Any object in the entire world. Does NOT start looking close to the object of findunit's first argument, but rather somewhat randomly.

On top of these, the following (new) values are defined:

FIND_UNIT_IN_ME:
Anything inside of the object of the first argument.

FIND_UNIT_HERE:
Anything `here', i.e. in object or around it (same as IN_ME + SURRO)

FIND_UNIT_GLOBAL: ANYTHING, starting close to object and working out.

Hope this explains findunit satisfactorily.

Gnort