The Dawn Of Time
The Official Forums for the Dawn Of Time Mud Codebase
 
Log in Register FAQ Memberlist Search The Dawn Of Time Forum Index Goto the Official Dawn Website

Expanding "where"

 
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Coding
View previous topic :: View next topic  
Author Message
Pixie



Joined: 16 Jan 2016
Posts: 56
Location: Pacific Northwest

PostPosted: Wed Jan 20, 2016 2:50 pm    Post subject: Expanding "where" Reply with quote

I am interested in expanding the use of the "where" command from this:

Code:
where
Players near you:
None.


To this:

Code:
where
Rooms with players:
         Room Name                  # of players
================================================
A Forested Clearing                           1
Large Stone Archway                           2
A Grand Courtyard                             1


I am hoping for guidance on this, as I'm still pretty tentative about diving in single-handed. How would you go about it?

I think primarily what I need is "how do I pull the name of the room the player is currently in", and "how to count numbers of players per room".


Back to top
View user's profile Send private message AIM Address
Oreant



Joined: 16 Jul 2010
Posts: 47

PostPosted: Fri Jan 22, 2016 4:06 pm    Post subject: Reply with quote

This looks like an interesting little challenge, I might try my hand at it this weekend. Check out the code for do_iwhere and it's two above functions in act_wiz2.cpp

It output like:
Code:
============================== IMMORTAL WHERE ==============================-
 1) [ 1204] Orion       92 is in A Clearing in the Forest (The Immortal Realms)
-================================= 1 TOTAL ================================-


Which is closer to what you're looking for. Though you specifically want to just count the players by room. So you could use a loop through players and add it to a list based on room and then count whenever you encounter a room again (with its own loop).

As far as how to get the room name someone is in, it would be like ch->in_room->name.


Back to top
View user's profile Send private message
Pixie



Joined: 16 Jan 2016
Posts: 56
Location: Pacific Northwest

PostPosted: Fri Jan 22, 2016 4:53 pm    Post subject: Reply with quote

iwhere is so close to what I had in mind I couldn't complain about adapting from it. Trimming off the vnum would make it just about perfect, and I could worry about counting the numbers instead of playernames later.

If you do give it a go, let me know! I'd love to see it get accomplished.


Back to top
View user's profile Send private message AIM Address
Pixie



Joined: 16 Jan 2016
Posts: 56
Location: Pacific Northwest

PostPosted: Wed Oct 05, 2016 6:15 am    Post subject: Reply with quote

Still struggling with this (and I am so glad the forums are back!).


Back to top
View user's profile Send private message AIM Address
Trell



Joined: 28 Jun 2013
Posts: 49

PostPosted: Thu Nov 24, 2016 7:52 am    Post subject: Try this Reply with quote

This is quick and dirty, and untested, but if you haven't gotten it already, give this a try. It should give you, or whomever else reads this thread a good beginning.

Code:

void do_where( char_data *ch, char *argument )
{
   char arg[MIL];
   char_data *victim=NULL;
   char_data *rch;
   connection_data *d;
   int pcount,tcount;
   bool found;

   //first, count players online...this is used for our tracking array to prevent repeats
   pcount = 0;
   for ( d = connection_list; d; d = d->next )
   {
      pcount++;
   }

   //declare our tracking array with the number of players
   //this will go awry if someone logs on in the nanoseconds it takes to run this function,
   //but it should be safe enough, you can add extra safety by pumping up pcount to account for logons...
   pcount += 5; //like this
   int rooms[pcount]; //tracking array
   int i = 0; //our array indexer
        for (i = 0;i<pcount;i++){rooms[i] = 0;} //initialize the array
        i = 0;
   bool rfound = false;

   ch->println("Rooms with players:");
   ch->println("         Room Name                  # of players ");
   ch->println("================================================");
   count = 0;
   for ( d = connection_list; d; d = d->next )
   {
      if ( d->connected_state == CON_PLAYING
      && ( victim = d->character ) != NULL
      &&   !IS_NPC(victim)
      &&   victim->in_room != NULL
      &&   !IS_SET(victim->in_room->room_flags,ROOM_NOWHERE)
      &&   is_room_private_to_char( victim->in_room, ch )
      &&   victim->in_room->area == ch->in_room->area
      &&   can_see( ch, victim ) )
      {
         rfound = false;
         //loop through our tracking array to make sure we haven't already done this room
         for (int j = 0;j<pcount ;j++ )
         {
            if (rooms[j] == victim->in_room->vnum){
               rfound = true;
               break;
            }
         }
         if (rfound){
            continue;
         }

         //new room... loop through the room and count the players
         rooms[i] = victim->in_room->vnum;
         i++; //since we've limited our count to pcount being players online, this should never exceed that logically
         count = 0;
         for (rch = victim->in_room->people;rch ;rch = rch->next_in_room )
         {
            if (!IS_NPC(rch) && can_see( ch, rch )){
               count++;
            }
         }
         //display the room
         ch->printlnf( "%22s                    %d",victim->in_room->name, count);
      }
   }
   return;
}


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Coding All times are GMT + 13 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001-2005 phpBB Group
Theme created by Vjacheslav Trushkin