<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <META NAME="generator" CONTENT="NoteTab"> <TITLE>Object Use</TITLE> </HEAD> <BODY> <P>Object Use - by Dace K. (djdace.k{atmark}gmail.com)<BR> --------------------------------------------------------------------------<BR> This is a simple, but effective little snippet that allows you to add <BR> progs to object, and let users interact with them. It works in the same<BR> way as a use prog does, but does not trigger when the item is worn/picked up/<BR> e.t.c, but when the "use" command is used in conjunction with the item.</P> <P>This code allows for the player to use the item regardless of whether<BR> it's being worn, carried, or in the room. Change to suit your mud's needs.</P> <P>To add an action prog to an item, simply use opedit <obj> action <percentage>.</P> <P>Terms:<BR> You may use this code in your mud if you leave all headers intact, and<BR> give credit to myself (Dace K) in your helpfile for the use command.</P> <P>Installation:</P> <P>mud.h<BR> ===========================================================<BR> In the typedef for prog types, add ACTION_PROG after USE_PROG.</P> <P> PULL_PROG, PUSH_PROG, SLEEP_PROG, REST_PROG, LEAVE_PROG, SCRIPT_PROG,<BR> USE_PROG<BR> <BR> to <BR> <BR> PULL_PROG, PUSH_PROG, SLEEP_PROG, REST_PROG, LEAVE_PROG, SCRIPT_PROG,<BR> USE_PROG, ACTION_PROG</P> <P> After:<BR> void oprog_wear_trigger( CHAR_DATA *ch, OBJ_DATA *obj );</P> <P>Add:<BR> bool oprog_action_trigger( CHAR_DATA *ch, OBJ_DATA *obj);</P> <P>db.c<BR> ===========================================================<BR> In<BR> char * const mprog_flags [] =</P> <P>Change:<BR> "speechiw", "pull", "push", "sleep", "rest", "leave", "script", "use"</P> <P>to</P> <P>"speechiw", "pull", "push", "sleep", "rest", "leave", "script", "use", "action"</P> <P>After:<BR> if ( !str_cmp( name, "use_prog" ) ) return USE_PROG;</P> <P>Add:<BR> if ( !str_cmp( name, "action_prog" ) ) return ACTION_PROG;</P> <P>act_info.c<BR> ===========================================================<BR> IMMEDIATELY after the following in do_examine:<BR> if ( IS_OBJ_STAT( obj, ITEM_COVERING ) )<BR> {<BR> sprintf( buf, "under %s noprog", arg );<BR> do_look( ch, buf );<BR> }<BR> <BR> Add:</P> <P> /*Comment out these two lines if you don't want users to know about action progs - Dace*/<BR> if ( HAS_PROG(obj->pIndexData, ACTION_PROG) )<BR> send_to_char( "&wThis object may have another &Ruse &wbesides what is apparent.\n\r", ch );</P> <P>mud_comm.c<BR> ===========================================================<BR> In mprog_type_to_name, search for:<BR> case USE_PROG: return "use_prog";</P> <P>Add underneath:<BR> case ACTION_PROG: return "action_prog";</P> <P>mud_prog.c<BR> ===========================================================<BR> <P> Before:<BR> /*<BR> * call in remove_obj, right after unequip_char<BR> * do a if(!ch) return right after, and return TRUE (?)<BR> * if !ch<BR> */<BR> <BR> Add: <BR> /* Progs invoked with the 'use' command. - Dace K*/<BR> bool oprog_action_trigger( CHAR_DATA *ch, OBJ_DATA *obj)<BR> {<BR> bool executed = FALSE;</P> <P> if ( HAS_PROG(obj->pIndexData, ACTION_PROG) )<BR> {<BR> set_supermob( obj );<BR> executed = oprog_percent_check( supermob, ch, obj, NULL, ACTION_PROG );</P> <P> release_supermob();<BR> }<BR> return executed;<BR> }</P> <P>===========================================================<BR> act_obj.c<BR> ===========================================================</P> <P>Add this at the bottom of the file.</P> <P>/*Invokes any 'action' progs on an object.*/<BR> void do_use( CHAR_DATA *ch, char *argument )<BR> {<BR> char arg[MAX_INPUT_LENGTH];<BR> OBJ_DATA *obj;</P> <P> if (IS_NPC(ch))<BR> return;</P> <P> one_argument( argument, arg );</P> <P> if ( arg[0] == '\0' )<BR> {<BR> send_to_char( "Syntax: 'Use <object>'\n\r", ch );<BR> return;<BR> }</P> <P> if ( ( obj = get_obj_wear( ch, arg ) ) == NULL )<BR> if ( ( obj = get_obj_carry( ch, arg ) ) == NULL )<BR> if (!(obj = get_obj_list_rev( ch, argument, ch->in_room->last_content )))<BR> {<BR> send_to_char( "There is no such item here.\n\r", ch );<BR> return;<BR> }</P> <P> if ( !oprog_action_trigger( ch, obj, NULL, NULL, NULL ))<BR> ch_printf(ch, "You can't think of anything special to do with %s.", obj->short_descr);<BR> return;<BR> }</P> <P>===========================================================</P> <P>Add the appropriate entries for do_use to tables.c and mud.h,<BR> make clean, recompile, then cedit use create; cedit use level 1<BR> while in game.</P> <P>Enjoy! :).<BR> This snippet, and others, can be found at http://satsui.serverbox.org .<BR> - Dace K.</P> </BODY> </HTML>