I Need Help With a New Variable...

Posted by Seifz on Sun 22 Feb 2004 03:21 AM — 7 posts, 23,015 views.

#0
I seem to always have trouble with simple things. Usually I end up figuring it out but I just can't get this one to work. Basically, I want to add another variable to do_who in act_info.c that counts the total number of players logged on, regardless of the argument given with 'who'. For instance, let's assume that 5 mortals and 3 immortals are logged on. When a player types 'who imm' it should display the list of immortals and then, at the end, say "3 players listed, 8 online." Where do I put this variable? The whole function is just confusing to me.
Canada #1
I'm using SWR, but there should be a part that looks like this:
    for ( d = last_descriptor; d; d = d->prev )
    {
	CHAR_DATA *wch;
	char const *race;

	if ( (d->connected != CON_PLAYING && d->connected != CON_EDITING )
	|| ( !can_see_ooc( ch, d->character ) && IS_IMMORTAL( d->character ) )
	|| d->original)
	    continue;
	wch   = d->original ? d->original : d->character;
	if ( wch->top_level < iLevelLower
	||   wch->top_level > iLevelUpper 
	|| ( fImmortalOnly  && wch->top_level < LEVEL_IMMORTAL ))
	    continue;

A part where they are looping through the desciptors. Just declare a count variable at the top of do_whom, initialize it to 0, and add that code add this:
++count;
Then, find the part that prints out how many people, and add the second part using count.
#2
Yeah, I've tried adding it to various places within that part... But I haven't been successful yet. I really need an exact location with this.

Also, should I use ++count or count++? I was trying it with count++ before.
Canada #3
if all your doing is count++;, it doesn't matter is the ++ is a suffix or a prefix, it will do the same thing.

If you can post that part up from your code, I can show you were to put it. As well as the "# of players" part or your code.
#4
I declared nTotal as an int with the other variables and then set it to 0 right below the line that sets nMatch to 0. Also, the display part itself is fine:

if ( !ch )
{
fprintf( whoout, "\n\r%d player%s listed, %d online.\n\r", nMatch, nMatch == 1 ? "" : "s", nTotal );
fclose( whoout );
return;
}

set_char_color( AT_YELLOW, ch );
ch_printf( ch, "\n\r%d player%s listed, %d online.\n\r", nMatch, nMatch == 1 ? "" : "s", nTotal );
return;
}

It's getting nTotal to count every character logged in that I can't seem to do... Where in the whole huge loop thing to I put it? I haven't edited that part of the function, so it should match the default SMAUG 1.4a code... Which probably hasn't changed much in SWR.
Canada #5
I've looked at the smaugfuss do_who... what a mess. Compared to the SWR, that is. However, look for this code:
	CHAR_DATA *wch;
	char const *class;

	if ( (d->connected != CON_PLAYING && d->connected != CON_EDITING)
	||   !can_see( ch, d->character ) || d->original)
	    continue;
        nTotal++;


And add the bold part. That SHOULD be all you have to do, but I don't know for sure.
#6
It works. Most excellent. Thanks for the help!

And yeah, it is a mess. I've considered stealing the SWR do_who equivalent and editing from there.