RE: Question about a function to track stats.
"Richard Lindsey" <[email protected]> Wed, 28 Sep 2005 17:05:46 -0500
| Newsgroups | gmane.games.devel.mud.rom |
|---|---|
| Message-ID | <[email protected]> |
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