> Oh...and as for the function:    void call_objprog(CHAR_DATA *ch, OBJ_DATA
> *obj, void *vo,
>   MPROG_LIST *code)
>
> I see what the function does...creates the mob and whatnot, but I, being a
> novice mud-coder, have no clue how to use that function to allow my
objprogs
> to cause spell effects.

Well, the trick is to not code obj or room progs separate at all, just
create a mob with the same name as the object, then run the prog using it as
you would a mobprog.  Saves a lot of work duplicating mobprog functionality.
It's generally transparent to both the person writing the prog and the
user...
I've found this can fix almost every issue with objprogs not being able to
do what you want.
Plus you can make a talking sword...
I'll attach a file with some more details and samples that'll work with
stock code in case it appeals to anyone.
Any questions, you have my email address.
--Palrich.

/*
  You'll still have to add the OLC functionality for saving and editing
  objprogs.. and add in the triggers.. and loading.  I don't have the patience
  to document that, and it's all covered well in the objprog snippet already
  floating around.
  You can pretty much keep the versions of mob_cmds and mob_prog.c that come
  with OLC, just add the obj trigger handlers you want to mob_prog.c.

  This code is edited slightly from its tested version to work with stock..
  probably has minor errors.

  --Palrich.
/*

/* mob_prog.c
   You can create a version of create_mobile that doesn't set descriptions
   or bother with a lot of the data, since we set it here or it's unimportant
   to an objprog.. speeds things up a little.
*/

void call_objprog(CHAR_DATA *ch, OBJ_DATA *obj, void *vo,
  MPROG_LIST *code)
{
  CHAR_DATA *mobject;
  mobject = create_mobile(get_mob_index(MOB_VNUM_OBJPROG));
  mobject->level = obj->level;
  free_string(mobject->short_descr);
  mobject->short_descr = str_dup(obj->short_descr);
  free_string(mobject->long_descr);
  mobject->long_descr = str_dup("");
  free_string(mobject->name);
  mobject->name = str_dup(obj->name);
  char_to_room(mobject, ch->in_room);
  program_flow(code->vnum, code->code, mobject, ch, (void *)obj, vo);
  extract_char(mobject, TRUE);
}

bool op_percent_trigger(OBJ_DATA *obj, CHAR_DATA *ch,
  const void *arg, int type)
{
  MPROG_LIST *prg;
  for (prg = obj->pIndexData->progs; prg != NULL; prg = prg->next)
  {
    if (prg->trig_type == type && number_percent() < atoi( prg->trig_phrase))
    {
      call_objprog(ch, obj, arg, code);
      return TRUE;
    }
  }
  return FALSE;
}

op_whatever_trigger(OBJ_DATA *obj, CHAR_DATA *ch, ...)
{
 ...
}

/* merc.h will need some stuff added.. */

struct obj_index_data
{
+    int prog_flags;
+    MPROG_LIST *progs;
    OBJ_INDEX_DATA *    next;

#define HAS_TRIGGER(ch,trig)    (IS_SET((ch)->pIndexData->mprog_flags,(trig)))
+#define OBJ_HAS_TRIGGER(obj,trig)  
(IS_SET((obj)->pIndexData->prog_flags,(trig)))
#define IS_SWITCHED( ch )       ( ch->desc && ch->desc->original )

+#define TRIG_DROP A
+#define TRIG_...

/*
  Now, for example, to add a trigger when an object is dropped,
  find do_drop in act_obj.c
*/

      act( "$n drops $p.", ch, obj, NULL, TO_ROOM );
      act( "You drop $p.", ch, obj, NULL, TO_CHAR );
+      if (OBJ_HAS_TRIGGER(obj, TRIG_DROP))
+        op_percent_trigger(obj, ch, NULL, TRIG_DROP);
      if (IS_OBJ_STAT(obj,ITEM_MELT_DROP))

Reply via email to