Rainer,

You might try something like this:

        char buf [MAX_STRING_LENGTH];
        CHAR_DATA *highest;
        ROOM_INDEX_DATA *room;
        int vnum     = 0;

        bool found;
        bool high;

        found   = FALSE;
        high    = FALSE;
        /* start with a random number (adjust limits to your mud) */
        for ( vnum = 1202; vnum < 24001; vnum = number_range(100, 24000) )
        {
                /*make it a random room */
                if ( ( room = get_room_index( vnum ) ) != NULL )
                {
                        /* find the highest mob in the room starting with the 
ch's level */
                        highest = ch;
                        for ( victim = room->people; victim != NULL; victim = 
victim->next_in_room )
                        {

                                if( victim->level > highest->level );
                                {
                                        highest = victim;
                                        high = TRUE;
                                        continue;
                                }
                        }
                        if ( high )
                        {
                                if ( ( IS_NPC(highest)
                                        && IS_SET(highest->act, ACT_AGGRESSIVE)
                                        && highest->level > ch->level )
                                /* the 2 is an offset that keeps newbies from 
getting an exact
                                 * level match for the first six levels */
                                &&   highest->level <= (ch->level + ((ch->level 
/ 6) +2))
                                &&   highest->level >= (ch->level - (ch->level 
/ 10)) )
                                {
                                        found = TRUE;
                                        break;
                                }
                        }

                }
                if ( found )
                break;
        }

        if ( ( room = get_room_index( vnum ) ) == NULL )
        {
                return;
        }


If you look at Vasago's code closely, you'll see he walks the char
list from the beginning every time, and rolls the dice to get a
"random" mob. The code above selects a random vnum, then looks to see
who's in the room. Since it's looking to place an object, it doesn't
worry about pet flags and such, put those in if you need them (it
does, however, make sure the mob found isn't aggy).

I guarantee my code is more random than Vasago's, however, I suspect
your real problem might be a lack of mobs at certain levels.


Hope this helps,
Sandi


Reply via email to