----- Original Message -----
From: Michael Gesner <MeGesner@aol.com>
To: <CIRCLE@post.queensu.ca>
Sent: Tuesday, March 02, 1999 8:13 PM
Subject: Source for Scoreboard
*snip*
> for (d = descriptor_list; d; d = d->next) {
>
> if (str_cmp("paintball", buf)) {
> if (PRF_FLAGGED(d->character, PRF_PAINTBALL))
> sprintf(scorebuf,"%s %15s Individual %d None"
> ,scorebuf,GET_NAME(d->character),GET_SCORE(d->character));
> }
>
> else if (str_cmp("lasertag", buf)) {
> if (PRF_FLAGGED(d->character, PRF_LASERTAG))
> sprintf(scorebuf,"%s %15s Individual %d None"
> ,scorebuf,GET_NAME(d->character),GET_SCORE(d->character));
> }
>}
One of these should always be true, at least, especially because you're
using str_cmp() wrong. Here's something I would do.
const char *scoreboard_games[] =
"paintball",
"lasertag",
"\n"
};
/* search_block() is your friend */
ACMD(do_scoreboard)
{
struct char_data *tch;
int game, counter = 0;
if (!*argument) {
send_to_char("You need to specify a game to see its scoreboard.\r\n",
ch);
return;
}
one_argument(argument, arg1); /* arg1 is a global I believe */
if ((game = search_block(arg1, scoreboard_games, FALSE)) < 0) {
send_to_char("That is not a valid game!\r\n", ch);
return;
}
/* You can't get this far without having done something right. Prepare
the buffer! Note, I use one strcpy(), because I think its tech-
nically nanoseconds faster than three or four sprintf() */
strcpy(buf, " Rhu-Dina'ar Automatic Scoreboard\r\n"
"------------------------------------------------------\r\n"
" Name: Team: Score: Bonus:\r\n"
"------------------------------------------------------\r\n");
/* 'game' now has 0 if the argument was an abbreviation of paintball,
or 1 if it was an abbreviation of lasertag. I like switches over
if-else segments */
switch (game) {
case 0: /* paintball */
/* Now we have to go through the character list and see who is playing
paintball. You used the descriptor list. I'm not sure which way
is better. */
for (ch = character_list; ch; ch = ch->next) {
if (PRF_FLAGGED(ch, PRF_PAINTBALL)) {
counter++; /* increment this counter so we can put a number of
players string at the bottom of the buffer. Good
in case there's nobody playing. */
sprintf(buf + strlen(buf), " %15s Individual %d None",
GET_NAME(ch),
GET_SCORE(ch)); /* buf+strlen(buf) is essentially the same as
what you
did, but its safe on Borland compilers who
clear the
buffer before printing into it */
/* Next! */
}
}
break; /* done in this case, next is almost an exact duplicate. */
case 1: /* lasertag */
for (ch = character_list; ch; ch = ch->next) {
if (PRF_FLAGGED(ch, PRF_LASERTAG)) {
counter++;
sprintf(buf + strlen(buf), " %15s Individual %d None",
GET_NAME(ch),
GET_SCORE(ch));
}
}
break;
default: /* should never reach this point */
sprintf(buf + strlen(buf), " An error has occured. Contact an
administrator.\r\n");
break;
}
/* This could more safely be put in the case values so that the default
case message is
the last line when there's an error. That should never happen though.
sprintf(buf + strlen(buf), " There %s %d players participating in
%s.\r\n", (counter != 1 ? "are" : "is"),
counter, scoreboard_games[game]);
/* Alright, I think the buffer is ready to be sent, do you? */
send_to_char(buf, ch);
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST