Help with a simple trigger

Login to reply  Page: « < 1 of 1 > »
28 Jul 2010 - 20:452933
Help with a simple trigger
Hello friends

I need help with a trigger. I walk a little rusty, so if they can help me, I thank you. It's simple.

It is this: You have an object vnum 30 201. I want that when the player enters a specific room, triggering "sweep" the inventory of it, and delete all the items in this inventory vnum him. But just this item.

Can someone help me with this?

Thanks


29 Jul 2010 - 02:062934
I would use has_item, purge, and a while loop.
while %actor.has_item(#)%
     %purge% %actor.inventory(#)%   
done
Need to add purges for equip position if the item is wearable. Help files below


Checks if actor has item (inventory, equipped and in containers) by subfield name/var/vnum.

TSTAT 155
> help %purge
%PURGE% OPURGE MPURGE WPURGE

%purge% <victim>

Purge removes objects or mobs from the game. If no argument is given, then
all objects and mobs in the room will be removed. If there is an argument,
only that mob or object will be purged. Players can not be purged.

Examples:
%purge% %self%
%purge% %actor.inventory(1300)%
%purge% %actor.eq(hold)%

When purging objects make sure the object exists. If it does not the room will
be purged:

if %actor.inventory(700)%
%purge% %actor.inventory(700)%
end

Alwasy purge at the end of a trigger. If you purge a mob/obj at the beginning
you can no longer access that mob/obj variables.

Example: TSTAT 1375, 6300

See Also: POSITIONS


__________________
Rumble
The Builder Academy
tbamud.com 9091

Last edited by Rumble (29 Jul 2010 - 02:06)
14 Sep 2010 - 14:253000
But if the object (30 201) is inside another object? This form would also work in this case?

Thanks


15 Sep 2010 - 11:033002
Actually %actor.inventory% just checks ch->carrying in its current version.

A slight rewrite might be in order. Add this near the top of dg_variables.c (near the other item_ functions:
/*
 * Search through a list, including containers,
 * for item with given name or vnum.
 * Return ID of first matching item.
 */
long get_item_id_in_list(char *item, obj_data *list)
{
   obj_data *i;
   long tmp = 0L;

   if (!item || !*item)
     return 0L;

   if (is_number(item)) {
      /* check for vnum */
      obj_vnum ovnum = atoi(item);

      for (i = list; i; i = i->next_content) {
         if (GET_OBJ_VNUM(i) == ovnum)
           return GET_ID(i);
         if (GET_OBJ_TYPE(i) == ITEM_CONTAINER) {
            tmp = get_item_id_in_list(item, i->contains);
            if (tmp != 0L) {
               return tmp; // found in recursive call
            }
         }
      }
   } else {
      for (i = list; i; i = i->next_content) {
         if (isname(item, i->name))
           return GET_ID(i);
         if (GET_OBJ_TYPE(i) == ITEM_CONTAINER) {
            tmp = get_item_id_in_list(item, i->contains);
            if (tmp != 0L) {
               return tmp; // found in recursive call
            }
         }
      }
   }
   return 0L; // not found
}

And then alter the inventory code like this, further down in dg_variables.c:
         else if (!str_cmp(field, "inventory")) {
            if(subfield && *subfield) {
               long id = get_item_id_in_list(subfield, c->carrying);
               if (id != 0L) {
                  snprintf(str, slen, "%c%ld", UID_CHAR, id); /* arg given*/
                  return;
               }
               *str = '{{uie-code}}'; /* arg given, not found */
            } else { /* no arg given */
              if (c->carrying) {
                snprintf(str, slen, "%c%ld", UID_CHAR, GET_ID(c->carrying));
              } else {
                *str = '{{uie-code}}';
              }
            }
          }

This alters the behaviour of %actor.inventory% slightly, since it might pick an item in a bag over an item in the root of the inventory, since it will traverse bag as they are encountered. If tihis is a showstopper, you will need to alter the order in get_item_id_in_list so it loops twice, once to check for name/vnum, and once to check for containers.


__________________
You know who I am.
19 Sep 2010 - 14:053007
BTW, this forum often messes up the code in code boxes...
In Welcor's post above, where you see:
 *str = '{{uie-code}}';
Replace {{uie-code}} with \0 or \x0 (backslash-zero), which is the NULL terminator on the end of a string ( \x0 is just the same, but in hexidecimal - I prefer to use this for string termination code because it's easier to read and search for, just a personal preference)


__________________
Login to reply  Page: « < 1 of 1 > »