Object Use - by Dace K. (djdace.k{atmark}gmail.com)
--------------------------------------------------------------------------
This is a simple, but effective little snippet that allows you to add
progs to object, and let users interact with them. It works in the same
way as a use prog does, but does not trigger when the item is worn/picked up/
e.t.c, but when the "use" command is used in conjunction with the item.

This code allows for the player to use the item regardless of whether
it's being worn, carried, or in the room. Change to suit your mud's needs.

To add an action prog to an item, simply use opedit <obj> action <percentage>.

Terms:
You may use this code in your mud if you leave all headers intact, and
give credit to myself (Dace K) in your helpfile for the use command.

Installation:

mud.h
===========================================================
In the typedef for prog types, add ACTION_PROG after USE_PROG.

  PULL_PROG, PUSH_PROG, SLEEP_PROG, REST_PROG, LEAVE_PROG, SCRIPT_PROG,
  USE_PROG
  
  to
  
  PULL_PROG, PUSH_PROG, SLEEP_PROG, REST_PROG, LEAVE_PROG, SCRIPT_PROG,
  USE_PROG, ACTION_PROG

After:
void oprog_wear_trigger( CHAR_DATA *ch, OBJ_DATA *obj );

Add:
bool oprog_action_trigger( CHAR_DATA *ch, OBJ_DATA *obj);

db.c
===========================================================
In
char * const mprog_flags [] =

Change:
"speechiw", "pull", "push", "sleep", "rest", "leave", "script", "use"

to

"speechiw", "pull", "push", "sleep", "rest", "leave", "script", "use", "action"

After:
if ( !str_cmp( name, "use_prog" ) ) return USE_PROG;

Add:
if ( !str_cmp( name, "action_prog" ) ) return ACTION_PROG;

act_info.c
===========================================================
IMMEDIATELY after the following in do_examine:
        if ( IS_OBJ_STAT( obj, ITEM_COVERING ) )
        {
            sprintf( buf, "under %s noprog", arg );
            do_look( ch, buf );
        }
        
Add:

        /*Comment out these two lines if you don't want users to know about action progs - Dace*/
        if ( HAS_PROG(obj->pIndexData, ACTION_PROG) )
        send_to_char( "&wThis object may have another &Ruse &wbesides what is apparent.\n\r", ch );

mud_comm.c
===========================================================
In mprog_type_to_name, search for:
case USE_PROG:          return "use_prog";

Add underneath:
case ACTION_PROG:          return "action_prog";

mud_prog.c
===========================================================

Before:
/*
 * call in remove_obj, right after unequip_char
 * do a if(!ch) return right after, and return TRUE (?)
 * if !ch
 */
 
Add:
/* Progs invoked with the 'use' command. - Dace K*/
bool oprog_action_trigger( CHAR_DATA *ch, OBJ_DATA *obj)
{
    bool executed = FALSE;

    if ( HAS_PROG(obj->pIndexData, ACTION_PROG) )
    {
        set_supermob( obj );
                executed = oprog_percent_check( supermob, ch, obj, NULL, ACTION_PROG );

        release_supermob();
    }
    return executed;
}

===========================================================
act_obj.c
===========================================================

Add this at the bottom of the file.

/*Invokes any 'action' progs on an object.*/
void do_use( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;

    if (IS_NPC(ch))
        return;

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
        send_to_char( "Syntax: 'Use <object>'\n\r", ch );
        return;
    }

        if ( ( obj = get_obj_wear( ch, arg ) ) == NULL )
    if ( ( obj = get_obj_carry( ch, arg ) ) == NULL )
        if (!(obj = get_obj_list_rev( ch, argument, ch->in_room->last_content )))
        {
            send_to_char( "There is no such item here.\n\r", ch );
            return;
        }

        if ( !oprog_action_trigger( ch, obj, NULL, NULL, NULL ))
        ch_printf(ch, "You can't think of anything special to do with %s.", obj->short_descr);
        return;
}

===========================================================

Add the appropriate entries for do_use to tables.c and mud.h,
make clean, recompile, then cedit use create; cedit use level 1
while in game.

Enjoy! :).
This snippet, and others, can be found at http://satsui.serverbox.org .
- Dace K.