I have something similar to this installed in my MUD, but for a different 
purpose, i have a race of Gholam, which if any of you are familiar w/ the Wheel 
of Time series, only 6 were ever created, so i have the code check the number 
of players that are that race when a player tries to remort and makes it to the 
race selection, and the mud doesn't even display it as an option if it finds 6 
of them... you can do it with something like this:
 
if you have a special field installed for this "limit", not the regular reset 
values that determine whether the item normally loads on a mob or not based on 
however many are in the world or whatnot, but a field to say only load this 
item if this limit isn't met on any player on or offline, like an 
obj->pIndexData->limit or whatever, then you can put this into the reset_room 
function... just do something like the following... when the mud cycles through 
the list of resets and finds an object reset, check
 
if ( ( obj = get_obj_index(pReset->arg1) ) )
{
    if ( obj->pIndexData->limit ) // if there's a limit at all
    {
        char buf[MAX_STRING_LENGTH];
        FILE *fp;
        bool loadobj = FALSE;
 
        sprintf(buf,"grep -h \"Vnum %d\" %s*",pReset->arg1,PLAYER_DIR);
        if ( ( fp = popen(buf,"r") ) )
        {
            int count = 0,vnum;
 
            do
            {
                fread_word(fp);
                vnum = fread_number(fp);
                if ( vnum == obj->pIndexData->vnum )
                    count++;
            } while ( !feof(fp) || count >= obj->pIndexData->limit )
 
            if ( count < obj->pIndexData->limit )
                loadobj = TRUE;
        }
 
        pclose(fp);
        if ( !loadobj )
            continue;
    }
}
 
This little piece of code should plug right into the case 'O' section of the 
reset loop in void reset_room, and grep for and count the total number of 
objects of the vnum of the one in question... if it finds no entries in any 
pfile, it will keep going till it loads the object, or if it finds less than 
the amount set for "limit" it will go ahead and load, otherwise, it will 
'continue' to the next element in the reset list and skip loading this item... 
i could have made it simply do fread_to_eol's to count the number of lines that 
were returned from the grep, but there would be a slight bug with that, if the 
vnum in question were say, 101, and it found a vnum for 1015 in someone's 
pfile, it would return that on the grep line as well, so i made it read the 
second piece of the line to compare to the item vnum and make sure it's a 
match... The only other thing that could interfere with it as it is, and it's 
an extremely rare case... would be if the person had a pet that had the same 
Vnum... but this could be easily fixed if you changed the wording for 
fwrite_pet and fread_pet to add a Vnump or something and read that from the 
pfile, instead of Vnum... anyway, this should be along the lines of what you're 
looking for :)
 
wavewave
Richard Lindsey.

        -----Original Message----- 
        From: Rainer Roomet [mailto:[EMAIL PROTECTED] 
        Sent: Sat 4/24/2004 6:53 AM 
        To: [email protected] 
        Cc: 
        Subject: question about limiting items
        
        

        I want to add limit item code to my rom 2.4. I look Tartarus code base 
but
        it is not that what i need. There was somet item limit code but it's not
        work properly. For example, if i set "the One Ring" limit 1. Then "the 
One
        Ring" loads only one time per game. And if some player have the One 
Ring and
        mud reboots then it dosen't load. Even the player is offline. It load 
again
        when player lost this ring (is he sacrifice it etc.).
        
        Anyone have idea ? And i apologize for my bad Englis :)
        
        -- Ranka
        
        The Lost Lands of Arion -- telnet irc.nohik.ee 4242
        http://www.zone.ee/gain/forum.php
        
        _________________________________________________________________
        The new MSN 8: smart spam protection and 2 months FREE* 
        http://join.msn.com/?page=features/junkmail
        
        
        --
        ROM mailing list
        [email protected]
        http://www.rom.org/cgi-bin/mailman/listinfo/rom
        

Reply via email to