IDK what you've been smoking but you are very very rusty with your coding
apparently. The get_mob_index was almost correct to use, as ammaross pointed
out. It doesn't create an instance of the mob:
MOB_INDEX_DATA *get_mob_index( int vnum )
{
    MOB_INDEX_DATA *pMobIndex;


    for ( pMobIndex  = mob_index_hash[vnum % MAX_KEY_HASH];
          pMobIndex != NULL;
          pMobIndex  = pMobIndex->next )
    {
        if ( pMobIndex->vnum == vnum )
            return pMobIndex;
    }

    if ( fBootDb )
    {
        bug( "Get_mob_index: bad vnum %d.", vnum );
        exit( 1 );
    }

    return NULL;
}

As you can see it runs threw the hash tables finding the mob by that vnum.
And returns the index of that vnum, you can edit it all you want. As it is
the pointer to that mobs index hence its name. He's doing a fine job if he
follows the post from Ammaross.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Richard
Lindsey
Sent: Wednesday, September 28, 2005 4:06 PM
To: KJM; [email protected]
Subject: RE: Question about a function to track stats.

>From what I can see at first glance, as I don't have mud code to stare
at anymore and this is all from memory... you're not actually modifying
anything as far as in-game stats are concerned, which is probably why
you're not seeing it load anything... the memory leak that bmschroe
pointed out is still in place there, as you're loading every mob in the
game and not doing anything with it... my guess is that you want to save
the kill counts externally so that they save across reboots and whatnot,
but you're not quite going about it the right way... as I don't know the
correct syntax from memory, I would suggest you go look in db2.c at the
void load_mobile function... you'll see where the actual indexdata is
created and added to the hash table... get_mob_index only creates 1
instance of a mob, such as when a mob repops in the world, it doesn't
edit the indexdata that all of those mobs are created from, so you need
to look into how to edit the indexdata in the linked list itself, and
not just on that one instance... and you shouldn't have to load anything
to do it, so you can completely scrap the calls to get_mob_index and
free up all of the memory being allocated and held onto... Hope that
gets you yet closer :)

Richard Lindsey.

-----Original Message-----
From: KJM [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 27, 2005 2:18 PM
To: [email protected]
Subject: Question about a function to track stats.

Greetings
    I want to keep track of mob kills/killed stats and show the top ten
in
each category....
 
I cant get the stats to load properly...here is my update_mobstats and
load_mobstats and a sample of the data....
 
What am I doing wrong?
 
*****LOAD_MOBSTAT*****
 
void load_mobstats()
{
  FILE *fp;
  int vnum;
 
      fclose(fpReserve);
      if ((fp=fopen("../data/mobstat.txt","r")) == NULL)
      {
        log_string("Error: unable to open mobstat file!");
        fpReserve = fopen( NULL_FILE, "r" );
        exit(1);
      }
 
      for ( ; ; )
      {
       MOB_INDEX_DATA *pMobIndex;
 
       if ( feof(fp) )
       {
        fclose( fp );
        fpReserve = fopen( NULL_FILE, "r" );
        return;
       }
 
       vnum = fread_number( fp );
 
       if ( vnum == -1 )
       {
        fclose( fp );
        return;
       }
 

       pMobIndex = get_mob_index(vnum);
       pMobIndex->killed = fread_number(fp);
       pMobIndex->kills = fread_number(fp);
      }
 
      fclose(fp);
      fpReserve = fopen( NULL_FILE, "r" );
      return;
}

 
*****UPDATE_MOBSTATS*****  Called one every 5 mins or so 
 
void mobstat_update (void)
{
     FILE *fp;
     int vnum;
     MOB_INDEX_DATA *pMobIndex;
     CHAR_DATA *mob;
     int nMatch;
     char buf[MSL];
 
    fclose(fpReserve);
 
    fp = fopen("../data/mobstat.txt","w");
 
    nMatch = 0;
    for (vnum = 0; nMatch < top_mob_index; vnum++)
    if ((pMobIndex = get_mob_index(vnum)) != NULL)
    {
      nMatch++;
      if ( ( pMobIndex = get_mob_index( vnum ) ) != NULL )
      {
       mob = create_mobile( pMobIndex );
       if (mob->pIndexData->kills >= 3 || mob->pIndexData->killed >= 3)
       {
        sprintf(buf,"%5d %5d %5d\n", mob->pIndexData->vnum,
mob->pIndexData->kills, mob->pIndexData->killed);
        fprintf( fp, buf );
       }
      }
    }
     fprintf(fp,"-1");
     fclose(fp);
     fpReserve = fopen( NULL_FILE, "r" );
     return;
}

 
*****DATA FILE**** mobstats.txt
 
   11     0     3
   12     1     2
  101     2    0
-1
 
 
Any help in pointing out my mistake would be great....it appears that
the
data is not getting loaded into the indexdata.....
 
Thanks
-T

-- 
ROM mailing list
[email protected]
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
-- 
ROM mailing list
[email protected]
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom

Reply via email to