Re: [SNIPP] counting inventory

From: Angus Mezick (angus@EDGIL.CCMAIL.COMPUSERVE.COM)
Date: 06/05/98


Here is a snippet, I log the num items as they enter and leave the mud, just so
I can catch repeat offenders that decide to use the auto-rent feature to avoid
this limit.
--Angus

+++ utils.c
void count_items(struct obj_data * obj, long *nitems)
{
   if (obj)
      {
      (*nitems)++;
      count_items(obj->contains, nitems);
      count_items(obj->next_content, nitems);
      }
}

+++ utils.h
void count_items(struct obj_data * obj, long *nitems);

+++ act.informative.c
ACMD(do_item_count)
{
   struct char_data *vict;
   int i;
   long numitems=0;
   char *buf=get_buffer(256);

   skip_spaces(&argument);
   if(strlen(argument)>4)
      {
      if(GET_LEVEL(ch)>LVL_GOD)
         {
         if(!(vict=get_char_vis(ch,argument)))
            send_to_char("Your target isn't here, try show rent
<person>\r\n",ch);
         else
            {
            count_items(vict->carrying,&numitems);

            for(i=0;i<NUM_WEARS;i++)
               count_items(GET_EQ(vict,i),&numitems);
            sprintf(buf,"%s is carrying %ld items.\r\n",GET_NAME(vict),
                    numitems);
            send_to_char(buf,ch);
            }
         }
      else
         {
         send_to_char("You can only count your own items!\r\n",ch);
         }
      }
   else
      {
      count_items(ch->carrying,&numitems);

      for(i=0;i<NUM_WEARS;i++)
         count_items(GET_EQ(ch,i),&numitems);
      sprintf(buf,"You are carrying %ld items.\r\n", numitems);
      send_to_char(buf,ch);
      }
   release_buffer(buf);
}

++act.other.c: ACMD(do_quit)
   else
      {
+      char *buf=get_buffer(SMALL_BUFSIZE);
+      for(i=0;i<NUM_WEARS;i++)
+         count_items(GET_EQ(ch,i),&nitems);
+      count_items(ch->carrying,&nitems);
+
+
+      if((nitems>max_obj_save)&&(!PRF_FLAGGED(ch,PRF_NOHASSLE)))
+         {
+         sprintf(buf,
+                "You cannot camp with more than %d items in your camp!\r\n"
+                "You have %ld items on your person. Time to donate some stuff!"
+                "\r\n",max_obj_save,nitems);
+         send_to_char(buf,ch);
+         }
+      else
+         {
         if (!GET_INVIS_LEV(ch))
            act("$n has left the game.", TRUE, ch, 0, 0, TO_ROOM);
         sprintf(buf, "%s has quit the game.", GET_NAME(ch));
         mudlog(buf, NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE);

+++ objsave.c:Crash_rentsave()
   Crash_extract_norents_from_equipped(ch);

   Crash_extract_norents(ch->carrying);

  /****   count here ****/
+   nitems=0;
+   for(j=0;j<NUM_WEARS;j++)
+      count_items(GET_EQ(ch,j),&nitems);
+   count_items(ch->carrying, &nitems);

+   if(nitems>max_obj_save)
+      {
+      sprintf(buf,"CAMP ALERT: %s camped with %ld items.",GET_NAME(ch),nitems);
+      mudlog(buf, NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE);
+      }
+   else
+      {
+      sprintf(buf, "CAMP: %s camped with %ld items.",GET_NAME(ch),nitems);
+      mudlog(buf, CMP, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE);
+      }
+   release_buffer(buf);

   rent.net_cost_per_diem = cost;
   rent.rentcode = RENT_RENTED;

I also stuck a counter in Crash_load() that
      if (!feof(fl))
         {
+        counter++;
         if ((obj = Obj_from_store_to(object, &locate)))
            {
----

+   sprintf(buf+strlen(buf),"(%d Items)",counter);
   mudlog(buf, NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE);

+   if(counter>max_obj_save)
+      {
+      sprintf(buf, "ALERT: %s un-rented with %d items.",GET_NAME(ch),counter);
+      mudlog(buf, NRM, MAX(LVL_IMMORT, GET_INVIS_LEV(ch)), TRUE);
+      }
+   release_buffer(buf);
  /* turn this into a crash file by re-writing the control block */
   rent.rentcode = RENT_CRASH;



_______________________________________
<question about counting items snipped>
<George's mailer code snipped>


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST