It reference for objects [by Gary Barnett]
Snippet Posted Wednesday, August 12th @ 11:29:38 PM, by George Greer in the Utils dept.
Added Feb 6, 1997. Click the link below to read it or download it.

From: Gary Barnett <gbarnett@polarnet.com>
Subject: Adding the concept of 'IT' for object commands

Last night I fired up my News Reader and read through the latest
discussions on the rec.games.mud.diku group. After reading a huge
thread on adding 'it' in object based commands; i.e.

> get bread
> eat it

I figured I'd fire up my copy of Dev Studio and see what I could
figure out.

About an hour and half later I had fully implemented the concept
into my mud.. Much easier than it would have seemed from reading
the newgroups..

Details:

In Utils.H

#define GET_OBJ_IT(ch) ((ch)->player_specials->last_obj)
#define GET_POS_IT(ch) ((ch)->player_specials->last_pos)

In structs.h (player_specials)
   struct obj_data *last_obj;
   int last_pos;

With those defines installed, it is just a matter of updating the
player's GET_OBJ_IT and GET_POS_IT fields whenever they access an
object (get, drop, wield, wear, et al).. A couple special checks
need to be made as well.

1) You drop an item.. another PC/NPC gets it.. Needs to cycle through
all the players in teh room to remove their if context if it matches
the 'gotten' object

2) A test for moving.. if you leave the room, your 'IT' context is
invalid.

3) The item being purged, the zone reset removes it, etc.

In addition, a line such as this can be used to supply the object to the
relevant routine that needs to know about it:

if ( (!IS_NPC(ch)) && str_cmp(arg, "it") && (GET_OBJ_IT(ch) != 0)
    && GET_POS_IT(ch) == X)) {
      obj=GET_OBJ_IT(ch);

}

(I placed these checks before the usual get_obj_in_list_vis call for the
relevant routines .. all object based commands)

note: the above X can be 0 (ground) 1 (inventory) 2 (equipment) and
is set whenever an object is accessed via a command (look at, drink,
wield, wear, remove, etc) -- Used to supply the position of the object
so that the test can fail for the 'current' object being out of position
for the relevant action.. i.e. drinking an item on the ground. as in the
following two commands:

> drop barrel
> drink it

Just thought I'd post one method for doing this.. It's still early on,
but from what I have been able to gather, the players LOVE it :-)

I imagine that a lower level call could be used.. i.e. generic find.
From looking at the code though, several routines would have to be
updated to use that call.. This method seemed easy, straightforward
and low overhead. (and easy to debug)

--Mallory



<< Ispell Code (Spell Checker) [by Chris Baggett] | Reply | View as text | Flattened | Language Addition [by ?] >>

 


Related Links
  download
Related Articles
More by greerga
 
 

CircleMUD Snippets
 
Note: Not all of these snippets will work perfectly with your version of code, so be prepared to fix one or two bugs that may arise, and please let me know what you needed to do to fix it. Sending a corrected version is always welcome.
Finally, if you wish to use any of the snippets from this page, you are more than welcome, just mention the authors in your credits. If you wish to release any of these snippets to the public on another site, contact me FIRST.