+Search

Checks all objects and exits in the room, as well as the room itself, for an attribute named HIDDEN. If present, it's evaluated as a ufun.

Author: Raevnos
Category: Globals
Compatibility: PennMUSH, TinyBit.

Instructions

Copy and paste the below code into a compatible MUSH or MUX.

MUSHCode for +Search

@@ -*- mushcode -*- $Id: search.txt 1.2 Wed, 02 Aug 2000 22:39:31 -0700 shawnw $
@create +search code
@lock/Basic +search code==me
@set +search code = VISUAL
@set +search code = !NO_COMMAND
&+SEARCH_CMD +search code=$+search:@select 0=hastype(%#, player), @pemit/s %#=Sorry\, only players can +search., match(get(%#/status), IC), {@pemit/s %#=+SEARCHing while OOC only checks objects you control.; @trigger %xa/search_trg=%#, [setr(1, filter(%xa/found, setr(0, filter(%xa/controls, cat(lcon(%l), lexits(%l), %l)))))], [setdiff(%q0, %q1)]},@trigger %xa/search_trg=%#, [setr(1, filter(%xa/found, setr(0, cat(lcon(%l), lexits(%l), %l))))], [setdiff(%q0, %q1)]
&CONTROLS +search code=controls(%#,%0)
@DESCRIBE +search code=+search is a system for creating hidden details or events that can be triggered by players. It's meant mostly for RP Mushes, but can be used in social ones also if you want. The code has only been tested on PennMUSH, but hopefully should work without modification on TinyMUSH and TinyMUX. Examine +SEARCH/INSTALL for hints on setting it up, and the HELP_X attributes for help on using it.
@set +search code/DESCRIBE=no_command visual
&FOUND +search code=t(ulocal(%0/hidden, %#))
&HASOSFAIL +search code=hasattrval(%0,osearchfail)
&HASSFAIL +search code=hasattrval(%0,searchfail)
&HELP_+SEARCH +search code=+SEARCH:%r%r[space(5)]This command allows you to ICl y search a room, it's contents, and it's exits for concealed features and details that may be present. Normally, it can only be used while IC. When OOC, it only works on objects you control, and has no time delay, for testing purposes.%r%rFor information on how to set up objects to be +search-able, see +HELP +SEARCH CODING
&HELP_+SEARCH_CODING +search code=The +search code checks all objects and exits in the room, as well as the room itself, for an attribute named HIDDEN. If present, it's evaluated as a ufun, with the dbref of the +searcher passed as \%0. If it returns a value that makes t() return 1 (See HELP T()), the object is considered found. Otherwise, the search on it fails.%r%rWhen a +search succeeds, the searcher sees the contents of the object's SEARCH attribute, others in the room see the object's OSEARCH attribute prefixed by the searcher's name, and the code in the object's ASEARCH attribute is triggered, with \%0 as the dbref of the +searcher. If the SEARCH and OSEARCH attributes are not set, default messages are displayed.%r%rIf the search fails, the same process occurs, with the SEARCHFAIL, OSEARCHFAIL, and ASEARCHFAIL attributes respectively. There are no defaults for these.%r%rFor an example, see +HELP +SEARCH EXAMPLE
&HELP_+SEARCH_EXAMPLE +search code=Here is a simple example of an object that is +searchable:%r%r@create Gopher Hole%r@set Gopher Hole=DARK%r&HIDDEN Gopher Hole=\[lt(rand(100),50)\]%r&SEARCH Gopher Hole=You stumble into a gopher hole and nearly twist your ankle.%r&OSEARCH Gopher Hole=stumbles into a gopher hole and nearly twists \%p ankle.%r&ASEARCH Gopher Hole=@set me=!dark%r&OSEARCHFAIL Gopher Hole=narrowly avoids stepping into a gopher hole, though \%s doesn't realize it.%r%rWhen Bob +searchs and succeeds (Which happens 50\% of the time), he sees:%rYou stumble into a gopher hole and nearly twist your ankle.%rOthers in the room see:%rBob stumbles into a gopher hole and nearly twists his ankle.%rAnd, the gopher hole object become visible.
&INSTALL +search code=To use this code on your mush, install the HELP_X attributes into your local +help. Put the +SEARCH_CMD attribute on a wizard object in the master room. Put everything else on a wizard object not in the master room. Change the +SEARCH_CMD attribute now in the master room by replacing '%xa' with the dbref of the object everything else is on. @edit can be used for this. Then, change the match(get(%#/status),IC) part of the +SEARCH_CMD attribute to whatever code your mush uses to check to see if a player is In Character. That should be all you need.
&LICENSE +search code=All code on this object (Raevnos' +search code) is released under the Gnu Public License. A copy of that license is avaliable at [tagwrap(a, href="http://www.gnu.org/copyleft/gpl.html", http://www.gnu.org/copyleft/gpl.html)]
&SEARCH_TRG +search code=@pemit/s %0=You search around for anything interesting...;@oemit %0=[name(%0)] searchs around for anything interesting...;@dolist %1=@verb ##=%0,SEARCH,You find [name(##)]!,OSEARCH,finds [name(##)]!,ASEARCH,%0,%q0;@dolist/notify setdiff(%2,%1)=@verb ##=%0,SEARCHFAIL,,OSEARCHFAIL,,ASEARCHFAIL,%0,%q0;@wait me={@switch and(eq(words(%1),0),eq(words(filter(hassfail,%2)),0))=1,@pemit/s %0=You didn't find anything.;@switch and(eq(words(%1),0),eq(words(filter(hasosfail,%2)),0))=1,@oemit %0=[capstr(subj(%0))] didn't find anything.};@@ This @wait and the /notify switch to the @dolist can be removed, leaving the plain @dolist and @switches without harm. It simply adds a slight delay to the final message (If shown) to simulate the time it takes to search. You can replace with a timed @wait, or take it out entirely if you wish. @@
@STARTUP +search code=@drain me
@set +search code/STARTUP=no_command
think Setup complete