Understand and use the object-finding simul_efuns for Oxidus. Covers find_target, find_targets, find_ob, get_object, get_objects, present_livings, present_players, present_npcs, present_clones, clones, top_environment, same_env_check, accessible_objects, this_body, and this_caller.
You are helping write or modify code that needs to locate objects in the game world. These are all simul_efuns — available everywhere without #include. Follow the lpc-coding-style skill for all formatting.
| Scenario | Function |
|---|---|
| Player command: find one item by name | find_target(tp, arg, source) |
| Player command: find all matching items | find_targets(tp, arg, source) |
| Get all living creatures in a room | present_livings(room) |
| Get all players in a room | present_players(room) |
| Get all NPCs in a room | present_npcs(room) |
| Find a specific living by name in a room | get_living(name, room) |
| Find a specific player by name in a room | get_player(name, room) |
| Find all clones of a file in a container | present_clones(file, container) |
| Find all clones of a file in the game | clones(file) |
| Flexible search with keywords ("me", "here", "@") | get_object(str, player) |
Complex hierarchical search (:i, :e, :d) | get_objects(str, player) |
| Programmatic file-name match in a container | find_ob(ob, container) |
| Get the room an object is ultimately in | top_environment(ob) |
| Check if two objects share an environment | same_env_check(ob1, ob2) |
| Get all reachable objects in a container | accessible_objects(container) |
These are the workhorses for commands — they include visibility checking and ID matching.
Find a single object visible to the user.
varargs object find_target(object user, string arg, object source, function f)
user — the player/NPC searching (used for visibility checks)arg — what to search for (matched via ob->id(arg)). Supports "sword 2" numeric indexingsource — container to search in (defaults to environment(user))f — optional extra filter function (: func(ob, user) :)// Find item in player's inventory
object ob = find_target(tp, arg, tp);
// Find item in the room
object ob = find_target(tp, arg, environment(tp));
// Find second sword in inventory
object ob = find_target(tp, "sword 2", tp);
// With custom filter
object ob = find_target(tp, arg, tp, (: $1->is_edible() :));
Find all matching objects visible to the user. Same parameters as find_target.
varargs object *find_targets(object user, string arg, object source, function f)
// All visible items in room (no arg = all)
object *obs = find_targets(tp, 0, environment(tp));
// All swords in inventory
object *obs = find_targets(tp, "sword", tp);
Both functions apply filters in order:
all_inventory(source) — get everything in the containerfilter_by_id(obs, arg) — keep only objects where ob->id(arg) is true (skipped if arg is null)filter_by_visibility(user, obs) — keep only objects where user->can_see(ob) is trueQuick ways to get living objects from a room. No visibility checks — returns all.
All living objects (players + NPCs) in a room.
object *present_livings(object room)
// Implementation: filter(all_inventory(room), (: living($1) :))
Only player characters.
object *present_players(object room)
// Implementation: filter(present_livings(room), (: userp :))
Only non-player characters.
object *present_npcs(object room)
// Implementation: filter(present_livings(room), (: !userp($1) :))
Find a specific living by name in a room.
object get_living(string id, object room)
// Uses present(id, room), then checks living()
Find multiple livings by name array.
object *get_livings(mixed ids, object room)
// ids can be string or string*
Find a specific player by name in a room.
object get_player(string name, object room)
// Uses get_living(), then checks userp()
Find multiple players by name array.
object *get_players(mixed names, object room)
Find all clones of a file within a specific container.
object *present_clones(mixed file, object container)
file — filename string or object (uses base_name() if object)container — where to search (defaults to previous_object())object *coins = present_clones("/std/coin", tp);
object *potions = present_clones(potion_ob, chest);
Find all clones of a file game-wide.
varargs object *clones(mixed file, int env_only)
env_only — if 1, only return clones that have an environment (filters out "floating" objects)object *all_monsters = clones("/std/monster");
object *placed_monsters = clones("/std/monster", 1);
Broad search with special keyword support. Searches through multiple locations.
varargs object get_object(string str, object player)
Search order:
@name prefix — returns environment of the named object"me" — returns the playerpresent(str, player))"here" / "env" / "environment" — returns player's environmentpresent(str, environment(player)))previous_object() inventoryfind_player(str) — global player lookupfind_living(str) — global living lookupload_object() — file-based lookupBest for wizard commands and flexible user input parsing.
Extended search with relationship markers. Supports chaining.
varargs mixed get_objects(string str, object player, int no_arr)
Relationship markers (colon-separated):
| Marker | Meaning |
|---|---|
:i | Inventory of base objects |
:e | Environment of base objects |
:d | Deep inventory of base objects |
:c | All children (clones) of base file |
:s | All shadows of base objects |
:>method | Call method, use result if object(s) |
:N (number) | Array index into results |
get_objects("users:i") // All items in all users' inventories
get_objects("bob:e:guard") // Guards in Bob's room
get_objects("/std/monster:c") // All monster clones
get_objects("users:s") // All shadows on users
get_objects("users:0") // First user
get_objects("users") // All users (special keyword)
Precise file-based lookup within a container. No visibility checks, no ID matching.
varargs object find_ob(mixed ob, mixed cont)
ob is an object: checks present(ob, cont)ob is a path with #id: exact file_name() matchob is a path without #: base_name() matchfind_ob("/obj/sword#42", room); // Exact clone
find_ob("/obj/sword", player); // Any clone of sword
find_ob(sword_obj, chest); // Is this object in chest?
Get the outermost environment (usually a room). Traverses up through nested containers, stops at objects where is_room() returns true.
object top_environment(object ob)
// sword in backpack in player in room -> returns room
object room = top_environment(sword);
Get all intermediate environments between an object and its room.
object *all_environment(object ob)
// Stops at is_room(), does NOT include the room
Check if two objects share an environment.
varargs int same_env_check(object one, object two, int top_env)
top_env = 0 (default): checks immediate environment()top_env = 1: checks top_environment() (same room, even if in different containers)// Are they in the same room?
if(same_env_check(player, target, 1)) { ... }
// Are they in the same container?
if(same_env_check(item1, item2)) { ... }
Get a nested array of all objects reachable within a container, respecting inventory_accessible().
varargs mixed *accessible_objects(object container, object pov)
Returns nested structure: ({container, item1, item2, ({subcontainer, sub_item1, sub_item2}), item3})
Returns 0 if inventory is not accessible.
Flat version of accessible_objects().
varargs object *accessible_objects_flat(object container, object pov)
The player/NPC executing the current command. Wrapper for efun::this_player().
object this_body()
The original initiator of the call chain (through forces/shadows). Wrapper for efun::this_player(1).
object this_caller()
Check if the caller matches a specific object or filename.
int caller_is(mixed ob)
Note: Does not work when called from other simul_efun functions.
Get the unique numeric object ID from the driver. Extracts the #N from file_name().
int getoid(object ob)
// "/obj/sword#42" -> 42
mixed main(object tp, string arg) {
if(!arg)
return _error("Eat what?");
object ob = find_target(tp, arg, tp); // search inventory
if(!ob)
return _error("You don't have that.");
if(!ob->is_edible())
return _error("You can't eat that.");
// ...
}
object ob = find_target(tp, arg, environment(tp));
if(!ob)
ob = find_target(tp, arg, tp);
object *npcs = present_npcs(environment(tp));
object *enemies = filter(npcs, (: $1->is_hostile($(tp)) :));
if(!same_env_check(tp, target, 1))
return _error("They are not here.");