<!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 &lt;obj&gt; action &lt;percentage&gt;.</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>&nbsp;&nbsp;PULL_PROG, PUSH_PROG, SLEEP_PROG, REST_PROG, LEAVE_PROG, SCRIPT_PROG,<BR>
&nbsp;&nbsp;USE_PROG<BR>
&nbsp;&nbsp;<BR>
&nbsp;&nbsp;to <BR>
&nbsp;&nbsp;<BR>
&nbsp;&nbsp;PULL_PROG, PUSH_PROG, SLEEP_PROG, REST_PROG, LEAVE_PROG, SCRIPT_PROG,<BR>
&nbsp;&nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( IS_OBJ_STAT( obj, ITEM_COVERING ) )<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf( buf, "under %s noprog", arg );<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_look( ch, buf );<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
Add:</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*Comment out these two lines if you don't want users to know about action progs - Dace*/<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( HAS_PROG(obj-&gt;pIndexData, ACTION_PROG) )<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;send_to_char( "&amp;wThis object may have another &amp;Ruse &amp;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: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return "use_prog";</P>

<P>Add underneath:<BR>
case ACTION_PROG: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return "action_prog";</P>


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

<P>&nbsp;&nbsp;&nbsp;&nbsp;if ( HAS_PROG(obj-&gt;pIndexData, ACTION_PROG) )<BR>
&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_supermob( obj );<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;executed = oprog_percent_check( supermob, ch, obj, NULL, ACTION_PROG );</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;release_supermob();<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;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>
&nbsp;&nbsp;&nbsp;&nbsp;char arg[MAX_INPUT_LENGTH];<BR>
&nbsp;&nbsp;&nbsp;&nbsp;OBJ_DATA *obj;</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;if (IS_NPC(ch))<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;one_argument( argument, arg );</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;if ( arg[0] == '\0' )<BR>
&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;send_to_char( "Syntax: 'Use &lt;object&gt;'\n\r", ch );<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}</P>

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

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( !oprog_action_trigger( ch, obj, NULL, NULL, NULL ))<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch_printf(ch, "You can't think of anything special to do with %s.", obj-&gt;short_descr);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>